【问题标题】:Magento: Get simple product color from custom tableMagento:从自定义表中获取简单的产品颜色
【发布时间】:2011-09-25 20:34:35
【问题描述】:

我在 Magento 1.10 Enterprise 中遇到了这个问题。我有一组简单的产品颜色 ID,我想用这个 ID 来查询 atb_color 表。原始查询:

SELECT description FROM atb_colors WHERE option_id = 'my_color_id'

这是我尝试构建的一种方法:

public function getColorData($product){ 
    $ids = $product->getTypeInstance()->getUsedProductIds();    
    foreach($ids as $id){
        $simpleproduct = Mage::getModel('catalog/product')->load($id);
                    -->Query using my_color_id

    }       
}

我可以用它来获取名称和数量。如果我把它放在 foreach 循环中:

echo $simpleproduct->getName()." - ".(int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($simpleproduct)->getQty() . '<br />';

我将如何运行此查询。请原谅我对 Magento 很陌生。掌握其中一些有点困难。但是我在最后期限内完成显示颜色和尺寸的这一部分。有什么帮助吗?求求求求!!

提前致谢

【问题讨论】:

    标签: function magento colors enterprise


    【解决方案1】:

    这是最奇怪的黑客,但如果你真的很赶时间

    public function getProductCustomColor($product)
    {
        $ids = $product->getTypeInstance()->getUsedProductIds();
        foreach($ids as $id){
            $simpleProduct = Mage::getModel('catalog/product')->load($id);
            $select = $product->getResource()->getReadConnection()->select()
                ->from('atb_colors', array('description'))
                ->where('option_id = :my_color_id');
            $colorDescription = $product->getResource()->getReadConnection()
                ->fetchOne($select, array('option_id' => $simpleProduct->getYourColorId()));
            // ...
        }
    }
    

    致所有人:永远不要以这种方式为 magento 编写代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-27
      • 1970-01-01
      • 2012-08-30
      • 2021-12-22
      • 1970-01-01
      • 2013-08-02
      • 2011-07-08
      • 2016-07-16
      相关资源
      最近更新 更多