1

私はopencartを初めて使用し、カート内に製品属性を表示できるようにする必要があるショップを現在開発しています。私はあちこち検索しましたが、どうやら誰もこの機能を必要としていませんでした。簡単に言えば、製品ページで属性を取得する方法を複製しようとしましたが、成功しませんでした。次の行を追加してコントローラーを変更しました。

$this->data['attribute_groups'] = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']);

私も追加しました:

<?php foreach ($attribute_groups as $attribute_group) { ?>
  <?php echo $attribute_group['name']; ?>
    <?php foreach ($attribute_group['attribute'] as $attribute) { ?>
   <?php echo $attribute['name']; ?>
<?php echo $attribute['text']; ?>
    <?php } ?>
  <?php } ?>
<?php } ?>

成功なし。どうにかして system/library/cart.php を変更する必要があると思います。問題は、私がそれを行う方法を知るのに十分なほど精通していないことです! この時点で、私はここで助けを求めることにしました!アイデアはありますか?

4

1 に答える 1

0

これは見た目ほど難しくなく、2 つのファイルを編集して 3 つのファイルを開くだけで済みます。

--1-- 属性を取得するためのメソッドをカート クラスに追加します。

カタログ/モデル/カタログ/product.php を開く

メソッドを見つけて、メソッドgetProductAttributes($product_id)全体をクリップボードにコピーします。

メソッドを開いsystem/library/cart.phpて、コピーしたgetProducts()メソッドを貼り付けます。

--2-- コードを貼り付けた場所のすぐ上、getProducts()メソッドの最後に、ビューの products 配列が構築されている場所が表示されます。これは次のようになります。

$this->data[$key] = array(
    'key'             => $key,
    'product_id'      => $product_query->row['product_id'],
    'name'            => $product_query->row['name'],
    'model'           => $product_query->row['model'],
    'shipping'        => $product_query->row['shipping'],
    'image'           => $product_query->row['image'],
    'option'          => $option_data,
    'download'        => $download_data,
    'quantity'        => $quantity,
    'minimum'         => $product_query->row['minimum'],
    'subtract'        => $product_query->row['subtract'],
    'stock'           => $stock,
    'price'           => ($price + $option_price),
    'total'           => ($price + $option_price) * $quantity,
    'reward'          => $reward * $quantity,
    'points'          => ($product_query->row['points'] ? ($product_query->row['points'] + $option_points) * $quantity : 0),
    'tax_class_id'    => $product_query->row['tax_class_id'],
    'weight'          => ($product_query->row['weight'] + $option_weight) * $quantity,
    'weight_class_id' => $product_query->row['weight_class_id'],
    'length'          => $product_query->row['length'],
    'width'           => $product_query->row['width'],
    'height'          => $product_query->row['height'],
    'length_class_id' => $product_query->row['length_class_id']                 
);

getAttributes メソッドの呼び出しを配列に追加するだけです。

'attributes' => $this->getProductAttributes($product_query->row['product_id'])

カート テンプレートを開きます。catalog/view/theme/yourtheme/common/cart.tpl商品オプション ループがあるところで、オプションと同じように属性をループできます。

于 2013-09-04T12:21:11.080 に答える