Magento - 获取愿望清单中商品的关联产品属性

Magento - Get the associated product attributes of an item in the wishlist

在 app/code/local/Mage/Catalog/Product/Type/Configurable/Price.php 中,我试图获取心愿单中关联产品的属性值。我尝试了几种方法,但我似乎只能为父产品生成数据。

最近的尝试

    $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 个属性的属性值,但似乎 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 网站上对此进行了测试,它对我有用。其实很简单,你只需要为那个系列找到合适的模型。另外,你好像要改价了?!?!请注意您的愿望清单项目包含您的逻辑中使用的必要属性。

$_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 文件,该文件在购物车和网站的其他关键区域中非常依赖。心愿单中的价格无论如何都会在移动到购物车时重新计算。