Skip to content

Commit bc46d6c

Browse files
authored
Merge pull request PrestaShop#41566 from mattgoud/fix/41057-discount-v2-cant-remove-delivery-condition
Discount - Fix delivery condition not removed when switching to None
2 parents 5e5be1c + a709af2 commit bc46d6c

3 files changed

Lines changed: 129 additions & 3 deletions

File tree

src/Core/Form/IdentifiableObject/DataHandler/DiscountFormDataHandler.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,13 @@ private function updateDiscountConditions(AddDiscountCommand|UpdateDiscountComma
286286
// Delivery conditions
287287
if ($data['conditions'][DiscountConditionsType::DELIVERY_CONDITIONS]['children_selector'] === DeliveryConditionsType::CARRIERS) {
288288
$command->setCarrierIds($data['conditions'][DiscountConditionsType::DELIVERY_CONDITIONS][DeliveryConditionsType::CARRIERS]);
289-
}
290-
if ($data['conditions'][DiscountConditionsType::DELIVERY_CONDITIONS]['children_selector'] === DeliveryConditionsType::COUNTRY) {
289+
$command->setCountryIds([]);
290+
} elseif ($data['conditions'][DiscountConditionsType::DELIVERY_CONDITIONS]['children_selector'] === DeliveryConditionsType::COUNTRY) {
291291
$command->setCountryIds($data['conditions'][DiscountConditionsType::DELIVERY_CONDITIONS][DeliveryConditionsType::COUNTRY]);
292+
$command->setCarrierIds([]);
293+
} elseif ($data['conditions'][DiscountConditionsType::DELIVERY_CONDITIONS]['children_selector'] === DeliveryConditionsType::NONE) {
294+
$command->setCarrierIds([]);
295+
$command->setCountryIds([]);
292296
}
293297
}
294298

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# ./vendor/bin/behat -c tests/Integration/Behaviour/behat.yml -s discount --tags update-discount-delivery-conditions
2+
@restore-all-tables-before-feature
3+
@restore-languages-after-feature
4+
@update-discount-delivery-conditions
5+
Feature: Update discount delivery conditions
6+
PrestaShop allows BO users to update delivery conditions on discounts
7+
As a BO user
8+
I must be able to remove or switch delivery conditions after they have been set
9+
10+
Background:
11+
Given shop "shop1" with name "test_shop" exists
12+
Given there is a currency named "usd" with iso code "USD" and exchange rate of 0.92
13+
Given language with iso code "en" is the default one
14+
And country "france" with iso code "FR" exists
15+
And country "spain" with iso code "ES" exists
16+
Given group "visitor" named "Visitor" exists
17+
Given group "guest" named "Guest" exists
18+
19+
Scenario: Remove country delivery condition by switching to none
20+
When I create a "free_shipping" discount "discount_countries_to_none" with following properties:
21+
| name[en-US] | Free shipping FR+ES |
22+
| countries | france,spain |
23+
Then discount "discount_countries_to_none" should have the following properties:
24+
| countries | spain,france |
25+
When I update discount "discount_countries_to_none" with the following properties:
26+
| countries | |
27+
Then discount "discount_countries_to_none" should have the following properties:
28+
| countries | |
29+
30+
Scenario: Remove carrier delivery condition by switching to none
31+
Given I add new zone "zone1" with following properties:
32+
| name | zone1 |
33+
| enabled | true |
34+
Given I create carrier "carrier1" with specified properties:
35+
| name | Carrier 1 |
36+
| grade | 1 |
37+
| trackingUrl | http://example.com/track.php?num=@ |
38+
| active | true |
39+
| max_width | 1454 |
40+
| max_height | 1234 |
41+
| max_depth | 1111 |
42+
| max_weight | 3864 |
43+
| group_access | visitor, guest |
44+
| delay[en-US] | Shipping delay |
45+
| shippingHandling | false |
46+
| isFree | true |
47+
| shippingMethod | weight |
48+
| zones | zone1 |
49+
| rangeBehavior | disabled |
50+
When I create a "free_shipping" discount "discount_carriers_to_none" with following properties:
51+
| name[en-US] | Free shipping carrier1 |
52+
| carriers | carrier1 |
53+
Then discount "discount_carriers_to_none" should have the following properties:
54+
| carriers | carrier1 |
55+
When I update discount "discount_carriers_to_none" with the following properties:
56+
| carriers | |
57+
Then discount "discount_carriers_to_none" should have the following properties:
58+
| carriers | |
59+
60+
Scenario: Switch from country condition to carrier condition clears countries
61+
Given I add new zone "zone2" with following properties:
62+
| name | zone2 |
63+
| enabled | true |
64+
Given I create carrier "carrier2" with specified properties:
65+
| name | Carrier 2 |
66+
| grade | 1 |
67+
| trackingUrl | http://example.com/track.php?num=@ |
68+
| active | true |
69+
| max_width | 1454 |
70+
| max_height | 1234 |
71+
| max_depth | 1111 |
72+
| max_weight | 3864 |
73+
| group_access | visitor, guest |
74+
| delay[en-US] | Shipping delay |
75+
| shippingHandling | false |
76+
| isFree | true |
77+
| shippingMethod | weight |
78+
| zones | zone2 |
79+
| rangeBehavior | disabled |
80+
When I create a "free_shipping" discount "discount_countries_to_carriers" with following properties:
81+
| name[en-US] | Free shipping countries |
82+
| countries | france |
83+
Then discount "discount_countries_to_carriers" should have the following properties:
84+
| countries | france |
85+
When I update discount "discount_countries_to_carriers" with the following properties:
86+
| carriers | carrier2 |
87+
| countries | |
88+
Then discount "discount_countries_to_carriers" should have the following properties:
89+
| carriers | carrier2 |
90+
| countries | |
91+
92+
Scenario: Switch from carrier condition to country condition clears carriers
93+
Given I add new zone "zone3" with following properties:
94+
| name | zone3 |
95+
| enabled | true |
96+
Given I create carrier "carrier3" with specified properties:
97+
| name | Carrier 3 |
98+
| grade | 1 |
99+
| trackingUrl | http://example.com/track.php?num=@ |
100+
| active | true |
101+
| max_width | 1454 |
102+
| max_height | 1234 |
103+
| max_depth | 1111 |
104+
| max_weight | 3864 |
105+
| group_access | visitor, guest |
106+
| delay[en-US] | Shipping delay |
107+
| shippingHandling | false |
108+
| isFree | true |
109+
| shippingMethod | weight |
110+
| zones | zone3 |
111+
| rangeBehavior | disabled |
112+
When I create a "free_shipping" discount "discount_carriers_to_countries" with following properties:
113+
| name[en-US] | Free shipping carrier3 |
114+
| carriers | carrier3 |
115+
Then discount "discount_carriers_to_countries" should have the following properties:
116+
| carriers | carrier3 |
117+
When I update discount "discount_carriers_to_countries" with the following properties:
118+
| countries | spain |
119+
| carriers | |
120+
Then discount "discount_carriers_to_countries" should have the following properties:
121+
| countries | spain |
122+
| carriers | |

tests/UI/campaigns/functional/BO/03_catalog/07_discounts/03_discountV2/04_minimumPurchaseAmountOnFreeShipping.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ describe('BO - Catalog - Discounts : Minimum purchase amount (On free shipping)'
394394
});
395395
});
396396

397-
// @todo : https://github.com/PrestaShop/PrestaShop/issues/41057
397+
// @todo : https://github.com/PrestaShop/PrestaShop/issues/39929
398398
describe.skip('Edit discount (with tax excluded) in BO and check it in FO', async () => {
399399
it('should go back to BO', async function () {
400400
await testContext.addContextItem(this, 'testIdentifier', 'goBackToBO', baseContext);

0 commit comments

Comments
 (0)