Skip to content

Commit 16ac771

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into develop
2 parents af3f50c + 16274ed commit 16ac771

File tree

192 files changed

+4891
-951
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+4891
-951
lines changed

app/code/Magento/Checkout/Block/Onepage/Success.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ protected function _prepareLastOrder()
104104
{
105105
$orderId = $this->_checkoutSession->getLastOrderId();
106106
if ($orderId) {
107-
$order = $this->_orderFactory->create()->load($orderId);
108-
if ($order->getId()) {
109-
$isVisible = !in_array($order->getStatus(), $this->_orderConfig->getInvisibleOnFrontStatuses());
107+
$incrementId = $this->_checkoutSession->getLastRealOrderId();
108+
$status = $this->_checkoutSession->getLastOrderStatus();
109+
if ($status && $incrementId) {
110+
$isVisible = !in_array($status, $this->_orderConfig->getInvisibleOnFrontStatuses());
110111
$canView = $this->httpContext->getValue(Context::CONTEXT_AUTH) && $isVisible;
111112
$this->addData(
112113
[
@@ -115,7 +116,7 @@ protected function _prepareLastOrder()
115116
'print_url' => $this->getUrl('sales/order/print', ['order_id' => $orderId]),
116117
'can_print_order' => $isVisible,
117118
'can_view_order' => $canView,
118-
'order_id' => $order->getIncrementId(),
119+
'order_id' => $incrementId,
119120
]
120121
);
121122
}

app/code/Magento/Checkout/Model/Type/Onepage.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,14 +983,18 @@ public function saveOrder()
983983
$redirectUrl
984984
)->setLastRealOrderId(
985985
$order->getIncrementId()
986+
)->setLastOrderStatus(
987+
$order->getStatus()
986988
);
987989
}
988990

989991
$this->_eventManager->dispatch(
990992
'checkout_submit_all_after',
991-
['order' => $order, 'quote' => $this->getQuote()]
993+
[
994+
'order' => $order,
995+
'quote' => $this->getQuote()
996+
]
992997
);
993-
994998
return $this;
995999
}
9961000

app/code/Magento/Checkout/Test/Unit/Block/Onepage/SuccessTest.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ class SuccessTest extends \PHPUnit_Framework_TestCase
2121
*/
2222
protected $orderConfig;
2323

24-
/**
25-
* @var \Magento\Sales\Model\OrderFactory | \PHPUnit_Framework_MockObject_MockObject
26-
*/
27-
protected $orderFactory;
28-
2924
/**
3025
* @var \Magento\Checkout\Model\Session | \PHPUnit_Framework_MockObject_MockObject
3126
*/
@@ -36,14 +31,19 @@ protected function setUp()
3631
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
3732

3833
$this->orderConfig = $this->getMock('Magento\Sales\Model\Order\Config', [], [], '', false);
39-
$this->orderFactory = $this->getMock('Magento\Sales\Model\OrderFactory', ['create'], [], '', false);
40-
$this->checkoutSession = $this->getMock('Magento\Checkout\Model\Session', ['getLastOrderId'], [], '', false);
34+
35+
$this->checkoutSession = $this->getMock(
36+
'Magento\Checkout\Model\Session',
37+
['getLastOrderId', 'getLastRealOrderId', 'getLastOrderStatus'],
38+
[],
39+
'',
40+
false
41+
);
4142

