Skip to content

Commit d58fbff

Browse files
author
Dmytro Voskoboinikov
committed
Merge branch 'develop' into MAGETWO-36849
2 parents e13e293 + ae2a82d commit d58fbff

File tree

40 files changed

+1725
-36
lines changed

40 files changed

+1725
-36
lines changed

app/code/Magento/Rule/Model/Resource/Rule/Collection/AbstractCollection.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,11 @@ public function addWebsiteFilter($websiteId)
8080
if ($websiteId instanceof \Magento\Store\Model\Website) {
8181
$websiteId = $websiteId->getId();
8282
}
83-
84-
$subSelect = $this->getConnection()->select()->from(
83+
$this->getSelect()->join(
8584
['website' => $this->getTable($entityInfo['associations_table'])],
86-
''
87-
)->where(
88-
'website.' . $entityInfo['entity_id_field'] . ' IN (?)',
89-
$websiteId
90-
);
91-
$this->getSelect()->exists(
92-
$subSelect,
93-
'main_table.' . $entityInfo['rule_id_field'] . ' = website.' . $entityInfo['rule_id_field']
85+
$this->getConnection()->quoteInto('website.' . $entityInfo['entity_id_field'] . ' = ?', $websiteId)
86+
. ' AND main_table.' . $entityInfo['rule_id_field'] . ' = website.' . $entityInfo['rule_id_field'],
87+
[]
9488
);
9589
}
9690
return $this;

app/code/Magento/Rule/Test/Unit/Model/Resource/Rule/Collection/AbstractCollectionTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ protected function _prepareAddFilterStubs()
120120
->method('where')
121121
->will($this->returnSelf());
122122

123-
$collectionSelect->expects($this->once())
124-
->method('exists');
125-
126123
$this->abstractCollection->expects($this->any())
127124
->method('getConnection')
128125
->will($this->returnValue($connection));

app/code/Magento/Sales/Model/Resource/Order/Relation.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ public function __construct(
6565
public function processRelation(\Magento\Framework\Model\AbstractModel $object)
6666
{
6767
/** @var \Magento\Sales\Model\Order $object */
68-
$this->addressHandler->removeEmptyAddresses($object);
69-
$this->addressHandler->process($object);
68+
7069
if (null !== $object->getItems()) {
7170
/** @var \Magento\Sales\Model\Order\Item $item */
7271
foreach ($object->getItems() as $item) {
@@ -98,5 +97,7 @@ public function processRelation(\Magento\Framework\Model\AbstractModel $object)
9897
$relatedObject->save();
9998
}
10099
}
100+
$this->addressHandler->removeEmptyAddresses($object);
101+
$this->addressHandler->process($object);
101102
}
102103
}

