Skip to content

Commit

Permalink
Merge pull request #6171 from magento-tsg-csl3/2.4-develop-pr41
Browse files Browse the repository at this point in the history
[TSG-CSL3] For 2.4 (pr41)
  • Loading branch information
viktym authored Sep 29, 2020
2 parents 1064e35 + fd6c705 commit fbfac3e
Show file tree
Hide file tree
Showing 23 changed files with 726 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Catalog\Model\Product\Filter\DateTime;
use Magento\Framework\Locale\Resolver;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\Stdlib\DateTime\Intl\DateFormatterFactory;
use Magento\Framework\Stdlib\DateTime\Timezone;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -43,7 +44,7 @@ function () {
);
$timezone = $objectManager->getObject(
Timezone::class,
['localeResolver' => $localeResolver]
['localeResolver' => $localeResolver, 'dateFormatterFactory' => new DateFormatterFactory()]
);
$stdlibDateTimeFilter = $objectManager->getObject(
\Magento\Framework\Stdlib\DateTime\Filter\DateTime::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<actionGroup ref="AdminCatalogPriceRuleSaveAndApplyActionGroup" stepKey="saveAndApplyFirstPriceRule"/>
<!-- Perform reindex -->
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex">
<argument name="indices" value="catalogrule_rule"/>
<argument name="indices" value=""/>
</actionGroup>
</before>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="CheckoutDifferentDefaultCountryPerStoreTest">
<annotations>
<features value="One Page Checkout"/>
<stories value="Checkout via the Storefront"/>
<title value="Checkout different default country per store"/>
<description value="Checkout display default country per store view"/>
<severity value="MAJOR"/>
<testCaseId value="MC-37707"/>
<useCaseId value="MC-36884"/>
<group value="checkout"/>
</annotations>
<before>
<!-- Create simple product -->
<createData entity="SimpleProduct2" stepKey="createProduct"/>
<!-- Create store view -->
<actionGroup ref="AdminLoginActionGroup" stepKey="loginToAdminArea"/>
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createStoreView">
<argument name="customStore" value="customStore"/>
</actionGroup>
<!-- Set Germany as default country for created store view -->
<magentoCLI command="config:set --scope=stores --scope-code={{customStore.code}} general/country/default {{DE_Address_Berlin_Not_Default_Address.country_id}}" stepKey="changeDefaultCountry"/>
</before>
<after>
<!--Delete product and store view-->
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
<actionGroup ref="AdminDeleteStoreViewActionGroup" stepKey="deleteStoreView">
<argument name="customStore" value="customStore"/>
</actionGroup>
</after>
<!-- Open product and add product to cart-->
<actionGroup ref="OpenStoreFrontProductPageActionGroup" stepKey="openProductPage">
<argument name="productUrlKey" value="$$createProduct.custom_attributes[url_key]$$"/>
</actionGroup>
<actionGroup ref="StorefrontAddProductToCartActionGroup" stepKey="addProductToCart">
<argument name="product" value="$$createProduct$$"/>
<argument name="productCount" value="1"/>
</actionGroup>
<!-- Go to cart -->
<actionGroup ref="StorefrontOpenCartFromMinicartActionGroup" stepKey="openCart"/>
<!-- Switch store view -->
<actionGroup ref="StorefrontSwitchStoreViewActionGroup" stepKey="switchStoreViewActionGroup">
<argument name="storeView" value="customStore"/>
</actionGroup>
<!-- Go to checkout page -->
<actionGroup ref="OpenStoreFrontCheckoutShippingPageActionGroup" stepKey="openCheckoutShippingPage"/>
<!-- Grab country code from checkout page and assert value with default country for created store view -->
<grabValueFrom selector="{{CheckoutShippingSection.country}}" stepKey="grabCountry"/>
<assertEquals stepKey="assertCountryValue">
<actualResult type="const">$grabCountry</actualResult>
<expectedResult type="string">{{DE_Address_Berlin_Not_Default_Address.country_id}}</expectedResult>
</assertEquals>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ define(

if (!quote.isVirtual()) {
checkoutProvider.on('shippingAddress', function (shippingAddressData) {
checkoutData.setShippingAddressFromData(shippingAddressData);
//jscs:disable requireCamelCaseOrUpperCaseIdentifiers
if (quote.shippingAddress().countryId !== shippingAddressData.country_id ||
(shippingAddressData.postcode || shippingAddressData.region_id)
) {
checkoutData.setShippingAddressFromData(shippingAddressData);
}
//jscs:enable requireCamelCaseOrUpperCaseIdentifiers
});
} else {
checkoutProvider.on('shippingAddress', function (shippingAddressData) {
Expand Down
8 changes: 5 additions & 3 deletions app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Locale\Resolver;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\Stdlib\DateTime\Intl\DateFormatterFactory;
use Magento\Framework\Stdlib\DateTime\Timezone;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\View\Element\Html\Date;
Expand Down Expand Up @@ -50,7 +51,7 @@ class DobTest extends TestCase
const YEAR = '2014';

// Value of date('Y', strtotime(self::DATE))
const DATE_FORMAT = 'M/d/Y';
const DATE_FORMAT = 'M/d/y';

/** Constants used by Dob::setDateInput($code, $html) */
const DAY_HTML =
Expand Down Expand Up @@ -119,7 +120,7 @@ function () {
);
$timezone = $objectManager->getObject(
Timezone::class,
['localeResolver' => $localeResolver]
['localeResolver' => $localeResolver, 'dateFormatterFactory' => new DateFormatterFactory()]
);

$this->_locale = Resolver::DEFAULT_LOCALE;
Expand Down Expand Up @@ -357,7 +358,8 @@ public function getDateFormatDataProvider(): array
preg_replace(
'/[^MmDdYy\/\.\-]/',
'',
(new \IntlDateFormatter('ar_SA', \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE))
(new DateFormatterFactory())
->create('ar_SA', \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE)
->getPattern()
)
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\GroupedProduct\Model\Inventory;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\GroupedProduct\Model\Product\Type\Grouped;
use Magento\Catalog\Api\Data\ProductInterface as Product;
use Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory;
use Magento\CatalogInventory\Api\StockItemRepositoryInterface;
use Magento\CatalogInventory\Api\StockConfigurationInterface;
use Magento\CatalogInventory\Observer\ParentItemProcessorInterface;
use Magento\CatalogInventory\Api\Data\StockItemInterface;
use Magento\GroupedProduct\Model\ResourceModel\Product\Link;
use Magento\Framework\App\ResourceConnection;

/**
* Process parent stock item for grouped product
*/
class ParentItemProcessor implements ParentItemProcessorInterface
{
/**
* @var Grouped
*/
private $groupedType;

/**
* @var StockItemRepositoryInterface
*/
private $stockItemRepository;

/**
* @var StockConfigurationInterface
*/
private $stockConfiguration;

/**
* @var StockItemCriteriaInterfaceFactory
*/
private $criteriaInterfaceFactory;

/**
* Product metadata pool
*
* @var MetadataPool
*/
private $metadataPool;

/**
* @var ResourceConnection
*/
private $resource;

/**
* @param Grouped $groupedType
* @param StockItemCriteriaInterfaceFactory $criteriaInterfaceFactory
* @param StockItemRepositoryInterface $stockItemRepository
* @param StockConfigurationInterface $stockConfiguration
* @param ResourceConnection $resource
* @param MetadataPool $metadataPool
*/
public function __construct(
Grouped $groupedType,
StockItemCriteriaInterfaceFactory $criteriaInterfaceFactory,
StockItemRepositoryInterface $stockItemRepository,
StockConfigurationInterface $stockConfiguration,
ResourceConnection $resource,
MetadataPool $metadataPool
) {
$this->groupedType = $groupedType;
$this->criteriaInterfaceFactory = $criteriaInterfaceFactory;
$this->stockConfiguration = $stockConfiguration;
$this->stockItemRepository = $stockItemRepository;
$this->resource = $resource;
$this->metadataPool = $metadataPool;
}

/**
* Process parent products
*
* @param Product $product
* @return void
*/
public function process(Product $product)
{
$parentIds = $this->getParentEntityIdsByChild($product->getId());
foreach ($parentIds as $productId) {
$this->processStockForParent((int)$productId);
}
}

/**
* Change stock item for parent product depending on children stock items
*
* @param int $productId
* @return void
*/
private function processStockForParent(int $productId)
{
$criteria = $this->criteriaInterfaceFactory->create();
$criteria->setScopeFilter($this->stockConfiguration->getDefaultScopeId());
$criteria->setProductsFilter($productId);
$stockItemCollection = $this->stockItemRepository->getList($criteria);
$allItems = $stockItemCollection->getItems();
if (empty($allItems)) {
return;
}
$parentStockItem = array_shift($allItems);
$groupedChildrenIds = $this->groupedType->getChildrenIds($productId);
$criteria->setProductsFilter($groupedChildrenIds);
$stockItemCollection = $this->stockItemRepository->getList($criteria);
$allItems = $stockItemCollection->getItems();

$groupedChildrenIsInStock = false;

foreach ($allItems as $childItem) {
if ($childItem->getIsInStock() === true) {
$groupedChildrenIsInStock = true;
break;
}
}

if ($this->isNeedToUpdateParent($parentStockItem, $groupedChildrenIsInStock)) {
$parentStockItem->setIsInStock($groupedChildrenIsInStock);
$parentStockItem->setStockStatusChangedAuto(1);
$this->stockItemRepository->save($parentStockItem);
}
}

/**
* Check is parent item should be updated
*
* @param StockItemInterface $parentStockItem
* @param bool $childrenIsInStock
* @return bool
*/
private function isNeedToUpdateParent(StockItemInterface $parentStockItem, bool $childrenIsInStock): bool
{
return $parentStockItem->getIsInStock() !== $childrenIsInStock &&
($childrenIsInStock === false || $parentStockItem->getStockStatusChangedAuto());
}

/**
* Retrieve parent ids array by child id
*
* @param int $childId
* @return string[]
*/
private function getParentEntityIdsByChild($childId)
{
$select = $this->resource->getConnection()
->select()
->from(['l' => $this->resource->getTableName('catalog_product_link')], [])
->join(
['e' => $this->resource->getTableName('catalog_product_entity')],
'e.' .
$this->metadataPool->getMetadata(ProductInterface::class)->getLinkField() . ' = l.product_id',
['e.entity_id']
)
->where('l.linked_product_id = ?', $childId)
->where(
'link_type_id = ?',
Link::LINK_TYPE_GROUPED
);

return $this->resource->getConnection()->fetchCol($select);
}
}
7 changes: 7 additions & 0 deletions app/code/Magento/GroupedProduct/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,11 @@
</argument>
</arguments>
</type>
<type name="Magento\CatalogInventory\Observer\SaveInventoryDataObserver">
<arguments>
<argument name="parentItemProcessorPool" xsi:type="array">
<item name="grouped" xsi:type="object"> Magento\GroupedProduct\Model\Inventory\ParentItemProcessor</item>
</argument>
</arguments>
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ protected function _prepareForm()
'title' => __('Select File to Import'),
'required' => true,
'class' => 'input-file',
'onchange' => 'varienImport.refreshLoadedFileLastModified(this);',
'note' => __(
'File must be saved in UTF-8 encoding for proper import'
),
Expand Down Expand Up @@ -282,7 +283,7 @@ protected function getDownloadSampleFileHtml()
private function getImportBehaviorTooltip()
{
$html = '<div class="admin__field-tooltip tooltip">
<a class="admin__field-tooltip-action action-help" target="_blank" title="What is this?"
<a class="admin__field-tooltip-action action-help" target="_blank" title="What is this?"
href="https://docs.magento.com/m2/ce/user_guide/system/data-import.html"><span>'
. __('What is this?')
. '</span></a></div>';
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/ImportExport/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,4 @@ Summary,Summary
"File %1 deleted","File %1 deleted"
"Please provide valid export file name","Please provide valid export file name"
"%1 is not a valid file","%1 is not a valid file"
"Content of uploaded file was changed, please re-upload the file","Content of uploaded file was changed, please re-upload the file"
Loading

0 comments on commit fbfac3e

Please sign in to comment.