【问题标题】:Change price by adding product to cart in Prestashop通过在 Prestashop 中将产品添加到购物车来更改价格
【发布时间】:2017-02-02 15:51:41
【问题描述】:

我创建了一个小的 Prestashop 模块。使用此模块,您可以自定义产品。

使用此代码将产品添加到购物车时

<a class="exclusive ajax_add_to_cart_button" rel="ajax_id_product_{$product.id_product}" 
href="{$link->getPageLink('cart')}?qty=1&amp;id_product={$product.id_product}&amp;
token={$static_token}&amp;add" title="{l s='Add to cart' mod='folienplotter'}">
{l s='Add to cart' mod='folienplotter'}</a>

计算出来的价格应该传递给产品。我不知道如何处理。

谢谢你帮助我!

【问题讨论】:

  • 计算价格是什么意思? “传递”给产品是什么意思??
  • 使用该模块,您可以定制产品。然后模块生成价格。如果您按“加入购物车”按钮,则应将计算出的价格的产品加入购物车。
  • 您无法更改产品价格。如果您这样做,您将在以后确认订单时遇到问题。我建议您不要触摸产品价格计算功能,因为它们非常复杂。祝你好运。
  • 您还有其他解决方案吗?

标签: php ajax prestashop prestashop-1.6


【解决方案1】:

添加产品时,您可以添加具有当前 id_cart 的 SpecificPrice,而不是将价格“传递”给模块中的产品:

$specific_price = new SpecificPrice();
$specific_price->id_product = (int)$id_product; // choosen product id
$specific_price->id_product_attribute = (int)$id_product_attribute; // optional or set to 0
$specific_price->id_cart = (int)$current_id_cart;
$specific_price->from_quantity = 1;
$specific_price->price = $new_price_without_tax;
$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"; // or set date x days from now
$specific_price->add();

然后 Prestashop 应该进行计算。

【讨论】:

  • 喜欢这个想法。唯一的问题是,如果客户选择将相同产品的另一个产品放入购物车,但定制不同,它将覆盖添加到购物车的第一个产品的价格。
  • 真的。 specific_price 中没有 id_costumization。但购物车中没有 id_costumization。你能有 2 个具有相同 id_product 和相同 id_product_attribute 的产品具有不同的定制吗?
  • 很遗憾 Prestashop 无法更新购物车定价。此解决方案仅为该购物车创建定价规则。购物车中超过 1 件具有相同 sku 的商品将改变价格。我希望有更好的解决方案。目前,这似乎是不编辑核心代码的唯一方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-04-01
  • 1970-01-01
  • 2017-04-06
  • 2011-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多