Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request #4863 from magento-epam/EPAM-PR-77
Browse files Browse the repository at this point in the history
- Increase test coverage for Promotion and Loyalty functional area
- fixed Fatal error is displayed during multishipping checkout when open Cart page in another window
- fixed  Admin user with permission for 1 store can manage product quantity
  • Loading branch information
irenelagno authored Oct 8, 2019
2 parents 586c9df + b7223a5 commit 61a5a30
Show file tree
Hide file tree
Showing 21 changed files with 504 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<createData entity="SimpleProduct2" stepKey="simpleProduct2"/>
</before>
<after>
<!-- Delete the bundled product we created in the test body -->
<actionGroup ref="deleteProductBySku" stepKey="deleteBundleProduct">
<argument name="sku" value="{{BundleProduct.sku}}"/>
</actionGroup>
<amOnPage url="{{AdminLogoutPage.url}}" stepKey="amOnLogoutPage"/>
<deleteData createDataKey="simpleProduct1" stepKey="deleteSimpleProduct1"/>
<deleteData createDataKey="simpleProduct2" stepKey="deleteSimpleProduct2"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminAssertDisabledQtyActionGroup">
<annotations>
<description>Goes to the 'Quantity' field and assert disabled attribute.</description>
</annotations>

<seeElement selector="{{AdminProductFormSection.productQuantity}}" stepKey="assertProductQty"/>
<assertElementContainsAttribute selector="{{AdminProductFormSection.productQuantity}}" attribute="disabled" expectedValue="true" stepKey="checkIfQtyIsDisabled" />
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

declare(strict_types=1);

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogInventory\Ui\DataProvider\Product\Form\Modifier;