app/code/Magento/Sales/etc/di.xml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@
288288
<item name="origin_column" xsi:type="string">billing_address_id</item>
289289
<item name="target_column" xsi:type="string">entity_id</item>
290290
</item>
291+
<item name="sales_order_payment" xsi:type="array">
292+
<item name="table" xsi:type="string">sales_order_payment</item>
293+
<item name="origin_column" xsi:type="string">entity_id</item>
294+
<item name="target_column" xsi:type="string">parent_id</item>
295+
</item>
291296
</argument>
292297
<argument name="columns" xsi:type="array">
293298
<item name="entity_id" xsi:type="string">sales_order.entity_id</item>
@@ -314,7 +319,7 @@
314319
<item name="subtotal" xsi:type="string">sales_order.base_subtotal</item>
315320
<item name="shipping_and_handling" xsi:type="string">sales_order.base_shipping_amount</item>
316321
<item name="customer_name" xsi:type="object">CustomerNameAggregator</item>
317-
<item name="payment_method" xsi:type="object">PaymentMethodSubSelect</item>
322+
<item name="payment_method" xsi:type="string">sales_order_payment.method</item>
318323
<item name="total_refunded" xsi:type="string">sales_order.total_refunded</item>
319324
</argument>
320325
</arguments>
@@ -340,6 +345,11 @@
340345
<item name="origin_column" xsi:type="string">billing_address_id</item>
341346
<item name="target_column" xsi:type="string">entity_id</item>
342347
</item>
348+
<item name="sales_order_payment" xsi:type="array">
349+
<item name="table" xsi:type="string">sales_order_payment</item>
350+
<item name="origin_column" xsi:type="string">order_id</item>
351+
<item name="target_column" xsi:type="string">parent_id</item>
352+
</item>
343353
</argument>
344354
<argument name="columns" xsi:type="array">
345355
<item name="entity_id" xsi:type="string">sales_shipment.entity_id</item>
@@ -357,7 +367,7 @@
357367
<item name="shipping_name" xsi:type="object">ShippingNameAggregator</item>
358368
<item name="customer_email" xsi:type="string">sales_order.customer_email</item>
359369
<item name="customer_group_id" xsi:type="string">sales_order.customer_group_id</item>
360-
<item name="payment_method" xsi:type="object">PaymentMethodSubSelect</item>
370+
<item name="payment_method" xsi:type="string">sales_order_payment.method</item>
361371
<item name="created_at" xsi:type="string">sales_shipment.created_at</item>
362372
<item name="updated_at" xsi:type="string">sales_shipment.updated_at</item>
363373
<item name="order_id" xsi:type="string">sales_shipment.order_id</item>
@@ -386,6 +396,11 @@
386396
<item name="origin_column" xsi:type="string">order_id</item>
387397
<item name="target_column" xsi:type="string">entity_id</item>
388398
</item>
399+
<item name="sales_order_payment" xsi:type="array">
400+
<item name="table" xsi:type="string">sales_order_payment</item>
401+
<item name="origin_column" xsi:type="string">order_id</item>
402+
<item name="target_column" xsi:type="string">parent_id</item>
403+
</item>
389404
</argument>
390405
<argument name="columns" xsi:type="array">
391406
<item name="entity_id" xsi:type="string">sales_creditmemo.entity_id</item>
@@ -405,7 +420,7 @@
405420
<item name="customer_name" xsi:type="object">CustomerNameAggregator</item>
406421
<item name="customer_email" xsi:type="string">sales_order.customer_email</item>
407422
<item name="customer_group_id" xsi:type="string">sales_order.customer_group_id</item>
408-
<item name="payment_method" xsi:type="object">PaymentMethodSubSelect</item>
423+
<item name="payment_method" xsi:type="string">sales_order_payment.method</item>
409424
<item name="shipping_information" xsi:type="string">sales_order.shipping_description</item>
410425
<item name="subtotal" xsi:type="string">sales_creditmemo.subtotal</item>
411426
<item name="shipping_and_handling" xsi:type="string">sales_creditmemo.shipping_amount</item>
@@ -436,6 +451,11 @@
436451
<item name="origin_column" xsi:type="string">billing_address_id</item>
437452
<item name="target_column" xsi:type="string">entity_id</item>
438453
</item>
454+
<item name="sales_order_payment" xsi:type="array">
455+
<item name="table" xsi:type="string">sales_order_payment</item>
456+
<item name="origin_column" xsi:type="string">order_id</item>
457+
<item name="target_column" xsi:type="string">parent_id</item>
458+
</item>
439459
</argument>
440460
<argument name="columns" xsi:type="array">
441461
<item name="entity_id" xsi:type="string">sales_invoice.entity_id</item>
@@ -449,7 +469,7 @@
449469
<item name="customer_name" xsi:type="object">CustomerNameAggregator</item>
450470
<item name="customer_email" xsi:type="string">sales_order.customer_email</item>
451471
<item name="customer_group_id" xsi:type="string">sales_order.customer_group_id</item>
452-
<item name="payment_method" xsi:type="object">PaymentMethodSubSelect</item>
472+
<item name="payment_method" xsi:type="string">sales_order_payment.method</item>
453473
<item name="store_currency_code" xsi:type="string">sales_invoice.store_currency_code</item>
454474
<item name="order_currency_code" xsi:type="string">sales_invoice.order_currency_code</item>
455475
<item name="base_currency_code" xsi:type="string">sales_invoice.base_currency_code</item>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\SalesRule\Model\Plugin\Resource;
7+
8+
class Rule
9+
{
10+
/**
11+
* @param \Magento\SalesRule\Model\Resource\Rule $subject
12+
* @param \Closure $proceed
13+
* @param \Magento\Framework\Model\AbstractModel $object
14+
* @return \Magento\Framework\Model\AbstractModel
15+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
16+
*/
17+
public function aroundLoadCustomerGroupIds(
18+
\Magento\SalesRule\Model\Resource\Rule $subject,
19+
\Closure $proceed,
20+
\Magento\Framework\Model\AbstractModel $object
21+
) {
22+
return $subject;
23+
}
24+
25+
/**
26+
* @param \Magento\SalesRule\Model\Resource\Rule $subject
27+
* @param \Closure $proceed
28+
* @param \Magento\Framework\Model\AbstractModel $object
29+
* @return \Magento\Framework\Model\AbstractModel
30+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
31+
*/
32+
public function aroundLoadWebsiteIds(
33+
\Magento\SalesRule\Model\Resource\Rule $subject,
34+
\Closure $proceed,
35+
\Magento\Framework\Model\AbstractModel $object
36+
) {
37+
return $subject;
38+
}
39+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\SalesRule\Model\Plugin;
7+
8+
class Rule
9+
{
10+
/**
11+
* @param \Magento\SalesRule\Model\Rule $subject
12+
* @param \Closure $proceed
13+
* @return \Magento\SalesRule\Model\Rule
14+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
15+
*/
16+
public function aroundLoadCouponCode(
17+
\Magento\SalesRule\Model\Rule $subject,
18+
\Closure $proceed
19+
) {
20+
return $subject;
21+
}
22+
}

app/code/Magento/SalesRule/Model/Resource/Rule.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ class Rule extends \Magento\Rule\Model\Resource\AbstractResource
3030
],
3131
];
3232

