我已经定义了一些自定义属性,并通过Opencart管理面板将它们分配给产品.我正在尝试在结账时检索这些属性以调整一些运费.
我目前正在catalog/model/shipping/ups.php使用该getQuote函数中的文件.我正在接近这个:
print_r($this->cart->getProducts());
Run Code Online (Sandbox Code Playgroud)
这给了我以下产品数据:
Array
(
[59] => Array
(
[key] => 59
[product_id] => 59
[name] => My Product Name
[model] => ABC
[shipping] => 1
[image] => data/myproduct.jpg
[option] => Array
(
)
[download] => Array
(
)
[quantity] => 1
[minimum] => 1
[subtract] => 1
[stock] => 1
[price] => 29.99
[total] => 29.99
[reward] => 0
[points] => 0
[tax_class_id] => 0
[weight] => 3.75
[weight_class_id] => 5
[length] => 0.00
[width] => 0.00
[height] => 0.00
[length_class_id] => 3
)
)
Run Code Online (Sandbox Code Playgroud)
但是,不返回自定义属性.我确信有一种很好的方法可以将产品ID传递给属性获取功能,但我找不到它.Opencart文档对于开发方面有点缺乏,而且在Google上没有运气.
通常我会grep从整个目录结构中找到我正在寻找的内容,但是在这个特定的Web主机上禁用了shell访问:(.
编辑
我相信属性是Opencart中内置的一个新功能.它就像一个自定义领域.
无论如何,在管理员方面,我去了Catalog> Attributes并创建了一个名为"Shipping Box Type"的自定义属性.然后,在特定产品下我可以设置属性.见截图.我的目标是检索"装运箱类型"的值.那是否回答了你的问题@Cleverbot?我确信我可以做一个自定义的数据库查询来获取它,但是它们必须是一个内置函数来获取属性?

Ban*_*jer 10
检索给定product_id的属性
$this->load->model('catalog/product');
$attributes = $this->model_catalog_product->getProductAttributes(59);
print_r($attributes);
Run Code Online (Sandbox Code Playgroud)
产量
Array
(
[0] => Array
(
[attribute_group_id] => 9
[name] => Shipping Fields
[attribute] => Array
(
[0] => Array
(
[attribute_id] => 16
[name] => Shipping Box Type
[text] => SM2
)
)
)
)
Run Code Online (Sandbox Code Playgroud)
更进一步,这里是循环浏览购物车中当前产品的示例,以查看它们具有的属性:
$this->load->model('catalog/product');
$cart_products = $this->cart->getProducts();
// get attributes for each product in the cart
foreach($cart_products as $product) {
$attributes = $this->model_catalog_product->getProductAttributes($product['product_id']);
print_r($attributes);
}
Run Code Online (Sandbox Code Playgroud)