结帐成功的物品属性

时间:2014-03-20 15:51:52

标签: php magento attributes product

我们有一家卖衣服的商店。我们的属性为size。我试图获取客户在成功页面上购买的商品以传递给某些JavaScript。获得数量和价格很简单,但我无法弄清楚如何获得物品的大小。

出了什么问题?

$_customerId = Mage::getSingleton('customer/session')->getCustomerId();
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getSingleton('sales/order');
$order->load($lastOrderId);
$_totalData = $order->getData();
$_grand = $_totalData['grand_total'];
$_allItems = $order->getAllVisibleItems();


<script type='text/javascript'>
var orderInfo =
{
  orderId : '<?php echo $lastOrderId; ?>',
  priceTotal : '<?php echo $_grand; ?>',
  itemCount : '<?php echo count($_allItems); ?>',
  items : 
    [
<?php 
foreach ($_allItems as $item) 
{
    $_itemSku = $item->getSku();
    $_itemId = $item->getId();
    $_itemData = $item->getData();
    $_productModel = Mage::getModel('catalog/product')->load($_itemId);
    $_itemSize = $_productModel->getAttributeText('Size');
    $_itemUrl = $_productModel->getProductUrl();
    ?>

        { itemId : '<?="hi" ?>', 
            sku: '<?=$_itemSku; ?>',
            size : '<?=$_itemSize ?>',
            priceUSD : '<?=$item->getPrice(); ?>', 
            url : '<?=$_productUrl ?>' 
        },
    <?php 
}
Mage::log("Item Size");
Mage::log("$_itemSize");
Mage::log("Item Data");
Mage::log($_itemData);
Mage::log('Prodouct Options');
Mage::log($_itemData['product_options']);
Mage::log(unserialize($_itemData['product_options']));
?>
    ]
}

1 个答案:

答案 0 :(得分:0)

看看@ How to get Magento Order data from Observer

获取项目选项

 foreach ($_allItems as $item){
      $_itemSku = $item->getSku();
      .....

      $optionArray = $item->getProductOptions()
      // Todo : check to see if set and is array $optionArray['options'] for product without options

      $_itemSize = '';
      foreach($optionArray['options'] as $option){
          // Mage::log($option)
          //echo $option['label']
          //$option['value']
          if($option['label'] == 'Size'){
              $_itemSize = $option['value'];
          }
      }
 }

 ...
 Mage::log("$_itemSize");