2

製品リスト ページで構成可能な製品属性値を取得する最も効果的な方法を探しています。たとえば、製品の色の値 (割り当てられた単純な製品から)

現在catalog_product_flat_n、この目的のためにテーブルを利用することを検討していますが、おそらくこれを行うためのより簡単またはより正しいアプローチがありますか? 私は使用を避けようとしています

$product->getTypeInstance()->getConfigurableAttributesAsArray()

これは非常に遅くなるため、すべての製品で

ありがとう

4

1 に答える 1

1

私は同じ問題を抱えていたので、フラット テーブルからデータを取得するための独自のリソース モデルを作成しました。以下のコードを調べてください。

  <?php

    class NameSpace_ModuleName_Model_Resource_Colors extends
        Mage_Core_Model_Resource_Db_Abstract
    {
        protected $_storeId;

        protected function _construct()
        {
            $this->_init('catalog/product_flat', 'entity_id');
            $this->_storeId = (int)Mage::app()->getStore()->getId();
        }

        public function getData($entityId)
        {
            $resource = Mage::getSingleton('core/resource');
            $select = $resource->getConnection('core_read')->select();
            $select
                ->from($this->getTable(array('catalog/product_flat', $this->_storeId)), '*')
                ->where('entity_id = :entity_id');



            $result = $resource->getConnection('core_read')->fetchAll($select, array('entity_id' => $entityId));

            return $result;
        }
    }

お役に立てば幸いです

于 2012-08-01T10:47:28.227 に答える