这并不像表面上看起来那么难,您只需要编辑 2 个文件并打开 3 个。
--1-- 将获取属性的方法添加到购物车类中。
打开目录/model/catalog/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
在产品选项循环所在的位置,您现在可以像选项一样循环遍历您的属性。