33+
/**
34+
* @var array
35+
*/
36+
protected $customerGroupIds = [];
37+
38+
/**
39+
* @var array
40+
*/
41+
protected $websiteIds = [];
42+
3343
/**
3444
* Magento string lib
3545
*
@@ -77,13 +87,38 @@ protected function _construct()
7787
*/
7888
protected function _afterLoad(AbstractModel $object)
7989
{
80-
$object->setData('customer_group_ids', (array)$this->getCustomerGroupIds($object->getId()));
81-
$object->setData('website_ids', (array)$this->getWebsiteIds($object->getId()));
90+
$this->loadCustomerGroupIds($object);
91+
$this->loadWebsiteIds($object);
8292

8393
parent::_afterLoad($object);
8494
return $this;
8595
}
8696

97+
/**
98+
* @param AbstractModel $object
99+
* @return void
100+
*/
101+
public function loadCustomerGroupIds(AbstractModel $object)
102+
{
103+
if (!$this->customerGroupIds) {
104+
$this->customerGroupIds = (array)$this->getCustomerGroupIds($object->getId());
105+
}
106+
$object->setData('customer_group_ids', $this->customerGroupIds);
107+
}
108+
109+
/**
110+
* @param AbstractModel $object
111+
* @return void
112+
*/
113+
public function loadWebsiteIds(AbstractModel $object)
114+
{
115+
if (!$this->websiteIds) {
116+
$this->websiteIds = (array)$this->getWebsiteIds($object->getId());
117+
}
118+
119+
$object->setData('website_ids', $this->websiteIds);
120+
}
121+
87122
/**
88123
* Prepare sales rule's discount quantity
89124
*

app/code/Magento/SalesRule/Model/Resource/Rule/Collection.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ public function setValidationFilter($websiteId, $customerGroupId, $couponCode =
103103
),
104104
['code']
105105
);
106-
$select->where('main_table.coupon_type = ? ', \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON);
106+
107+
$select->where(
108+
'main_table.coupon_type = ? ',
109+
\Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON
110+
);
111+
107112
$orWhereConditions = [
108113
$connection->quoteInto(
109114
'(main_table.coupon_type = ? AND rule_coupons.type = 0)',
@@ -118,8 +123,22 @@ public function setValidationFilter($websiteId, $customerGroupId, $couponCode =
118123
\Magento\SalesRule\Model\Rule::COUPON_TYPE_SPECIFIC
119124
),
120125
];
126+
127+
$andWhereConditions = [
128+
$connection->quoteInto(
129+
'rule_coupons.code = ?',
130+
$couponCode
131+
),
132+
$connection->quoteInto(
133+
'(rule_coupons.expiration_date IS NULL OR rule_coupons.expiration_date >= ?)',
134+
$this->_date->date('Y-m-d')
135+
),
136+
];
137+
121138
$orWhereCondition = implode(' OR ', $orWhereConditions);
122-
$select->orWhere('(' . $orWhereCondition . ') AND rule_coupons.code = ?', $couponCode);
139+
$andWhereCondition = implode(' AND ', $andWhereConditions);
140+
141+
$select->orWhere('(' . $orWhereCondition . ') AND ' . $andWhereCondition);
123142
} else {
124143
$this->addFieldToFilter(
125144
'main_table.coupon_type',

app/code/Magento/SalesRule/Model/Rule.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,20 @@ protected function _construct()
230230
* @return $this
231231
*/
232232
protected function _afterLoad()
233+
{
234+
$this->loadCouponCode();
235+
return parent::_afterLoad();
236+
}
237+
238+
/**
239+
* @return void
240+
*/
241+
public function loadCouponCode()
233242
{
234243
$this->setCouponCode($this->getPrimaryCoupon()->getCode());
235244
if ($this->getUsesPerCoupon() == null && !$this->getUseAutoGeneration()) {
236245
$this->setUsesPerCoupon($this->getPrimaryCoupon()->getUsageLimit());
237246
}
238-
return parent::_afterLoad();
239247
}
240248

