Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/develop' into BUGS
Browse files Browse the repository at this point in the history
  • Loading branch information
slavvka committed Jun 3, 2016
2 parents ed44e7f + 383362a commit ff3138e
Show file tree
Hide file tree
Showing 45 changed files with 466 additions and 252 deletions.
24 changes: 7 additions & 17 deletions app/code/Magento/Backend/Model/Session/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,16 @@ public function __construct(
*/
public function getQuote()
{
$cartManagement = $this->getCartManagement();

if ($this->_quote === null) {
$this->_quote = $this->quoteFactory->create();
if ($this->getStoreId()) {
if (!$this->getQuoteId()) {
$this->setQuoteId($cartManagement->createEmptyCart());
$this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]);
$this->_quote->setCustomerGroupId($this->groupManagement->getDefaultGroup()->getId());
$this->_quote->setIsActive(false);
$this->_quote->setStoreId($this->getStoreId());

$this->quoteRepository->save($this->_quote);
$this->setQuoteId($this->_quote->getId());
$this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]);
} else {
$this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]);
$this->_quote->setStoreId($this->getStoreId());
Expand All @@ -167,6 +168,7 @@ public function getQuote()
if ($this->getCustomerId() && $this->getCustomerId() != $this->_quote->getCustomerId()) {
$customer = $this->customerRepository->getById($this->getCustomerId());
$this->_quote->assignCustomer($customer);
$this->quoteRepository->save($this->_quote);
}
}
$this->_quote->setIgnoreOldQty(true);
Expand All @@ -176,18 +178,6 @@ public function getQuote()
return $this->_quote;
}

/**
* @return CartManagementInterface
* @deprecated
*/
private function getCartManagement()
{
if ($this->cartManagement === null) {
$this->cartManagement = ObjectManager::getInstance()->get(CartManagementInterface::class);
}
return $this->cartManagement;
}

/**
* Retrieve store model object
*
Expand Down
75 changes: 59 additions & 16 deletions app/code/Magento/Backend/Test/Unit/Model/Session/QuoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class QuoteTest extends \PHPUnit_Framework_TestCase
protected $cookieManagerMock;

/**
* @var \Magento\Framework\Session\StorageInterface|\PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Framework\Session\StorageInterface
*/
protected $storageMock;
protected $storage;

