Magento在Quote中保存账单地址

时间:2011-11-16 18:07:31

标签: php magento magento-1.5

从一开始我就为我可怜的英语道歉!我有一项任务是在页面结帐时在Magento的客户会话中正确存储信息。当我尝试保存访客用户的帐单地址时,我已经重写了帐单模式,一切正常。但是当用户登录并在他的地址簿中有多个地址时,我看到了有趣的事情....我更改了计费模型以保存客户地址ID并保存所选地址但是当用户选择选项“新地址”时,表单数据保存在报价中,当我尝试使用getQuote() - > getBillingAddress()我采取默认用户地址(当用户没有登录所有工作良好)我怎么能做这个任务?我需要帮助,因为这对我来说是一项重要任务......很多thx !!!

1 个答案:

答案 0 :(得分:0)

如果我正确解析您的问题,您是说getQuote()->getBillingAddress()获取客户的默认帐单邮寄地址而不是客户在订单中输入的新地址吗?

我在Magento 1.4.0.1中也有这个问题,我通过从客户那里获取所有地址并将每个属性与订单中指定的地址进行比较来找出地址的真实实体ID。 / p>

我从我的代码中删除了自定义业务逻辑的某些部分,因此请将其视为未经测试,但您明白了这一点:

(该代码仅在Magento 1.4.0.1上测试,可能不适用于Magento 1.5)

$currentCustomer = Mage::getModel('customer/customer')->load($order['customer_id']);
$attributesToCompare = array('firstname', 'lastname', 'country_id', 'region', 'region_id', 'city', 'telephone', 'postcode', 'company', 'fax', 'prefix', 'middlename', 'suffix', 'street');
$orderAddresses = array(
  'billing' => $order->getBillingAddress()->getData(),
  'shipping' => $order->getShippingAddress()->getData()
  );
$foundExistingCustomerAddressEntityId = array(
  'billing' => false,
  'shipping' => false
  );
$billingSameAsShipping = false;
$currentCustomerAddresses = $currentCustomer->getAddressesCollection();
// is the billing/shipping address currently found in the customer's address book?
foreach ($orderAddresses as $orderAddressKey => $orderAddress) {
  //var_dump($orderAddress);
  foreach ($currentCustomerAddresses as $currentCustomerAddressObj) {
    $currentCustomerAddress = $currentCustomerAddressObj->getData();
    $attributesMatchCount = 0;
    foreach ($attributesToCompare as $attributeToCompare) {
      if (empty($currentCustomerAddress[$attributeToCompare])) {
        $currentCustomerAddress[$attributeToCompare] = false;
      }
      $attributesMatchCount += ($orderAddress[$attributeToCompare] == $currentCustomerAddress[$attributeToCompare])?1:0;
      //echo 'attributesMatchCount: '.$attributesMatchCount." {$orderAddress[$attributeToCompare]} {$currentCustomerAddress[$attributeToCompare]}\n";
    }
    if ($attributesMatchCount == count($attributesToCompare)) {
      $foundExistingCustomerAddressEntityId[$orderAddressKey] = $currentCustomerAddress['entity_id'];
      //echo 'foundExistingCustomerAddressEntityId['.$orderAddressKey.']: '.$foundExistingCustomerAddressEntityId[$orderAddressKey]."\n\n";
      break;
    }
  }
}
$billingShippingExactMatchCount = 0;
foreach ($attributesToCompare as $attributeToCompare) {
  $billingShippingExactMatchCount += ($orderAddresses['billing'][$attributeToCompare] == $orderAddresses['shipping'][$attributeToCompare])?1:0;
}
if ($billingShippingExactMatchCount == count($attributesToCompare)) {
  $billingSameAsShipping = true;
}