在 app/code/local/Mage/Catalog/Product/Type/Configurable/Price.php 中,我试图获取愿望 list 中关联产品的属性值。我尝试了多种方法,但似乎只能为父产品生成数据。
最新尝试
$customer = Mage::getSingleton('customer/session')->getCustomer();
if($customer->getId()) {
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer, true);
$wishListItemCollection = $wishlist->getItemCollection();
foreach ($wishListItemCollection as $wlitem) {
$wishitem = Mage::getModel('catalog/product')->setStoreId($wlitem->getStoreId())->load($wlitem->getProductId());
//echo $wishitem->getId() . '<br>';
if($product->getId() == $wishitem->getId()) { //if the current product id equals the wishlist product id
echo $wishitem->getSku()."</br>";
}
}
}
这只能让我获得父产品的 sku。我最终想要得到的是我为可配置产品添加的 2 个属性的属性值(不是 super 属性),但 Price.php 中的 $product 似乎只有父产品集合。
其他尝试:
$item_s = Mage::getModel('wishlist/item')->loadWithOptions($product->getId(), 'simple_product')->getOptionsByCode();
$simple_product = $item_s['simple_product']->getData();
$simple_product_id = $simple_product['product_id'];
$sim_product = Mage::getModel('catalog/product')->load($simple_product_id);
print_r($sim_product);
这只会导致页面出现错误。
另外:
$_item = Mage::getModel('catalog/product')->load($product->getId());
//echo $_item->getData('ppuom');
//print_r($_item);
$simpleProduct = $_item->getOptionsByCode()['simple_product']->getItem()->getProduct();
print_r($simpleProduct);
最佳答案
看起来你已经完成了大部分任务。我已经在我的 Magento 网站上对此进行了测试,它对我有用。实际上非常简单,您只需为该系列选择合适的型号即可。另外,好像你要改变价格?!?!请注意,您的愿望 list 项目包含逻辑中使用的必要属性。
$_item = Mage::getModel('catalog/product')->load($product->getId());
$attribute1 = $_item->getData('attribute1_code'); //see admin for attribute code
$attribute2 = $_item->getData('attribute2_code'); //see admin for attribute code
或
更改模板的愿望 list 文件,而不是代码文件夹中的定价逻辑。您将可以访问所需的所有数据,并且不会干扰购物车和网站其他关键区域中严重依赖的price.php 文件。无论如何,当愿望 list 中的价格被移至购物车时,都会重新计算。
关于php - Magento - 获取愿望 list 中项目的关联产品属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37331003/