Php Magento-获取愿望列表中项目的关联产品属性
在app/code/local/Mage/Catalog/Product/Type/Configurable/Price.php中,我试图获取愿望列表中关联产品的属性值。我尝试了几种方法,但我似乎只能为父产品生成数据 最新尝试Php Magento-获取愿望列表中项目的关联产品属性,php,magento,model,magento-1.9,Php,Magento,Model,Magento 1.9,在app/code/local/Mage/Catalog/Product/Type/Configurable/Price.php中,我试图获取愿望列表中关联产品的属性值。我尝试了几种方法,但我似乎只能为父产品生成数据 最新尝试 $customer = Mage::getSingleton('customer/session')->getCustomer(); if($customer->getId()) { $wishlist = Mage::getM
$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>";
}
}
}
这只会导致页面出现错误
此外:
$_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网站上测试过了,它对我有效。其实很简单,你只需要为这个系列找到合适的型号。还有,你好像在改变价格?!?!请注意,您的愿望列表项包含逻辑中使用的必要属性
$_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
或
更改模板的愿望列表文件,而不是代码文件夹中的定价逻辑。您可以访问所需的所有数据,并且不会干扰price.php文件,该文件在购物车和网站的其他关键区域中非常依赖。愿望列表中的价格在移动到购物车时会重新计算。您还有其他尝试吗?@berg37我会用其他尝试更新我的问题。嗯。。。我将尝试这个方法,但它看起来只是返回父产品的属性值。我正在寻找子产品值。这实际上是获取可配置(父)产品的值,而不是关联(子)产品的值。你有其他的解决方案吗?而不是搞乱Price.php。。。为什么不把愿望列表模板弄乱呢?产品/项目所需的所有信息应随时提供给您。然后,如果客户将商品添加到购物车中,则Price.php文件将相应地进行计算。这有意义吗?很好。既然你提到了,我想这个愿望的价格只是为了虚荣。
$_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