我想为购物车中的某些产品添加特定价格。目前我在一家商店实现了这一目标,但在另一家商店却没有。我能够为购物车中的某个产品(属性)添加特定价格。我有这个添加部分的代码:
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
按要求禁用。因为我也想为访客/客人定价。