241249
/**
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\SalesRule\Test\Unit\Model\Plugin\Resource;
8+
9+
class RuleTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* @var \Magento\SalesRule\Model\Plugin\Resource\Rule
13+
*/
14+
protected $plugin;
15+
16+
/**
17+
* @var \PHPUnit_Framework_MockObject_MockObject
18+
*/
19+
protected $ruleResource;
20+
21+
/**
22+
* @var \Closure
23+
*/
24+
protected $genericClosure;
25+
26+
/**
27+
* @var \PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
protected $abstractModel;
30+
31+
public function setUp()
32+
{
33+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
34+
$this->ruleResource = $this->getMockBuilder('Magento\SalesRule\Model\Resource\Rule')
35+
->disableOriginalConstructor()
36+
->getMock();
37+
$this->genericClosure = function () {
38+
return;
39+
};
40+
$this->abstractModel = $this->getMockBuilder('Magento\Framework\Model\AbstractModel')
41+
->disableOriginalConstructor()
42+
->getMockForAbstractClass();
43+
44+
$this->plugin = $objectManager->getObject('Magento\SalesRule\Model\Plugin\Resource\Rule');
45+
}
46+
47+
public function testAroundLoadCustomerGroupIds()
48+
{
49+
$this->assertEquals(
50+
$this->ruleResource,
51+
$this->plugin->aroundLoadCustomerGroupIds($this->ruleResource, $this->genericClosure, $this->abstractModel)
52+
);
53+
}
54+
55+
public function testAroundLoadWebsiteIds()
56+
{
57+
$this->assertEquals(
58+
$this->ruleResource,
59+
$this->plugin->aroundLoadWebsiteIds($this->ruleResource, $this->genericClosure, $this->abstractModel)
60+
);
61+
}
62+
}

0 commit comments

Comments
 (0)