use Magento\Catalog\Controller\Adminhtml\Product\Initialization\StockDataFilter;
Expand Down Expand Up @@ -238,7 +237,7 @@ private function prepareMeta()
$this->meta = $this->arrayManager->merge(
$fieldsetPath . '/children',
$this->meta,
['container_quantity_and_stock_status_qty' => $container]
['quantity_and_stock_status_qty' => $container]
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<element name="totalAmount" type="text" selector="//*[@id='cart-totals']//tr[@class='grand totals']//td//span[@class='price' and contains(text(), '{{amount}}')]" parameterized="true"/>
<element name="proceedToCheckout" type="button" selector=".action.primary.checkout span" timeout="30"/>
<element name="discountAmount" type="text" selector="td[data-th='Discount']"/>
<element name="shippingHeading" type="button" selector="#block-shipping-heading" timeout="60"/>
<element name="shippingHeading" type="button" selector="#block-shipping-heading" timeout="10"/>
<element name="postcode" type="input" selector="input[name='postcode']" timeout="10"/>
<element name="stateProvince" type="select" selector="select[name='region_id']" timeout="10"/>
<element name="stateProvinceInput" type="input" selector="input[name='region']"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier;

use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Catalog\Model\Locator\LocatorInterface;

/**
* Data provider for quantity in the Configurable products
Expand All @@ -16,21 +19,37 @@ class ConfigurableQty extends AbstractModifier
const CODE_QTY_CONTAINER = 'quantity_and_stock_status_qty';

/**
* {@inheritdoc}
* @var LocatorInterface
*/
private $locator;

/**
* ConfigurableQty constructor
*
* @param LocatorInterface $locator
*/
public function __construct(LocatorInterface $locator)
{
$this->locator = $locator;
}

/**
* @inheritdoc
*/
public function modifyData(array $data)
{
return $data;
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function modifyMeta(array $meta)
{
if ($groupCode = $this->getGroupCodeByField($meta, self::CODE_QTY_CONTAINER)) {
$parentChildren = &$meta[$groupCode]['children'];
if (!empty($parentChildren[self::CODE_QTY_CONTAINER])) {
$isConfigurable = $this->locator->getProduct()->getTypeId() === 'configurable';
if (!empty($parentChildren[self::CODE_QTY_CONTAINER]) && $isConfigurable) {
$parentChildren[self::CODE_QTY_CONTAINER] = array_replace_recursive(
$parentChildren[self::CODE_QTY_CONTAINER],
[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="StorefrontCheckoutCartGiftMessageSection">
<element name="giftItemMessage" type="textarea" selector="tbody.cart:nth-of-type({{blockNumber}}) #gift-message-whole-message" parameterized="true"/>
</section>
</sections>
41 changes: 31 additions & 10 deletions app/code/Magento/Multishipping/Block/Checkout/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Multishipping\Block\Checkout;

use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Quote\Model\Quote\Address;
use Magento\Store\Model\ScopeInterface;

/**
* Mustishipping checkout shipping
Expand Down Expand Up @@ -67,6 +70,8 @@ public function getCheckout()
}

/**
* Add page title and prepare layout
*
* @return $this
*/
protected function _prepareLayout()
Expand All @@ -78,6 +83,8 @@ protected function _prepareLayout()
}

/**
* Retrieves addresses
*
* @return Address[]
*/
public function getAddresses()
Expand All @@ -86,6 +93,8 @@ public function getAddresses()
}

/**
* Returns count of addresses
*
* @return mixed
*/
public function getAddressCount()
Expand All @@ -99,14 +108,16 @@ public function getAddressCount()
}

/**
* Retrieves the address items
*
* @param Address $address
* @return \Magento\Framework\DataObject[]
*/
public function getAddressItems($address)
{
$items = [];
foreach ($address->getAllItems() as $item) {
if ($item->getParentItemId()) {
if ($item->getParentItemId() || !$item->getQuoteItemId()) {
continue;
}
$item->setQuoteItem($this->getCheckout()->getQuote()->getItemById($item->getQuoteItemId()));
Expand All @@ -118,6 +129,8 @@ public function getAddressItems($address)
}

/**
* Retrieves the address shipping method
*
* @param Address $address
* @return mixed
*/
Expand All @@ -127,6 +140,8 @@ public function getAddressShippingMethod($address)
}

/**
* Retrieves address shipping rates
*
* @param Address $address
* @return mixed
*/
Expand All @@ -137,22 +152,20 @@ public function getShippingRates($address)
}

/**
* Retrieves the carrier name by the code
*
* @param string $carrierCode
* @return string
*/
public function getCarrierName($carrierCode)
{
if ($name = $this->_scopeConfig->getValue(
'carriers/' . $carrierCode . '/title',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)
) {
return $name;
}
return $carrierCode;
$name = $this->_scopeConfig->getValue('carriers/' . $carrierCode . '/title', ScopeInterface::SCOPE_STORE);
return $name ?: $carrierCode;
}

/**
* Retrieves the address edit url
*
* @param Address $address
* @return string
*/
Expand All @@ -162,6 +175,8 @@ public function getAddressEditUrl($address)
}

/**
* Retrieves the url for items edition
*
* @return string
*/
public function getItemsEditUrl()
Expand All @@ -170,6 +185,8 @@ public function getItemsEditUrl()
}

/**
* Retrieves the url for the post action
*
* @return string
*/
public function getPostActionUrl()
Expand All @@ -178,6 +195,8 @@ public function getPostActionUrl()
}

/**
* Retrieves the back url
*
* @return string
*/
public function getBackUrl()
Expand All @@ -186,6 +205,8 @@ public function getBackUrl()
}

/**
* Returns converted and formatted price
*
* @param Address $address
* @param float $price
* @param bool $flag
Expand All @@ -202,7 +223,7 @@ public function getShippingPrice($address, $price, $flag)
}

/**
* Retrieve text for items box
* Retrieves text for items box
*
* @param \Magento\Framework\DataObject $addressEntity
* @return string
Expand Down
65 changes: 43 additions & 22 deletions app/code/Magento/Multishipping/Model/Cart/Controller/CartPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,89 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Multishipping\Model\Cart\Controller;

use Magento\Checkout\Controller\Cart;
use Magento\Checkout\Model\Session;
use Magento\Customer\Api\AddressRepositoryInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Multishipping\Model\Checkout\Type\Multishipping\State;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Model\Quote;

/**
* Cleans shipping addresses and item assignments after MultiShipping flow
*/
class CartPlugin
{
/**
* @var \Magento\Quote\Api\CartRepositoryInterface
* @var CartRepositoryInterface
*/
private $cartRepository;

/**
* @var \Magento\Checkout\Model\Session
* @var Session
*/
private $checkoutSession;

/**
* @var \Magento\Customer\Api\AddressRepositoryInterface
* @var AddressRepositoryInterface
*/
private $addressRepository;

/**
* @param \Magento\Quote\Api\CartRepositoryInterface $cartRepository
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Customer\Api\AddressRepositoryInterface $addressRepository
* @param CartRepositoryInterface $cartRepository
* @param Session $checkoutSession
* @param AddressRepositoryInterface $addressRepository
*/
public function __construct(
\Magento\Quote\Api\CartRepositoryInterface $cartRepository,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository
CartRepositoryInterface $cartRepository,
Session $checkoutSession,
AddressRepositoryInterface $addressRepository
) {
$this->cartRepository = $cartRepository;
$this->checkoutSession = $checkoutSession;
$this->addressRepository = $addressRepository;
}

/**
* @param \Magento\Checkout\Controller\Cart $subject
* @param \Magento\Framework\App\RequestInterface $request
* Cleans shipping addresses and item assignments after MultiShipping flow
*
* @param Cart $subject
* @param RequestInterface $request
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @throws LocalizedException
*/
public function beforeDispatch(
\Magento\Checkout\Controller\Cart $subject,
\Magento\Framework\App\RequestInterface $request
) {
/** @var \Magento\Quote\Model\Quote $quote */
public function beforeDispatch(Cart $subject, RequestInterface $request)
{
/** @var Quote $quote */
$quote = $this->checkoutSession->getQuote();

// Clear shipping addresses and item assignments after MultiShipping flow
if ($quote->isMultipleShippingAddresses()) {
if ($quote->isMultipleShippingAddresses() && $this->isCheckoutComplete()) {
foreach ($quote->getAllShippingAddresses() as $address) {
$quote->removeAddress($address->getId());
}

$shippingAddress = $quote->getShippingAddress();
$defaultShipping = $quote->getCustomer()->getDefaultShipping();
if ($defaultShipping) {
$defaultCustomerAddress = $this->addressRepository->getById(
$defaultShipping
);
$defaultCustomerAddress = $this->addressRepository->getById($defaultShipping);
$shippingAddress->importCustomerAddressData($defaultCustomerAddress);
}
$this->cartRepository->save($quote);
}
}

/**
* Checks whether the checkout flow is complete
*
* @return bool
*/
private function isCheckoutComplete() : bool
{
return (bool) ($this->checkoutSession->getStepData(State::STEP_SHIPPING)['is_complete'] ?? true);
}
}
Loading

0 comments on commit 61a5a30

Please sign in to comment.