4243
$this->block = $objectManager->getObject(
4344
'Magento\Checkout\Block\Onepage\Success',
4445
[
4546
'orderConfig' => $this->orderConfig,
46-
'orderFactory' => $this->orderFactory,
4747
'checkoutSession' => $this->checkoutSession
4848
]
4949
);
@@ -74,28 +74,21 @@ public function testGetAdditionalInfoHtml()
7474
public function testToHtmlOrderVisibleOnFront(array $invisibleStatuses, $orderStatus, $expectedResult)
7575
{
7676
$orderId = 5;
77-
$order = $this->getMock('Magento\Sales\Model\Order', ['getId', '__wakeup', 'load', 'getStatus'], [], '', false);
78-
79-
$order->expects($this->any())
80-
->method('load')
81-
->with($orderId)
82-
->will($this->returnValue($order));
83-
$order->expects($this->any())
84-
->method('getId')
85-
->will($this->returnValue($orderId));
86-
$order->expects($this->any())
87-
->method('getStatus')
88-
->will($this->returnValue($orderStatus));
77+
$realOrderId = 100003332;
8978

9079
$this->checkoutSession->expects($this->once())
9180
->method('getLastOrderId')
9281
->will($this->returnValue($orderId));
82+
$this->checkoutSession->expects($this->once())
83+
->method('getLastRealOrderId')
84+
->will($this->returnValue($realOrderId));
85+
$this->checkoutSession->expects($this->once())
86+
->method('getLastOrderStatus')
87+
->will($this->returnValue($orderStatus));
88+
9389
$this->orderConfig->expects($this->any())
9490
->method('getInvisibleOnFrontStatuses')
9591
->will($this->returnValue($invisibleStatuses));
96-
$this->orderFactory->expects($this->once())
97-
->method('create')
98-
->will($this->returnValue($order));
9992

10093
$this->block->toHtml();
10194

app/code/Magento/Customer/Model/Resource/Address.php

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use Magento\Framework\Exception\InputException;
1111

12-
class Address extends \Magento\Eav\Model\Entity\AbstractEntity
12+
class Address extends \Magento\Eav\Model\Entity\VersionControl\AbstractEntity
1313
{
1414
/**
1515
* @var \Magento\Framework\Validator\Factory
@@ -23,19 +23,23 @@ class Address extends \Magento\Eav\Model\Entity\AbstractEntity
2323

2424
/**
2525
* @param \Magento\Eav\Model\Entity\Context $context
26+
* @param \Magento\Framework\Model\Resource\Db\VersionControl\Snapshot $entitySnapshot,
27+
* @param \Magento\Framework\Model\Resource\Db\VersionControl\RelationComposite $entityRelationComposite,
2628
* @param \Magento\Framework\Validator\Factory $validatorFactory
2729
* @param \Magento\Customer\Model\CustomerFactory $customerFactory
2830
* @param array $data
2931
*/
3032
public function __construct(
3133
\Magento\Eav\Model\Entity\Context $context,
34+
\Magento\Framework\Model\Resource\Db\VersionControl\Snapshot $entitySnapshot,
35+
\Magento\Framework\Model\Resource\Db\VersionControl\RelationComposite $entityRelationComposite,
3236
\Magento\Framework\Validator\Factory $validatorFactory,
3337
\Magento\Customer\Model\CustomerFactory $customerFactory,
3438
$data = []
3539
) {
3640
$this->_validatorFactory = $validatorFactory;
3741
$this->_customerFactory = $customerFactory;
38-
parent::__construct($context, $data);
42+
parent::__construct($context, $entitySnapshot, $entityRelationComposite, $data);
3943
}
4044

4145
/**
@@ -63,31 +67,6 @@ public function getEntityType()
6367
return parent::getEntityType();
6468
}
6569

66-
/**
67-
* Set default shipping to address
68-
*
69-
* @param \Magento\Framework\Object $address
70-
* @return $this
71-
*/
72-
protected function _afterSave(\Magento\Framework\Object $address)
73-
{
74-
if ($address->getIsCustomerSaveTransaction()) {
75-
return $this;
76-
}
77-
if ($address->getId() && ($address->getIsDefaultBilling() || $address->getIsDefaultShipping())) {
78-
$customer = $this->_createCustomer()->load($address->getCustomerId());
79-
80-
if ($address->getIsDefaultBilling()) {
81-
$customer->setDefaultBilling($address->getId());
82-
}
83-
if ($address->getIsDefaultShipping()) {
84-
$customer->setDefaultShipping($address->getId());
85-
}
86-
$customer->save();
87-
}
88-
return $this;
89-
}
90-
9170
/**
9271
* Check customer address before saving
9372
*

app/code/Magento/Customer/Model/Resource/Address/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @author Magento Core Team <core@magentocommerce.com>
1212
*/
13-
class Collection extends \Magento\Eav\Model\Entity\Collection\AbstractCollection
13+
class Collection extends \Magento\Eav\Model\Entity\Collection\VersionControl\AbstractCollection
1414
{
1515
/**
1616
* Resource initialization
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Customer address entity resource model
4+
*
5+
* Copyright © 2015 Magento. All rights reserved.
6+
* See COPYING.txt for license details.
7+
*/
8+
namespace Magento\Customer\Model\Resource\Address;
9+
10+
use Magento\Framework\Model\Resource\Db\VersionControl\RelationInterface;
11+
12+
/**
13+
* Class represents save operations for customer address relations
14+
*/
15+
class Relation implements RelationInterface
16+
{
17+
/**
18+
* @var \Magento\Customer\Model\CustomerFactory
19+
*/
20+
protected $customerFactory;
21+
22+
/**
23+
* @param \Magento\Customer\Model\CustomerFactory $customerFactory
24+
*/
25+
public function __construct(\Magento\Customer\Model\CustomerFactory $customerFactory)
26+
{
27+
$this->customerFactory = $customerFactory;
28+
}
29+
30+
/**
31+
* Process object relations
32+
*
33+
* @param \Magento\Framework\Model\AbstractModel $object
34+
* @return void
35+
*/
36+
public function processRelation(\Magento\Framework\Model\AbstractModel $object)
37+
{
38+
/**
39+
* @var $object \Magento\Customer\Model\Address
40+
*/
41+
if (!$object->getIsCustomerSaveTransaction() && $this->isAddressDefault($object)) {
42+
$customer = $this->customerFactory->create()->load($object->getCustomerId());
43+
$changedAddresses = [];
44+
45+
if ($object->getIsDefaultBilling()) {
46+
$changedAddresses['default_billing'] = $object->getId();
47+
}
48+
49+
if ($object->getIsDefaultShipping()) {
50+
$changedAddresses['default_shipping'] = $object->getId();
51+
}
52+
53+
if ($changedAddresses) {
54+
$customer->getResource()->getWriteConnection()->update(
55+
$customer->getResource()->getTable('customer_entity'),
56+
$changedAddresses,
57+
$customer->getResource()->getWriteConnection()->quoteInto('entity_id = ?', $customer->getId())
58+
);
59+
}
60+
}
61+
}
62+
63+
/**
64+
* Checks if address has chosen as default and has had an id
65+
*
66+
* @param \Magento\Framework\Model\AbstractModel $object
67+
* @return bool
68+
*/
69+
protected function isAddressDefault(\Magento\Framework\Model\AbstractModel $object)
70+
{
71+
return $object->getId() && ($object->getIsDefaultBilling() || $object->getIsDefaultShipping());
72+
}
73+
}

app/code/Magento/Customer/Model/Resource/Customer.php

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Customer entity resource model
1313
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1414
*/
15-
class Customer extends \Magento\Eav\Model\Entity\AbstractEntity
15+
class Customer extends \Magento\Eav\Model\Entity\VersionControl\AbstractEntity
1616
{
1717
/**
1818
* @var \Magento\Framework\Validator\Factory
@@ -33,19 +33,23 @@ class Customer extends \Magento\Eav\Model\Entity\AbstractEntity
3333

3434
/**
3535
* @param \Magento\Eav\Model\Entity\Context $context
36+
* @param \Magento\Framework\Model\Resource\Db\VersionControl\Snapshot $entitySnapshot
37+
* @param \Magento\Framework\Model\Resource\Db\VersionControl\RelationComposite $entityRelationComposite
3638
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
3739
* @param \Magento\Framework\Validator\Factory $validatorFactory
3840
* @param \Magento\Framework\Stdlib\DateTime $dateTime
3941
* @param array $data
4042
*/
4143
public function __construct(
4244
\Magento\Eav\Model\Entity\Context $context,
45+
\Magento\Framework\Model\Resource\Db\VersionControl\Snapshot $entitySnapshot,
46+
\Magento\Framework\Model\Resource\Db\VersionControl\RelationComposite $entityRelationComposite,
4347
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
4448
\Magento\Framework\Validator\Factory $validatorFactory,
4549
\Magento\Framework\Stdlib\DateTime $dateTime,
4650
$data = []
4751
) {
48-
parent::__construct($context, $data);
52+
parent::__construct($context, $entitySnapshot, $entityRelationComposite, $data);
4953
$this->_scopeConfig = $scopeConfig;
5054
$this->_validatorFactory = $validatorFactory;
5155
$this->dateTime = $dateTime;
@@ -149,72 +153,14 @@ protected function _validate($customer)
149153
/**
150154
* Save customer addresses and set default addresses in attributes backend
151155
*
152-
* @param \Magento\Customer\Model\Customer $customer
156+
* @param \Magento\Framework\Object $customer
153157
* @return $this
154158
*/
155159
protected function _afterSave(\Magento\Framework\Object $customer)
156160
{
157-
$this->_saveAddresses($customer);
158161
return parent::_afterSave($customer);
159162
}
160163

161-
/**
162-
* Save/delete customer address
163-
*
164-
* @param \Magento\Customer\Model\Customer $customer
165-
* @return $this
166-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
167-
*/
168-
protected function _saveAddresses(\Magento\Customer\Model\Customer $customer)
169-
{
170-
$defaultBillingId = $customer->getData('default_billing');
171-
$defaultShippingId = $customer->getData('default_shipping');
172-
/** @var \Magento\Customer\Model\Address $address */
173-
foreach ($customer->getAddresses() as $address) {
174-
if ($address->getData('_deleted')) {
175-
if ($address->getId() == $defaultBillingId) {
176-
$customer->setData('default_billing', null);
177-
}
178-
if ($address->getId() == $defaultShippingId) {
179-
$customer->setData('default_shipping', null);
180-
}
181-
$removedAddressId = $address->getId();
182-
$address->delete();
183-
// Remove deleted address from customer address collection
184-
$customer->getAddressesCollection()->removeItemByKey($removedAddressId);
185-
} else {
186-
$address->setParentId(
187-
$customer->getId()
188-
)->setStoreId(
189-
$customer->getStoreId()
190-
)->setIsCustomerSaveTransaction(
191-
true
192-
)->save();
193-
if (($address->getIsPrimaryBilling() ||
194-
$address->getIsDefaultBilling()) && $address->getId() != $defaultBillingId
195-
) {
196-
$customer->setData('default_billing', $address->getId());
197-
}
198-
if (($address->getIsPrimaryShipping() ||
199-
$address->getIsDefaultShipping()) && $address->getId() != $defaultShippingId
200-
) {
201-
$customer->setData('default_shipping', $address->getId());
202-
}
203-
}
204-
}
205-
$changedAddresses = [];
206-
207-
$changedAddresses['default_billing'] = $customer->getData('default_billing');
208-
$changedAddresses['default_shipping'] = $customer->getData('default_shipping');
209-
$this->_getWriteAdapter()->update(
210-
$this->getTable('customer_entity'),
211-
$changedAddresses,
212-
$this->_getWriteAdapter()->quoteInto('entity_id = ?', $customer->getId())
213-
);
214-
215-
return $this;
216-
}
217-
218164
/**
219165
* Retrieve select object for loading base entity row
220166
*

0 commit comments

Comments
 (0)