我想为购物车中的某些商品添加特定价格。目前我在一家商店实现了这一目标,但在另一家商店却没有。我能够为购物车中的某个产品(属性)添加特定价格。我有这个代码来执行添加部分:
foreach ($prices as $product) {
$specific_price = new SpecificPrice;
$specific_price->id_product = $product['id_product'];
$specific_price->id_product_attribute = $product['id_product_attribute'];
$specific_price->id_cart = (int)$params['cart']->id;
$specific_price->id_shop = $this->context->shop->id;
$specific_price->id_shop_group = $this->context->shop->id_shop_group;
$specific_price->id_country = $this->context->country->id;
$specific_price->id_currency = $this->context->currency->id;
$specific_price->id_group = $this->context->customer->id_default_group;
$specific_price->id_customer = $this->context->customer->id ? $this->context->customer->id : NULL;
$specific_price->from_quantity = 0;
$m2 = $product['m2'] < 0 ? 1 : round($product['m2']);
$specific_price->price = Tools::ps_round($product['price'] * $m2 / $product['quantity'], 6);
$specific_price->reduction_type = 'amount';
$specific_price->reduction_tax = 1;
$specific_price->reduction = 0;
$specific_price->from = date('Y-m-d H:i:s');
$specific_price->to = '0000-00-00 00:00:00';
try {
$specific_price->add(true);
} catch (Exception $e) {
Logger::addLog(sprintf('[%s] %s, line %d', $this->name, $e->getMessage(), __LINE__));
echo $e->getMessage();
if ($e->getCode() == 0) {
try {
$specific_price->update(true);
} catch (Exception $e) {
Logger::addLog(sprintf('[%s] %s, line %d', $this->name, $e->getMessage(), __LINE__ ));
echo $e->getMessage();
}
}
}
}
在id_shop 1
中它可以正常运行,但在另一个商店id_shop 2
它没有。我在这个问题上开了好几个小时。我到处都是干净的缓存,重新启动XAMPP,检查http.conf是否有线索。
我已根据要求禁用id_customer
。因为我想为访客/客人保存价格。