6

私は最初のmagentoのデプロイに取り組んできました。かなりカスタマイズされたテーマが構築されました...非標準のカスタマイズのいくつかに今すぐ取り組んでいます:

私の主な製品タイプの1つは、バンドル製品として設定したオフィスチェアです。この製品タイプには多くのオプションがあり(約100のファブリックオプション、アームスタイル、ランバー、ヘッドレストなど)、カタログ/製品/ビューページにこれらの各画像を表示できるようにする必要があります。

バンドル製品であること(そして、これが正しい製品タイプであるかどうかについての議論は控えます-構成可能製品とバンドル製品の間で議論を交わしました)-各製品は、いくつかの単純な製品から組み立てられています(オプションとして) 。これらのシンプルな製品には画像をアップロードできますが、私はそうしました。メディアフォルダからURLを取得したいのですが...

いくつかの狩猟の後-これらは重要な要素のようです:

テーマ/../template/catalog/product/view/options.phtml

<?php $_options = Mage::helper('core')->decorateArray($this->getOptions()) ?>
<dl>
    <?php foreach($_options as $_option): ?>
        <?php echo $this->getOptionHtml($_option) ?>
    <?php endforeach; ?>
</dl>

テーマ/../template/bundle/catalog/product/view/type/bundle/option/select.phtml

<?php /* @var $this Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option_Select */ ?>
<?php $_option      = $this->getOption(); ?>
<?php $_selections  = $_option->getSelections(); ?>

私はついに見つけましgetSelections()た:

class Mage_Bundle_Model_Resource_Price_Index extends Mage_Core_Model_Resource_Db_Abstract
{ ...


    /**
        * Retrieve bundle options with selections and prices by product
       *
        * @param int $productId
        * @return array
        */
       public function getSelections($productId)
       {
           $options = array();
           $read = $this->_getReadAdapter();
           $select = $read->select()
               ->from(
                   array('option_table' => $this->getTable('bundle/option')),
                   array('option_id', 'required', 'type')
               )
               ->join(
                   array('selection_table' => $this->getTable('bundle/selection')),
                   'selection_table.option_id=option_table.option_id',
                   array('selection_id', 'product_id', 'selection_price_type',
                       'selection_price_value', 'selection_qty', 'selection_can_change_qty')
               )
               ->join(
                   array('e' => $this->getTable('catalog/product')),
                   'e.entity_id=selection_table.product_id AND e.required_options=0',
                   array()
               )
               ->where('option_table.parent_id=:product_id');

           $query = $read->query($select, array('product_id' => $productId));
           while ($row = $query->fetch()) {
               if (!isset($options[$row['option_id']])) {
                   $options[$row['option_id']] = array(
                       'option_id'     => $row['option_id'],
                       'required'      => $row['required'],
                       'type'          => $row['type'],
                       'selections'    => array()
                   );
               }
               $options[$row['option_id']]['selections'][$row['selection_id']] = array(
                   'selection_id'      => $row['selection_id'],
                   'product_id'        => $row['product_id'],
                   'price_type'        => $row['selection_price_type'],
                   'price_value'       => $row['selection_price_value'],
                   'qty'               => $row['selection_qty'],
                   'can_change_qty'    => $row['selection_can_change_qty']
               );
           }

           return $options;
       }

selection_idしたがって、、などを含む配列が返されますがproduct_idprice_typeその選択の画像URLを参照するものはありません。

とすれば:

class Mage_Catalog_Helper_Product extends Mage_Core_Helper_Url
{ ...
public function getImageUrl($product)
        {
            $url = false;
            if (!$product->getImage()) {
                $url = Mage::getDesign()->getSkinUrl('images/no_image.jpg');
            }
            elseif ($attribute = $product->getResource()->getAttribute('image')) {
               $url = $attribute->getFrontend()->getUrl($product);
           }
           return $url;
       }

テーマ/../template/bundle/catalog/product/view/type/bundle/option/select.phtmlのように、各選択の画像URLへの参照を含むjsオブジェクトを作成しようとしています。

var option_set_<?php echo $_option->getId() ?> = {};
<?php foreach ($_selections as $_selection): ?>
    option_set_<?php echo $_option->getId() ?>._<?php echo $_selection->getSelectionId() ?> = '<?php echo $_selection->getImageUrl(); ?>';
<?php endforeach; ?>

しかし$_selection、プレースホルダーグラフィックにバウンスするだけなので、明らかに正しく入力されていません。

これらのオプションを製品として入力できると仮定すると(または、selection_idから単純な製品を取得すると、そのようなものが機能するように見えます。それがこの機能をどのように管理したいかはわかりませんが、 URLのスタックを取得します-それから私はビジネスになります

奇妙なことに、インターウェブは基本的にこの問題について沈黙しています。どうやら誰も彼らの製品オプションのために画像を表示する必要はありません(あるいは、唯一の解決策は有料の拡張機能です-これは最後の手段になります)。

どうすればこれを理解できますか?

イエスはキリストをタップダンスします。メイジはもっと複雑になるでしょうか?


アップデート

これをそのように機能させる:

<?php echo $this->helper('catalog/image')->init($_selection, 'small_image')->resize(40,40); ?>

誰かがこの修正を必要とする場合、私が選択した答えもうまく機能します。

4

1 に答える 1

4

$ _selectionsのproduct_idは、選択した単純な商品のIDを表します。したがって、行うべきことは次のとおりです。

  1. $_selectionsのproduct_idを取得します。
  2. このproduct_idで製品をロードします
  3. 結果の製品オブジェクトをMage_Catalog_Helper_Product::getImageUrlに渡します。
于 2012-07-04T21:40:36.430 に答える