Skip to content

Commit

Permalink
Merge pull request #435 from magento-folks/bugfix
Browse files Browse the repository at this point in the history
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
  • Loading branch information
VladimirZaets authored Sep 27, 2016
2 parents 14028aa + c5c94de commit 8007ad1
Show file tree
Hide file tree
Showing 18 changed files with 343 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ public function save(\Magento\Catalog\Api\Data\ProductAttributeInterface $attrib
$attribute->setFrontendInput($existingModel->getFrontendInput());

if (is_array($attribute->getFrontendLabels())) {
$frontendLabel[0] = $existingModel->getDefaultFrontendLabel();
$defaultFrontendLabel = $attribute->getDefaultFrontendLabel();
$frontendLabel[0] = !empty($defaultFrontendLabel)
? $defaultFrontendLabel
: $existingModel->getDefaultFrontendLabel();
foreach ($attribute->getFrontendLabels() as $item) {
$frontendLabel[$item->getStoreId()] = $item->getLabel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Catalog\Model\Product\Attribute\Repository;
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Eav\Api\Data\AttributeFrontendLabelInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand Down Expand Up @@ -288,4 +289,42 @@ public function testSaveDoesNotSaveAttributeOptionsIfOptionsAreAbsentInPayload()

$this->model->save($attributeMock);
}

public function testSaveSavesDefaultFrontendLabelIfItIsPresentInPayload()
{
$labelMock = $this->getMock(AttributeFrontendLabelInterface::class);
$labelMock->expects($this->any())->method('getStoreId')->willReturn(1);
$labelMock->expects($this->any())->method('getLabel')->willReturn('Store Scope Label');

$attributeId = 1;
$attributeCode = 'existing_attribute_code';
$attributeMock = $this->getMock(Attribute::class, [], [], '', false);
$attributeMock->expects($this->any())->method('getAttributeCode')->willReturn($attributeCode);
$attributeMock->expects($this->any())->method('getAttributeId')->willReturn($attributeId);
$attributeMock->expects($this->any())->method('getDefaultFrontendLabel')->willReturn('Default Label');
$attributeMock->expects($this->any())->method('getFrontendLabels')->willReturn([$labelMock]);
$attributeMock->expects($this->any())->method('getOptions')->willReturn([]);


$existingModelMock = $this->getMock(Attribute::class, [], [], '', false);
$existingModelMock->expects($this->any())->method('getAttributeId')->willReturn($attributeId);
$existingModelMock->expects($this->any())->method('getAttributeCode')->willReturn($attributeCode);

$this->eavAttributeRepositoryMock->expects($this->any())
->method('get')
->with(ProductAttributeInterface::ENTITY_TYPE_CODE, $attributeCode)
->willReturn($existingModelMock);

$attributeMock->expects($this->once())
->method('setDefaultFrontendLabel')
->with(
[
0 => 'Default Label',
1 => 'Store Scope Label'
]
);
$this->attributeResourceMock->expects($this->once())->method('save')->with($attributeMock);

$this->model->save($attributeMock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ define([], function () {

return {
email: addressData.email,
countryId: (addressData.country_id) ? addressData.country_id : window.checkoutConfig.defaultCountryId,
countryId: addressData['country_id'] || addressData.countryId || window.checkoutConfig.defaultCountryId,
regionId: regionId,
regionCode: (addressData.region) ? addressData.region.region_code : null,
region: (addressData.region) ? addressData.region.region : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ define(
'../action/select-shipping-address',
'./postcode-validator',
'mage/translate',
'uiRegistry'
'uiRegistry',
'Magento_Checkout/js/model/quote'
],
function (
$,
Expand All @@ -22,7 +23,8 @@ define(
selectShippingAddress,
postcodeValidator,
$t,
uiRegistry
uiRegistry,
quote
) {
'use strict';

Expand All @@ -41,7 +43,7 @@ define(
* @param {Object} validator
*/
registerValidator: function (carrier, validator) {
if (checkoutConfig.activeCarriers.indexOf(carrier) != -1) {
if (checkoutConfig.activeCarriers.indexOf(carrier) !== -1) {
validators.push(validator);
}
},
Expand Down Expand Up @@ -174,6 +176,7 @@ define(
address;

if (this.validateAddressData(addressFlat)) {
addressFlat = $.extend(true, {}, quote.shippingAddress(), addressFlat);
address = addressConverter.formAddressDataToQuoteAddress(addressFlat);
selectShippingAddress(address);
}
Expand Down
10 changes: 9 additions & 1 deletion app/code/Magento/Newsletter/Model/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,17 @@ protected function _updateCustomerSubscription($customerId, $subscribe)

$sendInformationEmail = false;
$status = self::STATUS_SUBSCRIBED;
$isConfirmNeed = $this->_scopeConfig->getValue(
self::XML_PATH_CONFIRMATION_FLAG,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
) == 1 ? true : false;
if ($subscribe) {
if (AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED
== $this->customerAccountManagement->getConfirmationStatus($customerId)
) {
$status = self::STATUS_UNCONFIRMED;
} else if ($isConfirmNeed) {
$status = self::STATUS_NOT_ACTIVE;
}
} else {
$status = self::STATUS_UNSUBSCRIBED;
Expand Down Expand Up @@ -581,7 +587,9 @@ protected function _updateCustomerSubscription($customerId, $subscribe)
$sendSubscription = $sendInformationEmail;
if ($sendSubscription === null xor $sendSubscription) {
try {
if ($this->isStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) {
if ($isConfirmNeed) {
$this->sendConfirmationRequestEmail();
} else if ($this->isStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) {
$this->sendUnsubscriptionEmail();
} elseif ($this->isStatusChanged() && $status == self::STATUS_SUBSCRIBED) {
$this->sendConfirmationSuccessEmail();
Expand Down
31 changes: 31 additions & 0 deletions app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,37 @@ public function testSubscribeCustomerById()
$this->subscriber->subscribeCustomerById($customerId);
}

public function testSubscribeCustomerById1()
{
$customerId = 1;
$customerDataMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
->getMock();
$this->customerRepository->expects($this->atLeastOnce())
->method('getById')
->with($customerId)->willReturn($customerDataMock);
$this->resource->expects($this->atLeastOnce())
->method('loadByCustomerData')
->with($customerDataMock)
->willReturn(
[
'subscriber_id' => 1,
'subscriber_status' => 3
]
);
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
$customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
$customerDataMock->expects($this->once())->method('getEmail')->willReturn('email');
$this->sendEmailCheck();
$this->customerAccountManagement->expects($this->once())
->method('getConfirmationStatus')
->willReturn(\Magento\Customer\Api\AccountManagementInterface::ACCOUNT_CONFIRMATION_NOT_REQUIRED);
$this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true);

$this->subscriber->subscribeCustomerById($customerId);
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus());
}

public function testUnsubscribe()
{
$this->resource->expects($this->once())->method('save')->willReturnSelf();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ interface GuestBillingAddressManagementInterface
*
* @param string $cartId The cart ID.
* @param \Magento\Quote\Api\Data\AddressInterface $address Billing address data.
* @param bool $useForShipping
* @return int Address ID.
* @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist.
* @throws \Magento\Framework\Exception\InputException The specified cart ID or address data is not valid.
*/
public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address);
public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address, $useForShipping = false);

/**
* Return the billing address for a specified quote.
Expand Down
19 changes: 19 additions & 0 deletions app/code/Magento/Quote/Model/BillingAddressManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class BillingAddressManagement implements BillingAddressManagementInterface
*/
protected $addressRepository;

/**
* @var \Magento\Quote\Model\ShippingAddressAssignment
*/
private $shippingAddressAssignment;

/**
* Constructs a quote billing address service object.
*
Expand Down Expand Up @@ -71,6 +76,7 @@ public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $addres
$quote->removeAddress($quote->getBillingAddress()->getId());
$quote->setBillingAddress($address);
try {
$this->getShippingAddressAssignment()->setAddress($quote, $address, $useForShipping);
$quote->setDataChanges(true);
$this->quoteRepository->save($quote);
} catch (\Exception $e) {
Expand All @@ -88,4 +94,17 @@ public function get($cartId)
$cart = $this->quoteRepository->getActive($cartId);
return $cart->getBillingAddress();
}

/**
* @return \Magento\Quote\Model\ShippingAddressAssignment
* @deprecated
*/
private function getShippingAddressAssignment()
{
if (!$this->shippingAddressAssignment) {
$this->shippingAddressAssignment = ObjectManager::getInstance()
->get(\Magento\Quote\Model\ShippingAddressAssignment::class);
}
return $this->shippingAddressAssignment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public function __construct(
/**
* {@inheritDoc}
*/
public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address)
public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address, $useForShipping = false)
{
/** @var $quoteIdMask QuoteIdMask */
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
return $this->billingAddressManagement->assign($quoteIdMask->getQuoteId(), $address);
return $this->billingAddressManagement->assign($quoteIdMask->getQuoteId(), $address, $useForShipping);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions app/code/Magento/Quote/Model/Quote/Address/Total/Grand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ class Grand extends \Magento\Quote\Model\Quote\Address\Total\AbstractTotal
* @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment
* @param \Magento\Quote\Model\Quote\Address\Total $total
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function collect(
\Magento\Quote\Model\Quote $quote,
\Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
\Magento\Quote\Model\Quote\Address\Total $total
) {
$grandTotal = $total->getGrandTotal();
$baseGrandTotal = $total->getBaseGrandTotal();
$totals = array_sum($total->getAllTotalAmounts());
$baseTotals = array_sum($total->getAllBaseTotalAmounts());

$total->setGrandTotal($totals);
$total->setBaseGrandTotal($baseTotals);
$total->setGrandTotal($grandTotal + $totals);
$total->setBaseGrandTotal($baseGrandTotal + $baseTotals);
return $this;
}

Expand All @@ -34,6 +37,7 @@ public function collect(
* @param \Magento\Quote\Model\Quote $quote
* @param \Magento\Quote\Model\Quote\Address\Total $total
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total)
{
Expand Down
63 changes: 63 additions & 0 deletions app/code/Magento/Quote/Model/ShippingAddressAssignment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Quote\Model;

class ShippingAddressAssignment
{
/**
* @var \Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor
*/
private $shippingAssignmentProcessor;

/**
* @var \Magento\Quote\Api\Data\CartExtensionFactory
*/
private $cartExtensionFactory;

/**
* ShippingAddressAssignment constructor.
* @param \Magento\Quote\Api\Data\CartExtensionFactory $cartExtensionFactory
* @param Quote\ShippingAssignment\ShippingAssignmentProcessor $shippingAssignmentProcessor
*/
public function __construct(
\Magento\Quote\Api\Data\CartExtensionFactory $cartExtensionFactory,
\Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor $shippingAssignmentProcessor
) {
$this->shippingAssignmentProcessor = $shippingAssignmentProcessor;
$this->cartExtensionFactory = $cartExtensionFactory;
}

/**
* @param \Magento\Quote\Api\Data\CartInterface $quote
* @param \Magento\Quote\Api\Data\AddressInterface $address
* @param bool $useForShipping
* @return void
*/
public function setAddress(
\Magento\Quote\Api\Data\CartInterface $quote,
\Magento\Quote\Api\Data\AddressInterface $address,
$useForShipping = false
) {
if ($useForShipping) {
$quote->removeAddress($quote->getShippingAddress()->getId());
$address->setSameAsBilling(1);
$address->setCollectShippingRates(true);
} else {
$address = $quote->getShippingAddress()->setSameAsBilling(0);
}

$quote->setShippingAddress($address);
$cartExtension = $quote->getExtensionAttributes();
if ($cartExtension === null) {
$cartExtension = $this->cartExtensionFactory->create();
}
/** @var \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment */
$shippingAssignment = $this->shippingAssignmentProcessor->create($quote);
$cartExtension->setShippingAssignments([$shippingAssignment]);
$quote->setExtensionAttributes($cartExtension);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,24 @@ public function testCollect()

$totalMock = $this->getMock(
\Magento\Quote\Model\Quote\Address\Total::class,
['getAllTotalAmounts', 'getAllBaseTotalAmounts', 'setGrandTotal', 'setBaseGrandTotal'],
[
'getAllTotalAmounts',
'getAllBaseTotalAmounts',
'setGrandTotal',
'setBaseGrandTotal',
'getGrandTotal',
'getBaseGrandTotal'
],
[],
'',
false
);
$totalMock->expects($this->once())->method('getGrandTotal')->willReturn(2);
$totalMock->expects($this->once())->method('getBaseGrandTotal')->willReturn(2);
$totalMock->expects($this->once())->method('getAllTotalAmounts')->willReturn($totals);
$totalMock->expects($this->once())->method('getAllBaseTotalAmounts')->willReturn($totalsBase);
$totalMock->expects($this->once())->method('setGrandTotal')->with($grandTotal);
$totalMock->expects($this->once())->method('setBaseGrandTotal')->with($grandTotalBase);
$totalMock->expects($this->once())->method('setGrandTotal')->with($grandTotal + 2);
$totalMock->expects($this->once())->method('setBaseGrandTotal')->with($grandTotalBase + 2);

$this->model->collect(
$this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false),
Expand Down
Loading

0 comments on commit 8007ad1

Please sign in to comment.