Skip to content

Commit 8007ad1

Browse files
Merge pull request #435 from magento-folks/bugfix
Bugs MAGETWO-56752 Fix, verify and unisolate CreateTaxRuleEntityTest::CreateTaxRuleEntityTestVariation5 MAGETWO-56159 Newsletter need to confirm doesn't work MAGETWO-54776 User unable to do a full payment with gift card for the order containing gift wrap MAGETWO-58062 Ship To section on Checkout's Review & Payments step, clears out the Ship To address on page reload MAGETWO-58609 default_frontend_label is ignored on REST product attributes call MAGETWO-58677 Cart Price Rule (coupon) works no longer than current date MAGETWO-58269 [GitHub] Error in 'useForShipping'-parameter when saving billing address via API #6557
2 parents 14028aa + c5c94de commit 8007ad1

File tree

18 files changed

+343
-28
lines changed

18 files changed

+343
-28
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/Repository.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ public function save(\Magento\Catalog\Api\Data\ProductAttributeInterface $attrib
125125
$attribute->setFrontendInput($existingModel->getFrontendInput());
126126

127127
if (is_array($attribute->getFrontendLabels())) {
128-
$frontendLabel[0] = $existingModel->getDefaultFrontendLabel();
128+
$defaultFrontendLabel = $attribute->getDefaultFrontendLabel();
129+
$frontendLabel[0] = !empty($defaultFrontendLabel)
130+
? $defaultFrontendLabel
131+
: $existingModel->getDefaultFrontendLabel();
129132
foreach ($attribute->getFrontendLabels() as $item) {
130133
$frontendLabel[$item->getStoreId()] = $item->getLabel();
131134
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/RepositoryTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Catalog\Model\Product\Attribute\Repository;
1313
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
1414
use Magento\Catalog\Api\Data\ProductAttributeInterface;
15+
use Magento\Eav\Api\Data\AttributeFrontendLabelInterface;
1516

1617
/**
1718
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -288,4 +289,42 @@ public function testSaveDoesNotSaveAttributeOptionsIfOptionsAreAbsentInPayload()
288289

289290
$this->model->save($attributeMock);
290291
}
292+
293+
public function testSaveSavesDefaultFrontendLabelIfItIsPresentInPayload()
294+
{
295+
$labelMock = $this->getMock(AttributeFrontendLabelInterface::class);
296+
$labelMock->expects($this->any())->method('getStoreId')->willReturn(1);
297+
$labelMock->expects($this->any())->method('getLabel')->willReturn('Store Scope Label');
298+
299+
$attributeId = 1;
300+
$attributeCode = 'existing_attribute_code';
301+
$attributeMock = $this->getMock(Attribute::class, [], [], '', false);
302+
$attributeMock->expects($this->any())->method('getAttributeCode')->willReturn($attributeCode);
303+
$attributeMock->expects($this->any())->method('getAttributeId')->willReturn($attributeId);
304+
$attributeMock->expects($this->any())->method('getDefaultFrontendLabel')->willReturn('Default Label');
305+
$attributeMock->expects($this->any())->method('getFrontendLabels')->willReturn([$labelMock]);
306+
$attributeMock->expects($this->any())->method('getOptions')->willReturn([]);
307+
308+
309+
$existingModelMock = $this->getMock(Attribute::class, [], [], '', false);
310+
$existingModelMock->expects($this->any())->method('getAttributeId')->willReturn($attributeId);
311+
$existingModelMock->expects($this->any())->method('getAttributeCode')->willReturn($attributeCode);
312+
313+
$this->eavAttributeRepositoryMock->expects($this->any())
314+
->method('get')
315+
->with(ProductAttributeInterface::ENTITY_TYPE_CODE, $attributeCode)
316+
->willReturn($existingModelMock);
317+
318+
$attributeMock->expects($this->once())
319+
->method('setDefaultFrontendLabel')
320+
->with(
321+
[
322+
0 => 'Default Label',
323+
1 => 'Store Scope Label'
324+
]
325+
);
326+
$this->attributeResourceMock->expects($this->once())->method('save')->with($attributeMock);
327+
328+
$this->model->save($attributeMock);
329+
}
291330
}

app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ define([], function () {
2121

2222
return {
2323
email: addressData.email,
24-
countryId: (addressData.country_id) ? addressData.country_id : window.checkoutConfig.defaultCountryId,
24+
countryId: addressData['country_id'] || addressData.countryId || window.checkoutConfig.defaultCountryId,
2525
regionId: regionId,
2626
regionCode: (addressData.region) ? addressData.region.region_code : null,
2727
region: (addressData.region) ? addressData.region.region : null,

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ define(
1212
'../action/select-shipping-address',
1313
'./postcode-validator',
1414
'mage/translate',
15-
'uiRegistry'
15+
'uiRegistry',
16+
'Magento_Checkout/js/model/quote'
1617
],
1718
function (
1819
$,
@@ -22,7 +23,8 @@ define(
2223
selectShippingAddress,
2324
postcodeValidator,
2425
$t,
25-
uiRegistry
26+
uiRegistry,
27+
quote
2628
) {
2729
'use strict';
2830

@@ -41,7 +43,7 @@ define(
4143
* @param {Object} validator
4244
*/
4345
registerValidator: function (carrier, validator) {
44-
if (checkoutConfig.activeCarriers.indexOf(carrier) != -1) {
46+
if (checkoutConfig.activeCarriers.indexOf(carrier) !== -1) {
4547
validators.push(validator);
4648
}
4749
},
@@ -174,6 +176,7 @@ define(
174176
address;
175177

176178
if (this.validateAddressData(addressFlat)) {
179+
addressFlat = $.extend(true, {}, quote.shippingAddress(), addressFlat);
177180
address = addressConverter.formAddressDataToQuoteAddress(addressFlat);
178181
selectShippingAddress(address);
179182
}

app/code/Magento/Newsletter/Model/Subscriber.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,17 @@ protected function _updateCustomerSubscription($customerId, $subscribe)
542542

543543
$sendInformationEmail = false;
544544
$status = self::STATUS_SUBSCRIBED;
545+
$isConfirmNeed = $this->_scopeConfig->getValue(
546+
self::XML_PATH_CONFIRMATION_FLAG,
547+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
548+
) == 1 ? true : false;
545549
if ($subscribe) {
546550
if (AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED
547551
== $this->customerAccountManagement->getConfirmationStatus($customerId)
548552
) {
549553
$status = self::STATUS_UNCONFIRMED;
554+
} else if ($isConfirmNeed) {
555+
$status = self::STATUS_NOT_ACTIVE;
550556
}
551557
} else {
552558
$status = self::STATUS_UNSUBSCRIBED;
@@ -581,7 +587,9 @@ protected function _updateCustomerSubscription($customerId, $subscribe)
581587
$sendSubscription = $sendInformationEmail;
582588
if ($sendSubscription === null xor $sendSubscription) {
583589
try {
584-
if ($this->isStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) {
590+
if ($isConfirmNeed) {
591+
$this->sendConfirmationRequestEmail();
592+
} else if ($this->isStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) {
585593
$this->sendUnsubscriptionEmail();
586594
} elseif ($this->isStatusChanged() && $status == self::STATUS_SUBSCRIBED) {
587595
$this->sendConfirmationSuccessEmail();

app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,37 @@ public function testSubscribeCustomerById()
260260
$this->subscriber->subscribeCustomerById($customerId);
261261
}
262262

263+
public function testSubscribeCustomerById1()
264+
{
265+
$customerId = 1;
266+
$customerDataMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
267+
->getMock();
268+
$this->customerRepository->expects($this->atLeastOnce())
269+
->method('getById')
270+
->with($customerId)->willReturn($customerDataMock);
271+
$this->resource->expects($this->atLeastOnce())
272+
->method('loadByCustomerData')
273+
->with($customerDataMock)
274+
->willReturn(
275+
[
276+
'subscriber_id' => 1,
277+
'subscriber_status' => 3
278+
]
279+
);
280+
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
281+
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
282+
$customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
283+
$customerDataMock->expects($this->once())->method('getEmail')->willReturn('email');
284+
$this->sendEmailCheck();
285+
$this->customerAccountManagement->expects($this->once())
286+
->method('getConfirmationStatus')
287+
->willReturn(\Magento\Customer\Api\AccountManagementInterface::ACCOUNT_CONFIRMATION_NOT_REQUIRED);
288+
$this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true);
289+
290+
$this->subscriber->subscribeCustomerById($customerId);
291+
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus());
292+
}
293+
263294
public function testUnsubscribe()
264295
{
265296
$this->resource->expects($this->once())->method('save')->willReturnSelf();

app/code/Magento/Quote/Api/GuestBillingAddressManagementInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ interface GuestBillingAddressManagementInterface
1616
*
1717
* @param string $cartId The cart ID.
1818
* @param \Magento\Quote\Api\Data\AddressInterface $address Billing address data.
19+
* @param bool $useForShipping
1920
* @return int Address ID.
2021
* @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist.
2122
* @throws \Magento\Framework\Exception\InputException The specified cart ID or address data is not valid.
2223
*/
23-
public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address);
24+
public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address, $useForShipping = false);
2425

2526
/**
2627
* Return the billing address for a specified quote.

app/code/Magento/Quote/Model/BillingAddressManagement.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class BillingAddressManagement implements BillingAddressManagementInterface
4040
*/
4141
protected $addressRepository;
4242

43+
/**
44+
* @var \Magento\Quote\Model\ShippingAddressAssignment
45+
*/
46+
private $shippingAddressAssignment;
47+
4348
/**
4449
* Constructs a quote billing address service object.
4550
*
@@ -71,6 +76,7 @@ public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $addres
7176
$quote->removeAddress($quote->getBillingAddress()->getId());
7277
$quote->setBillingAddress($address);
7378
try {
79+
$this->getShippingAddressAssignment()->setAddress($quote, $address, $useForShipping);
7480
$quote->setDataChanges(true);
7581
$this->quoteRepository->save($quote);
7682
} catch (\Exception $e) {
@@ -88,4 +94,17 @@ public function get($cartId)
8894
$cart = $this->quoteRepository->getActive($cartId);
8995
return $cart->getBillingAddress();
9096
}
97+
98+
/**
99+
* @return \Magento\Quote\Model\ShippingAddressAssignment
100+
* @deprecated
101+
*/
102+
private function getShippingAddressAssignment()
103+
{
104+
if (!$this->shippingAddressAssignment) {
105+
$this->shippingAddressAssignment = ObjectManager::getInstance()
106+
->get(\Magento\Quote\Model\ShippingAddressAssignment::class);
107+
}
108+
return $this->shippingAddressAssignment;
109+
}
91110
}

app/code/Magento/Quote/Model/GuestCart/GuestBillingAddressManagement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public function __construct(
4242
/**
4343
* {@inheritDoc}
4444
*/
45-
public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address)
45+
public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address, $useForShipping = false)
4646
{
4747
/** @var $quoteIdMask QuoteIdMask */
4848
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
49-
return $this->billingAddressManagement->assign($quoteIdMask->getQuoteId(), $address);
49+
return $this->billingAddressManagement->assign($quoteIdMask->getQuoteId(), $address, $useForShipping);
5050
}
5151

5252
/**

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@ class Grand extends \Magento\Quote\Model\Quote\Address\Total\AbstractTotal
1414
* @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment
1515
* @param \Magento\Quote\Model\Quote\Address\Total $total
1616
* @return $this
17+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
1718
*/
1819
public function collect(
1920
\Magento\Quote\Model\Quote $quote,
2021
\Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
2122
\Magento\Quote\Model\Quote\Address\Total $total
2223
) {
24+
$grandTotal = $total->getGrandTotal();
25+
$baseGrandTotal = $total->getBaseGrandTotal();
2326
$totals = array_sum($total->getAllTotalAmounts());
2427
$baseTotals = array_sum($total->getAllBaseTotalAmounts());
2528

26-
$total->setGrandTotal($totals);
27-
$total->setBaseGrandTotal($baseTotals);
29+
$total->setGrandTotal($grandTotal + $totals);
30+
$total->setBaseGrandTotal($baseGrandTotal + $baseTotals);
2831
return $this;
2932
}
3033

@@ -34,6 +37,7 @@ public function collect(
3437
* @param \Magento\Quote\Model\Quote $quote
3538
* @param \Magento\Quote\Model\Quote\Address\Total $total
3639
* @return $this
40+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3741
*/
3842
public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total)
3943
{

0 commit comments

Comments
 (0)