【问题标题】:Magento - Get the associated product attributes of an item in the wishlistMagento - 获取愿望清单中商品的相关产品属性
【发布时间】:2016-09-16 19:02:03
【问题描述】:

在 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); 

【问题讨论】:

  • 你还做了哪些其他尝试?
  • @berg37 我会用其他尝试更新我的问题。

标签: php magento model magento-1.9


【解决方案1】:

似乎你大部分时间都在那里。我已经在我的 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 文件。无论如何,愿望清单中的价格都会在它被移到购物车时重新计算。

【讨论】:

  • 嗯...我会试试这个,但看起来这只会返回父产品的属性值。我正在寻找子产品价值。
  • 这确实是获取可配置(父)产品的值,而不是关联(子)产品。您还有其他解决方案吗?
  • 与其搞乱Price.php...你为什么不搞乱心愿单模板呢?您需要的产品/项目的所有信息都应该随时可供您使用。然后,如果客户将商品添加到购物车,您的 Price.php 文件将进行相应的计算。这有意义吗?
  • 好点。我想你提到的愿望清单价格只是为了虚荣。
猜你喜欢
  • 1970-01-01
  • 2022-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多