/**
* @var \Magento\Framework\Session\ValidatorInterface|\PHPUnit_Framework_MockObject_MockObject
Expand Down Expand Up @@ -166,12 +166,7 @@ protected function setUp()
'',
false
);
$this->storageMock = $this->getMockForAbstractClass(
'Magento\Framework\Session\StorageInterface',
[],
'',
false
);
$this->storage = new \Magento\Framework\Session\Storage();
$this->cookieManagerMock = $this->getMock('Magento\Framework\Stdlib\CookieManagerInterface');
$this->cookieMetadataFactoryMock = $this->getMock(
'Magento\Framework\Stdlib\Cookie\CookieMetadataFactory',
Expand Down Expand Up @@ -219,7 +214,7 @@ protected function setUp()
'sessionConfig' => $this->sessionConfigMock,
'saveHandler' => $this->saveHandlerMock,
'validator' => $this->validatorMock,
'storage' => $this->storageMock,
'storage' => $this->storage,
'cookieManager' => $this->cookieManagerMock,
'cookieMetadataFactory' => $this->cookieMetadataFactoryMock,
'appState' => $appStateMock,
Expand Down Expand Up @@ -249,20 +244,72 @@ public function testGetQuoteWithoutQuoteId()
$customerId = 66;
$customerGroupId = 77;

$this->cartManagementMock->expects($this->once())->method('createEmptyCart')->willReturn($quoteId);

$this->quote->expects($this->any())
->method('getQuoteId')
->will($this->returnValue(null));
$this->quote->expects($this->any())
->method('setQuoteId')
->with($quoteId);
$cartInterfaceMock = $this->getMock(
'\Magento\Quote\Api\Data\CartInterface',
[
'getId',
'setId',
'getCreatedAt',
'setCreatedAt',
'getUpdatedAt',
'setUpdatedAt',
'getConvertedAt',
'setConvertedAt',
'getIsActive',
'setIsActive',
'getIsVirtual',
'getItems',
'setItems',
'getItemsCount',
'setItemsCount',
'getItemsQty',
'setItemsQty',
'getCustomer',
'setCustomer',
'getBillingAddress',
'setBillingAddress',
'getReservedOrderId',
'setReservedOrderId',
'getOrigOrderId',
'setOrigOrderId',
'getCurrency',
'setCurrency',
'getCustomerIsGuest',
'setCustomerIsGuest',
'getCustomerNote',
'setCustomerNote',
'getCustomerNoteNotify',
'setCustomerNoteNotify',
'getCustomerTaxClassId',
'setCustomerTaxClassId',
'getStoreId',
'setStoreId',
'getExtensionAttributes',
'setExtensionAttributes',
'setIgnoreOldQty',
'setIsSuperMode',
'setCustomerGroupId'
]
);
$this->quoteFactoryMock->expects($this->once())
->method('create')
->willReturn($cartInterfaceMock);
$this->quote->expects($this->any())
->method('getStoreId')
->will($this->returnValue($storeId));
$this->quote->expects($this->any())
->method('getCustomerId')
->will($this->returnValue($customerId));
$cartInterfaceMock->expects($this->atLeastOnce())
->method('getId')
->willReturn($quoteId);


$defaultGroup = $this->getMockBuilder('Magento\Customer\Api\Data\GroupInterface')
->getMock();
Expand Down Expand Up @@ -297,14 +344,10 @@ public function testGetQuoteWithoutQuoteId()
false
);
$this->quoteRepositoryMock->expects($this->once())->method('get')->willReturn($quoteMock);
$quoteMock->expects($this->once())
$cartInterfaceMock->expects($this->once())
->method('setCustomerGroupId')
->with($customerGroupId)
->will($this->returnSelf());
$quoteMock->expects($this->once())
->method('setIsActive')
->with(false)
->will($this->returnSelf());
$quoteMock->expects($this->once())
->method('assignCustomer')
->with($dataCustomerMock);
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Checkout/view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
</item>
</argument>
</arguments>
<container name="minicart.addons" label="Mini-cart promotion block"/>
</block>
</referenceContainer>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<div id="minicart-content-wrapper" data-bind="scope: 'minicart_content'">
<!-- ko template: getTemplate() --><!-- /ko -->
</div>
<?php echo $block->getChildHtml('minicart.addons'); ?>
</div>
<?php endif ?>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ define(
},

addressToEstimationAddress: function (address) {
var estimatedAddressData = {
country_id: address.countryId,
region: address.region,
region_id: address.regionId,
postcode: address.postcode
};
return this.formAddressDataToQuoteAddress(estimatedAddressData);
var self = this;
var estimatedAddressData = {};

$.each(address, function (key) {
estimatedAddressData[self.toUnderscore(key)] = address[key];
});
return this.formAddressDataToQuoteAddress(estimatedAddressData);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ define(
var checkoutConfig = window.checkoutConfig,
validators = [],
observedElements = [],
postcodeElement = null;
postcodeElement = null,
postcodeElementName = 'postcode';

return {
validateAddressTimeout: 0,
Expand All @@ -50,7 +51,7 @@ define(
* @return {Boolean}
*/
validateAddressData: function (address) {
return validators.some(function(validator) {
return validators.some(function (validator) {
return validator.validate(address);
});
},
Expand All @@ -64,6 +65,11 @@ define(
var self = this,
elements = shippingRatesValidationRules.getObservableFields();

if ($.inArray(postcodeElementName, elements) === -1) {
// Add postcode field to observables if not exist for zip code validation support
elements.push(postcodeElementName);
}

$.each(elements, function (index, field) {
uiRegistry.async(formPath + '.' + field)(self.doElementBinding.bind(self));
});
Expand All @@ -80,12 +86,12 @@ define(
var observableFields = shippingRatesValidationRules.getObservableFields();

if (element && (observableFields.indexOf(element.index) !== -1 || force)) {
if (element.index !== 'postcode') {
if (element.index !== postcodeElementName) {
this.bindHandler(element, delay);
}
}

if (element.index === 'postcode') {
if (element.index === postcodeElementName) {
this.bindHandler(element, delay);
postcodeElement = element;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ define([

event.preventDefault();

if (!customer().firstname && !cart().isGuestCheckoutAllowed) {
if (!customer().firstname && cart().isGuestCheckoutAllowed === false) {
authenticationPopup.showModal();

return false;
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Checkout/view/frontend/web/js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ define([
var cart = customerData.get('cart'),
customer = customerData.get('customer');

if (!customer().firstname && !cart().isGuestCheckoutAllowed) {
if (!customer().firstname && cart().isGuestCheckoutAllowed === false) {
// set URL for redirect on successful login/registration. It's postprocessed on backend.
$.cookie('login_redirect', this.options.url.checkout);
if (this.options.url.isRedirectRequired) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ define(
if (customer.isLoggedIn() && !this.customerHasAddresses) {
this.saveInAddressBook(1);
}
addressData.save_in_address_book = this.saveInAddressBook();
addressData.save_in_address_book = this.saveInAddressBook() ? 1 : 0;
newBillingAddress = createBillingAddress(addressData);

// New address must be selected as a billing address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ define(

if (!this.source.get('params.invalid')) {
addressData = this.source.get('shippingAddress');
addressData.save_in_address_book = this.saveInAddressBook;
// if user clicked the checkbox, its value is true or false. Need to convert.
addressData.save_in_address_book = this.saveInAddressBook ? 1 : 0;

// New address must be selected as a shipping address
newShippingAddress = createShippingAddress(addressData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
<div data-bind="text: error_message"></div>
<!-- /ko -->
<!-- ko if: (available) -->
<input name="estimate_method"
type="radio"
<input type="radio"
class="radio"
data-bind="
click: $parents[1].selectShippingMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@
<td class="col col-method">
<!-- ko ifnot: method.error_message -->
<!-- ko if: $parent.rates().length == 1 -->
<input name="shipping_method"
class="radio"
<input class="radio"
type="radio"
data-bind="attr: {
checked: $parent.rates().length == 1,
Expand All @@ -92,7 +91,7 @@
}" />
<!-- /ko -->
<!--ko ifnot: ($parent.rates().length == 1)-->
<input name="shipping_method" type="radio"
<input type="radio"
data-bind="
value: method.carrier_code + '_' + method.method_code,
checked: $parent.isSelected,
Expand Down Expand Up @@ -125,7 +124,7 @@
<div data-bind="text: method.error_message"></div>
</div>
<span class="no-display">
<input name="shipping_method" type="radio" data-bind="attr: {'value' : method.method_code, 'id': 's_method_' + method.method_code}"/>
<input type="radio" data-bind="attr: {'value' : method.method_code, 'id': 's_method_' + method.method_code}"/>
</span>
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ define(
],
function ($, modal) {
'use strict';

return {
modalWindow: null,

/** Create popUp window for provided element */
createPopUp: function(element) {
createPopUp: function (element) {
this.modalWindow = element;
var options = {
'type': 'popup',
Expand All @@ -29,7 +30,7 @@ define(
},

/** Show login popup window */
showModal: function() {
showModal: function () {
$(this.modalWindow).modal('openModal');
}
}
Expand Down
Loading

0 comments on commit ff3138e

Please sign in to comment.