Skip to content

Commit 5cc16d9

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-63585' into 2.0.15-develop-pr14
2 parents a0a7c49 + 36a7b04 commit 5cc16d9

File tree

14 files changed

+503
-14
lines changed

14 files changed

+503
-14
lines changed

app/code/Magento/Quote/Model/Quote/Address/Total/Shipping.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,11 @@ public function collect(
5656

5757
$address->setWeight(0);
5858
$address->setFreeMethodWeight(0);
59-
$address->setFreeShipping(false);
6059

6160
$addressWeight = $address->getWeight();
6261
$freeMethodWeight = $address->getFreeMethodWeight();
62+
$addressFreeShipping = $address->getFreeShipping();
6363

64-
$isAllFree = $this->freeShipping->isFreeShipping($quote, $shippingAssignment->getItems());
65-
if ($isAllFree && !$address->getFreeShipping()) {
66-
$address->setFreeShipping(true);
67-
}
6864
$total->setTotalAmount($this->getCode(), 0);
6965
$total->setBaseTotalAmount($this->getCode(), 0);
7066

@@ -100,7 +96,7 @@ public function collect(
10096
$itemQty = $child->getTotalQty();
10197
$rowWeight = $itemWeight * $itemQty;
10298
$addressWeight += $rowWeight;
103-
if ($address->getFreeShipping() || $child->getFreeShipping() === true) {
99+
if ($addressFreeShipping || $child->getFreeShipping() === true) {
104100
$rowWeight = 0;
105101
} elseif (is_numeric($child->getFreeShipping())) {
106102
$freeQty = $child->getFreeShipping();
@@ -118,7 +114,7 @@ public function collect(
118114
$itemWeight = $item->getWeight();
119115
$rowWeight = $itemWeight * $item->getQty();
120116
$addressWeight += $rowWeight;
121-
if ($address->getFreeShipping() || $item->getFreeShipping() === true) {
117+
if ($addressFreeShipping || $item->getFreeShipping() === true) {
122118
$rowWeight = 0;
123119
} elseif (is_numeric($item->getFreeShipping())) {
124120
$freeQty = $item->getFreeShipping();
@@ -138,7 +134,7 @@ public function collect(
138134
$itemWeight = $item->getWeight();
139135
$rowWeight = $itemWeight * $item->getQty();
140136
$addressWeight += $rowWeight;
141-
if ($address->getFreeShipping() || $item->getFreeShipping() === true) {
137+
if ($addressFreeShipping || $item->getFreeShipping() === true) {
142138
$rowWeight = 0;
143139
} elseif (is_numeric($item->getFreeShipping())) {
144140
$freeQty = $item->getFreeShipping();
@@ -159,6 +155,10 @@ public function collect(
159155

160156
$address->setWeight($addressWeight);
161157
$address->setFreeMethodWeight($freeMethodWeight);
158+
$address->setFreeShipping(
159+
$this->freeShipping->isFreeShipping($quote, $shippingAssignment->getItems())
160+
);
161+
162162
$address->collectShippingRates();
163163

164164
if ($method) {

dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,5 +1037,33 @@
10371037
<item name="dataset" xsi:type="string">default_subcategory</item>
10381038
</field>
10391039
</dataset>
1040+
1041+
<dataset name="simple_with_weight_10_for_salesrule">
1042+
<field name="attribute_set_id" xsi:type="array">
1043+
<item name="dataset" xsi:type="string">default</item>
1044+
</field>
1045+
<field name="name" xsi:type="string">Simple Product %isolation%</field>
1046+
<field name="sku" xsi:type="string">sku_simple_product_%isolation%</field>
1047+
<field name="product_has_weight" xsi:type="string">Yes</field>
1048+
<field name="weight" xsi:type="string">10</field>
1049+
<field name="quantity_and_stock_status" xsi:type="array">
1050+
<item name="qty" xsi:type="string">25</item>
1051+
<item name="is_in_stock" xsi:type="string">In Stock</item>
1052+
</field>
1053+
<field name="price" xsi:type="array">
1054+
<item name="value" xsi:type="string">560</item>
1055+
</field>
1056+
<field name="tax_class_id" xsi:type="array">
1057+
<item name="dataset" xsi:type="string">taxable_goods</item>
1058+
</field>
1059+
<field name="website_ids" xsi:type="array">
1060+
<item name="0" xsi:type="string">Main Website</item>
1061+
</field>
1062+
<field name="visibility" xsi:type="string">Catalog, Search</field>
1063+
<field name="url_key" xsi:type="string">simple-product-%isolation%</field>
1064+
<field name="checkout_data" xsi:type="array">
1065+
<item name="dataset" xsi:type="string">simple_order_default</item>
1066+
</field>
1067+
</dataset>
10401068
</repository>
10411069
</config>

dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Totals.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class Totals extends Block
105105
*/
106106
public function getGrandTotal()
107107
{
108+
$this->waitForUpdatedTotals();
108109
$grandTotal = $this->_rootElement->find($this->grandTotal, Locator::SELECTOR_CSS)->getText();
109110
return $this->escapeCurrency($grandTotal);
110111
}

dev/tests/functional/tests/app/Magento/SalesRule/Test/Handler/SalesRule/Curl.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,28 @@ class Curl extends Conditions implements SalesRuleInterface
3838
*/
3939
protected $mapTypeParams = [
4040
'Subtotal' => [
41-
'type' => 'Magento\SalesRule\Model\Rule\Condition\Address',
41+
'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class,
4242
'attribute' => 'base_subtotal',
4343
],
4444
'Conditions combination' => [
45-
'type' => 'Magento\SalesRule\Model\Rule\Condition\Combine',
45+
'type' => \Magento\SalesRule\Model\Rule\Condition\Combine::class,
4646
'aggregator' => 'all',
4747
'value' => '1',
4848
],
4949
'Shipping Country' => [
50-
'type' => 'Magento\SalesRule\Model\Rule\Condition\Address',
50+
'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class,
5151
'attribute' => 'country_id',
5252
],
5353
'Shipping Postcode' => [
54-
'type' => 'Magento\SalesRule\Model\Rule\Condition\Address',
54+
'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class,
5555
'attribute' => 'postcode',
5656
],
57+
'Total Weight' => [
58+
'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class,
59+
'attribute' => 'weight',
60+
],
5761
'Category' => [
58-
'type' => 'Magento\SalesRule\Model\Rule\Condition\Product',
62+
'type' => \Magento\SalesRule\Model\Rule\Condition\Product::class,
5963
'attribute' => 'category_ids',
6064
]
6165
];
@@ -179,7 +183,7 @@ public function prepareData(FixtureInterface $fixture)
179183

180184
if (isset($this->data['actions_serialized'])) {
181185
$this->mapTypeParams['Conditions combination']['type'] =
182-
'Magento\SalesRule\Model\Rule\Condition\Product\Combine';
186+
\Magento\SalesRule\Model\Rule\Condition\Product\Combine::class;
183187
$this->data['rule']['actions'] = $this->prepareCondition($this->data['actions_serialized']);
184188
unset($this->data['actions_serialized']);
185189
}

dev/tests/functional/tests/app/Magento/SalesRule/Test/Repository/SalesRule.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,25 @@
189189
<field name="simple_action" xsi:type="string">Percent of product price discount</field>
190190
<field name="discount_amount" xsi:type="string">50</field>
191191
</dataset>
192+
193+
<dataset name="rule_with_freeshipping_by_weight">
194+
<field name="name" xsi:type="string">Cart price rule with free shipping by weight</field>
195+
<field name="is_active" xsi:type="string">Yes</field>
196+
<field name="website_ids" xsi:type="array">
197+
<item name="0" xsi:type="string">Main Website</item>
198+
</field>
199+
<field name="customer_group_ids" xsi:type="array">
200+
<item name="0" xsi:type="string">NOT LOGGED IN</item>
201+
</field>
202+
<field name="coupon_type" xsi:type="string">No Coupon</field>
203+
<field name="sort_order" xsi:type="string">1</field>
204+
<field name="is_rss" xsi:type="string">Yes</field>
205+
<field name="conditions_serialized" xsi:type="string">[Total Weight|is|1]</field>
206+
<field name="simple_action" xsi:type="string">Percent of product price discount</field>
207+
<field name="discount_amount" xsi:type="string">0</field>
208+
<field name="apply_to_shipping" xsi:type="string">No</field>
209+
<field name="stop_rules_processing" xsi:type="string">No</field>
210+
<field name="simple_free_shipping" xsi:type="string">For matching items only</field>
211+
</dataset>
192212
</repository>
193213
</config>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\SalesRule\Test\TestCase;
8+
9+
/**
10+
* Precondition:
11+
* 1. Cart Price Rule was created.
12+
*
13+
* Steps:
14+
* 1. Go to storefront.
15+
* 2. Add product to shopping cart.
16+
* 3. Go to shopping cart page.
17+
* 4. Perform asserts.
18+
*
19+
* @group Shopping_Cart_Price_Rules
20+
* @ZephyrId MAGETWO-64748
21+
*/
22+
class ShoppingCartWithFreeShippingTest extends \Magento\Mtf\TestCase\Injectable
23+
{
24+
/**
25+
* @var \Magento\Mtf\TestStep\TestStepFactory
26+
*/
27+
private $testStepFactory;
28+
29+
/**
30+
* Factory for cteating product fixture.
31+
*
32+
* @var \Magento\Mtf\Fixture\FixtureFactory
33+
*/
34+
protected $fixtureFactory;
35+
36+
/**
37+
* Inject data.
38+
*
39+
* @param \Magento\Mtf\TestStep\TestStepFactory $testStepFactory
40+
* @param \Magento\Mtf\Fixture\FixtureFactory
41+
* @return void
42+
*/
43+
public function __inject(
44+
\Magento\Mtf\TestStep\TestStepFactory $testStepFactory,
45+
\Magento\Mtf\Fixture\FixtureFactory $fixtureFactory
46+
) {
47+
$this->testStepFactory = $testStepFactory;
48+
$this->fixtureFactory = $fixtureFactory;
49+
}
50+
51+
/**
52+
* Test sales rule with free shipping applied by product weight.
53+
*
54+
* @param \Magento\SalesRule\Test\Fixture\SalesRule $salesRule
55+
* @param string $product
56+
* @param \Magento\Checkout\Test\Fixture\Cart $cart
57+
* @return void
58+
*/
59+
public function testRuleWithFreeShippingByWeight(
60+
\Magento\SalesRule\Test\Fixture\SalesRule $salesRule,
61+
$product,
62+
\Magento\Checkout\Test\Fixture\Cart $cart,
63+
array $shipping = null
64+
) {
65+
$salesRule->persist();
66+
list($fixture, $dataset) = explode('::', $product);
67+
$product = $this->fixtureFactory->createByCode($fixture, ['dataset' => $dataset]);
68+
$product->persist();
69+
70+
$this->testStepFactory->create(
71+
\Magento\Checkout\Test\TestStep\AddProductsToTheCartStep::class,
72+
['products' => [$product]]
73+
)->run();
74+
75+
$this->testStepFactory->create(
76+
\Magento\Checkout\Test\TestStep\EstimateShippingAndTaxStep::class,
77+
['products' => [$product], 'cart' => $cart, 'shipping' => $shipping]
78+
)->run();
79+
}
80+
81+
/**
82+
* Clear data after test.
83+
*
84+
* @return void
85+
*/
86+
public function tearDown()
87+
{
88+
$this->testStepFactory->create(\Magento\SalesRule\Test\TestStep\DeleteAllSalesRuleStep::class)->run();
89+
}
90+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\SalesRule\Test\TestCase\ShoppingCartWithFreeShippingTest" summary="Shopping Cart With Freeshipping" ticketId="MAGETWO-64748">
10+
<variation name="ShoppingCartWithFreeShippingTestVariation1">
11+
<data name="salesRule/dataset" xsi:type="string">rule_with_freeshipping_by_weight</data>
12+
<data name="product" xsi:type="string">catalogProductSimple::default</data>
13+
<data name="cart/data/subtotal" xsi:type="string">560.00</data>
14+
<data name="cart/data/shipping_amount" xsi:type="string">0.00</data>
15+
<data name="cart/data/grand_total" xsi:type="string">560.00</data>
16+
<data name="shipping/shipping_service" xsi:type="string">Flat Rate</data>
17+
<data name="shipping/shipping_method" xsi:type="string">Fixed</data>
18+
</variation>
19+
<variation name="ShoppingCartWithFreeShippingTestVariation2">
20+
<data name="salesRule/dataset" xsi:type="string">rule_with_freeshipping_by_weight</data>
21+
<data name="product" xsi:type="string">catalogProductSimple::simple_with_weight_10_for_salesrule</data>
22+
<data name="cart/data/subtotal" xsi:type="string">560.00</data>
23+
<data name="cart/data/shipping_amount" xsi:type="string">5.00</data>
24+
<data name="cart/data/grand_total" xsi:type="string">565.00</data>
25+
<data name="shipping/shipping_service" xsi:type="string">Flat Rate</data>
26+
<data name="shipping/shipping_method" xsi:type="string">Fixed</data>
27+
</variation>
28+
</testCase>
29+
</config>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/** @var $product \Magento\Catalog\Model\Product */
8+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
9+
->create(\Magento\Catalog\Model\Product::class);
10+
$product->isObjectNew(true);
11+
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
12+
->setId(1)
13+
->setAttributeSetId(4)
14+
->setWebsiteIds([1])
15+
->setName('Simple Product')
16+
->setSku('simple')
17+
->setPrice(10)
18+
->setWeight(1)
19+
->setShortDescription("Short description")
20+
->setTaxClassId(0)
21+
->setTierPrice(
22+
[
23+
[
24+
'website_id' => 0,
25+
'cust_group' => \Magento\Customer\Model\Group::CUST_GROUP_ALL,
26+
'price_qty' => 2,
27+
'price' => 8,
28+
],
29+
[
30+
'website_id' => 0,
31+
'cust_group' => \Magento\Customer\Model\Group::CUST_GROUP_ALL,
32+
'price_qty' => 5,
33+
'price' => 5,
34+
],
35+
[
36+
'website_id' => 0,
37+
'cust_group' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
38+
'price_qty' => 3,
39+
'price' => 5,
40+
],
41+
]
42+
)
43+
->setDescription('Description with <b>html tag</b>')
44+
->setMetaTitle('meta title')
45+
->setMetaKeyword('meta keyword')
46+
->setMetaDescription('meta description')
47+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
48+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
49+
->setCategoryIds([2])
50+
->setStockData(
51+
[
52+
'use_config_manage_stock' => 1,
53+
'qty' => 100,
54+
'is_qty_decimal' => 0,
55+
'is_in_stock' => 1,
56+
]
57+
)
58+
->setCanSaveCustomOptions(true)
59+
->setHasOptions(false)
60+
->save();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/** @var \Magento\Framework\Registry $registry */
8+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
9+
10+
$registry->unregister('isSecureArea');
11+
$registry->register('isSecureArea', true);
12+
13+
/** @var $product \Magento\Catalog\Model\Product */
14+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
15+
$product->load(1);
16+
if ($product->getId()) {
17+
$product->delete();
18+
}
19+
20+
$registry->unregister('isSecureArea');
21+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)