英文:
Prestashop cart rule with free shipping not works
问题
我在PrestaShop中有一个网站(版本1.7.6.9),我创建了一个购物车规则,对整个购物车应用了30%的折扣,还有免费送货:
但是当我输入代码时,它只应用了百分比折扣,而没有免费送货:
我尝试过删除百分比折扣,只保留免费送货,但在这种情况下会扣除运费,但我需要两种折扣,我该如何解决?
英文:
I have a site in prestashop (version 1.7.6.9), I created a cart rule that applies a 30% discount on the whole cart and also free shipping:
but when I enter the code it only applies percentage discount and not free shipping:
I've tried removing the percentage discount, leaving only the free shipping and in this case it takes away the shipping cost, but I need both discounts, how can I solve it?
答案1
得分: 0
这是折扣包括运费在PS 1.7中的工作方式 - 运费价格始终显示在订单总额中,但运费成本会在“折扣”行中累加并扣除。
如果你进行计算,你会注意到屏幕截图是正确的,因为折扣是价格(32.70)+运费(7.00)的30%总和,总折扣为39.70。
英文:
That's the way discounts including shipping works with PS 1.7 - Shipping price is always shown in order total , but shipping cost is being summed and subtracted in the "discount" row.
If you do the math you will notice the screenshot is correct, as discount is summing up 30% on price (32.70) + shipping (7.00) resulting in a 39.70 total discount.
答案2
得分: 0
我通过编辑文件/src/Adapter/Presenter/Cart/CartPresenter.php并添加以下函数来解决了这个问题:
private function getShippingDisplayValue($cart, $shippingCost)
{
$shippingDisplayValue = '';
// 如果应用的购物车规则之一具有免费送货,则运费显示值为'Free'
foreach ($cart->getCartRules() as $rule) {
if ($rule['free_shipping'] && !$rule['carrier_restriction']) {
return $this->translator->trans('Free', [], 'Shop.Theme.Checkout');
}
}
if ($shippingCost != 0) {
$shippingDisplayValue = $this->priceFormatter->format($shippingCost);
} else {
$defaultCountry = null;
if (isset(Context::getContext()->cookie->id_country)) {
$defaultCountry = new Country((int) Context::getContext()->cookie->id_country);
}
$deliveryOptionList = $cart->getDeliveryOptionList($defaultCountry);
if (count($deliveryOptionList) > 0) {
foreach ($deliveryOptionList as $option) {
foreach ($option as $currentCarrier) {
if (isset($currentCarrier['is_free']) && $currentCarrier['is_free'] > 0) {
$shippingDisplayValue = $this->translator->trans('Free', [], 'Shop.Theme.Checkout');
break 2;
}
}
}
}
}
return $shippingDisplayValue;
}
注意:上述代码是PHP代码,只进行了格式化,没有翻译。
英文:
I solved it by editing the file /src/Adapter/Presenter/Cart/CartPresenter.php and adding this function:
private function getShippingDisplayValue($cart, $shippingCost)
{
$shippingDisplayValue = '';
// if one of the applied cart rules have free shipping, then the shipping display value is 'Free'
foreach ($cart->getCartRules() as $rule) {
if ($rule['free_shipping'] && !$rule['carrier_restriction']) {
return $this->translator->trans('Free', [], 'Shop.Theme.Checkout');
}
}
if ($shippingCost != 0) {
$shippingDisplayValue = $this->priceFormatter->format($shippingCost);
} else {
$defaultCountry = null;
if (isset(Context::getContext()->cookie->id_country)) {
$defaultCountry = new Country((int) Context::getContext()->cookie->id_country);
}
$deliveryOptionList = $cart->getDeliveryOptionList($defaultCountry);
if (count($deliveryOptionList) > 0) {
foreach ($deliveryOptionList as $option) {
foreach ($option as $currentCarrier) {
if (isset($currentCarrier['is_free']) && $currentCarrier['is_free'] > 0) {
$shippingDisplayValue = $this->translator->trans('Free', [], 'Shop.Theme.Checkout');
break 2;
}
}
}
}
}
return $shippingDisplayValue;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论