Skip to content

Commit

Permalink
Merge pull request #519 from magento-folks/bugfix
Browse files Browse the repository at this point in the history
[Folks] Bugfix
  • Loading branch information
guz-anton committed Apr 6, 2016
2 parents f732a63 + e9fe699 commit a89acbb
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
*/
/*jshint browser:true jquery:true*/
/*global alert*/
define([], function() {
define([], function () {
/**
* @param addressData
* @param {Object} addressData
* Returns new address object
*/
return function (addressData) {
var identifier = Date.now();

return {
email: addressData.email,
countryId: (addressData.country_id) ? addressData.country_id : window.checkoutConfig.defaultCountryId,
regionId: (addressData.region && addressData.region.region_id)
? addressData.region.region_id
regionId: (addressData.region && addressData.region.region_id) ?
addressData.region.region_id
: window.checkoutConfig.defaultRegionId,
regionCode: (addressData.region) ? addressData.region.region_code : null,
region: (addressData.region) ? addressData.region.region : null,
Expand All @@ -33,25 +34,26 @@ define([], function() {
suffix: addressData.suffix,
vatId: addressData.vat_id,
saveInAddressBook: addressData.save_in_address_book,
isDefaultShipping: function() {
customAttributes: addressData.custom_attributes,
isDefaultShipping: function () {
return addressData.default_shipping;
},
isDefaultBilling: function() {
isDefaultBilling: function () {
return addressData.default_billing;
},
getType: function() {
getType: function () {
return 'new-customer-address';
},
getKey: function() {
getKey: function () {
return this.getType();
},
getCacheKey: function() {
getCacheKey: function () {
return this.getType() + identifier;
},
isEditable: function() {
isEditable: function () {
return true;
},
canUseForBilling: function() {
canUseForBilling: function () {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ define(
return totals;
},
setTotals: function(totalsData) {
if (_.isObject(totalsData.extension_attributes)) {
if (_.isObject(totalsData) && _.isObject(totalsData.extension_attributes)) {
_.each(totalsData.extension_attributes, function(element, index) {
totalsData[index] = element;
});
Expand Down
28 changes: 28 additions & 0 deletions app/code/Magento/Customer/Model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress
*/
protected $indexerRegistry;

/**
* @var \Magento\Customer\Model\Address\CustomAttributeListInterface
*/
private $attributeList;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand Down Expand Up @@ -347,4 +352,27 @@ public function reindex()
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
$indexer->reindexRow($this->getCustomerId());
}

/**
* {@inheritdoc}
*/
protected function getCustomAttributesCodes()
{
return array_keys($this->getAttributeList()->getAttributes());
}

/**
* Get new AttributeList dependency for application code.
* @return \Magento\Customer\Model\Address\CustomAttributeListInterface
* @deprecated
*/
private function getAttributeList()
{
if (!$this->attributeList) {
$this->attributeList = \Magento\Framework\App\ObjectManager::getInstance()->get(
\Magento\Customer\Model\Address\CustomAttributeListInterface::class
);
}
return $this->attributeList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public function setData($key, $value = null)
{
if (is_array($key)) {
$key = $this->_implodeArrayField($key);
} elseif (is_array($value) && $this->isAddressMultilineAttribute($key)) {
} elseif (is_array($value) && !empty($value) && $this->isAddressMultilineAttribute($key)) {
$value = $this->_implodeArrayValues($value);
}
return parent::setData($key, $value);
Expand Down
17 changes: 17 additions & 0 deletions app/code/Magento/Customer/Model/Address/CustomAttributeList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Model\Address;

class CustomAttributeList implements CustomAttributeListInterface
{
/**
* {@inheritdoc}
*/
public function getAttributes()
{
return [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Model\Address;

interface CustomAttributeListInterface
{
/**
* Retrieve list of customer addresses custom attributes
*
* @return array
*/
public function getAttributes();
}
2 changes: 2 additions & 0 deletions app/code/Magento/Customer/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
type="Magento\Customer\Model\EmailNotification" />
<preference for="Magento\Customer\Api\CustomerNameGenerationInterface"
type="Magento\Customer\Helper\View" />
<preference for="Magento\Customer\Model\Address\CustomAttributeListInterface"
type="Magento\Customer\Model\Address\CustomAttributeList" />
<type name="Magento\Customer\Model\Session">
<arguments>
<argument name="configShare" xsi:type="object">Magento\Customer\Model\Config\Share\Proxy</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ define([], function() {
vatId: addressData.vat_id,
sameAsBilling: addressData.same_as_billing,
saveInAddressBook: addressData.save_in_address_book,
customAttributes: addressData.custom_attributes,
isDefaultShipping: function() {
return addressData.default_shipping;
},
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/Quote/Model/Quote/Item/Compare.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ protected function getOptionValues($value)
if (is_string($value) && is_array(@unserialize($value))) {
$value = @unserialize($value);
unset($value['qty'], $value['uenc']);
$value = array_filter($value, function ($optionValue) {
return !empty($optionValue);
});
}
return $value;
}
Expand Down
25 changes: 25 additions & 0 deletions app/code/Magento/Quote/Model/QuoteManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
use Magento\Sales\Api\OrderManagementInterface as OrderManagement;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Quote\Model\Quote\Address;
use Magento\Framework\App\ObjectManager;
use Magento\Quote\Model\QuoteIdMaskFactory;

/**
* Class QuoteManagement
Expand Down Expand Up @@ -130,6 +132,11 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface
*/
protected $quoteFactory;

/**
* @var QuoteIdMaskFactory
*/
private $quoteIdMaskFactory;

/**
* @param EventManager $eventManager
* @param QuoteValidator $quoteValidator
Expand Down Expand Up @@ -262,6 +269,12 @@ public function assignCustomer($cartId, $customerId, $storeId)

$quote->setCustomer($customer);
$quote->setCustomerIsGuest(0);
$quoteIdMaskFactory = $this->getQuoteIdMaskFactory();
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
$quoteIdMask = $quoteIdMaskFactory->create()->load($cartId, 'quote_id');
if ($quoteIdMask->getId()) {
$quoteIdMask->delete();
}
$this->quoteRepository->save($quote);
return true;

Expand Down Expand Up @@ -547,4 +560,16 @@ protected function _prepareCustomerQuote($quote)
$shipping->setIsDefaultBilling(true);
}
}

/**
* @return QuoteIdMaskFactory
* @deprecated
*/
private function getQuoteIdMaskFactory()
{
if (!$this->quoteIdMaskFactory) {
$this->quoteIdMaskFactory = ObjectManager::getInstance()->get(QuoteIdMaskFactory::class);
}
return $this->quoteIdMaskFactory;
}
}
27 changes: 27 additions & 0 deletions app/code/Magento/Quote/Test/Unit/Model/Quote/Item/CompareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,31 @@ public function testCompareItemWithoutOptionWithCompared()
->will($this->returnValue([]));
$this->assertFalse($this->helper->compare($this->itemMock, $this->comparedMock));
}

/**
* Verify that compare ignores empty options.
*/
public function testCompareWithEmptyValues()
{
$this->itemMock->expects($this->any())
->method('getProductId')
->will($this->returnValue(1));
$this->comparedMock->expects($this->any())
->method('getProductId')
->will($this->returnValue(1));

$this->itemMock->expects($this->once())->method('getOptions')->willReturn([
$this->getOptionMock('option-1', serialize([
'non-empty-option' => 'test',
'empty_option' => ''
]))
]);
$this->comparedMock->expects($this->once())->method('getOptions')->willReturn([
$this->getOptionMock('option-1', serialize([
'non-empty-option' => 'test'
]))
]);

$this->assertTrue($this->helper->compare($this->itemMock, $this->comparedMock));
}
}
53 changes: 49 additions & 4 deletions app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class QuoteManagementTest extends \PHPUnit_Framework_TestCase
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $quoteFactoryMock;
private $quoteIdMock;

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
Expand Down Expand Up @@ -238,7 +238,6 @@ protected function setUp()
);

$this->quoteFactoryMock = $this->getMock('\Magento\Quote\Model\QuoteFactory', ['create'], [], '', false);

$this->model = $objectManager->getObject(
'\Magento\Quote\Model\QuoteManagement',
[
Expand All @@ -264,6 +263,12 @@ protected function setUp()
'quoteFactory' => $this->quoteFactoryMock
]
);

// Set the new dependency
$this->quoteIdMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false);
$quoteIdFactoryMock = $this->getMock(\Magento\Quote\Model\QuoteIdMaskFactory::class, ['create'], [], '', false);
$this->setPropertyValue($this->model, 'quoteIdMaskFactory', $quoteIdFactoryMock);

}

public function testCreateEmptyCartAnonymous()
Expand Down Expand Up @@ -508,6 +513,13 @@ public function testAssignCustomer()
$customerId = 455;
$storeId = 5;

$this->getPropertyValue($this->model, 'quoteIdMaskFactory')
->expects($this->once())
->method('create')
->willReturn($this->quoteIdMock);
$this->quoteIdMock->expects($this->once())->method('load')->with($cartId, 'quote_id')->willReturnSelf();
$this->quoteIdMock->expects($this->once())->method('getId')->willReturn(10);
$this->quoteIdMock->expects($this->once())->method('delete');
$quoteMock = $this->getMock(
'\Magento\Quote\Model\Quote',
['getCustomerId', 'setCustomer', 'setCustomerIsGuest'],
Expand Down Expand Up @@ -739,7 +751,7 @@ public function testPlaceOrderIfCustomerIsGuest()
$this->checkoutSessionMock->expects($this->once())->method('setLastOrderId')->with($orderId);
$this->checkoutSessionMock->expects($this->once())->method('setLastRealOrderId')->with($orderIncrementId);
$this->checkoutSessionMock->expects($this->once())->method('setLastOrderStatus')->with($orderStatus);

$this->assertEquals($orderId, $service->placeOrder($cartId));
}

Expand Down Expand Up @@ -935,7 +947,7 @@ protected function prepareOrderFactory(
$order = $this->getMock(
'Magento\Sales\Model\Order',
['setShippingAddress', 'getAddressesCollection', 'getAddresses', 'getBillingAddress', 'addAddresses',
'setBillingAddress', 'setAddresses', 'setPayment', 'setItems', 'setQuoteId'],
'setBillingAddress', 'setAddresses', 'setPayment', 'setItems', 'setQuoteId'],
[],
'',
false
Expand Down Expand Up @@ -979,4 +991,37 @@ public function testGetCartForCustomer()
->willReturn($cartMock);
$this->assertEquals($cartMock, $this->model->getCartForCustomer($customerId));
}

/**
* Get any object property value.
*
* @param $object
* @param $property
* @return mixed
*/
protected function getPropertyValue($object, $property)
{
$reflection = new \ReflectionClass(get_class($object));
$reflectionProperty = $reflection->getProperty($property);
$reflectionProperty->setAccessible(true);

return $reflectionProperty->getValue($object);
}

/**
* Set object property value.
*
* @param $object
* @param $property
* @param $value
*/
protected function setPropertyValue(&$object, $property, $value)
{
$reflection = new \ReflectionClass(get_class($object));
$reflectionProperty = $reflection->getProperty($property);
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($object, $value);

return $object;
}
}
Loading

0 comments on commit a89acbb

Please sign in to comment.