Skip to content

Commit

Permalink
Merge branch '2.4-develop' into ref-AdminDashboardWithChartsTest
Browse files Browse the repository at this point in the history
  • Loading branch information
engcom-Hotel authored Jan 22, 2021
2 parents b5ec75c + 30301a5 commit 4b67412
Show file tree
Hide file tree
Showing 72 changed files with 2,751 additions and 292 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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="AwsS3AdminImportSimpleAndConfigurableProductsWithAssignedImagesTest" extends="AdminImportSimpleAndConfigurableProductsWithAssignedImagesTest">
<annotations>
<features value="AwsS3"/>
<stories value="Import Products"/>
<title value="S3 - Import Configurable Product With Simple Child Products With Images"/>
<description value="Imports a .csv file containing a configurable product with 3 child simple products that
have images. Verifies that products are imported successfully and that the images are attached to the
products as expected."/>
<severity value="MAJOR"/>
<group value="importExport"/>
<group value="remote_storage_aws_s3"/>
<skip>
<issueId value="MC-39280"/>
</skip>
</annotations>

<before>
<!-- Enable AWS S3 Remote Storage -->
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.enable_options}}" stepKey="enableRemoteStorage"/>
</before>

<after>
<!-- Disable AWS S3 Remote Storage -->
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.disable_options}}" stepKey="disableRemoteStorage"/>
</after>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,12 @@ public function addWebsiteFilter($websites = null)
}

$this->_productLimitationFilters['website_ids'] = $websites;
$this->_applyProductLimitations();

if ($this->getStoreId() == Store::DEFAULT_STORE_ID) {
$this->_productLimitationJoinWebsite();
} else {
$this->_applyProductLimitations();
}

return $this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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="StorefrontNavigateToCategoryUrlActionGroup">
<annotations>
<description>Goes to the Storefront Category page for the provided Category URL.</description>
</annotations>
<arguments>
<argument name="categoryUrl" type="string"/>
</arguments>
<amOnPage url="{{StorefrontCategoryPage.url(categoryUrl)}}" stepKey="goToStorefrontCategoryPage"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
</arguments>

<selectOption selector="{{StorefrontProductInfoMainSection.productOptionSelect(attributeLabel)}}" userInput="{{optionLabel}}" stepKey="fillDropDownAttributeOption"/>
<waitForPageLoad stepKey="waitForPageLoad"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<element name="imageFileUpload" type="input" selector="#fileupload"/>
<element name="imageUploadButton" type="button" selector="div.image div.fileinput-button"/>
<element name="imageFile" type="text" selector="//*[@id='media_gallery_content']//img[contains(@src, '{{url}}')]" parameterized="true"/>
<element name="imageElement" type="text" selector="#media_gallery_content img"/>
<element name="removeImageButton" type="button" selector=".action-remove"/>
<element name="removeImageButtonForExactImage" type="button" selector="[id='media_gallery_content'] img[src*='{{imageName}}'] + div[class='actions'] button[class='action-remove']" parameterized="true"/>
<element name="modalOkBtn" type="button" selector="button.action-primary.action-accept"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\Validator\UniversalFactory;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -93,6 +94,11 @@ class CollectionTest extends TestCase
*/
private $storeManager;

/**
* @var ProductLimitation|MockObject
*/
private $productLimitationMock;

/**
* @var EntityFactory|MockObject
*/
Expand Down Expand Up @@ -192,7 +198,7 @@ protected function setUp(): void
$this->entityMock->expects($this->any())->method('getTable')->willReturnArgument(0);
$this->connectionMock->expects($this->atLeastOnce())->method('select')->willReturn($this->selectMock);

$productLimitationMock = $this->createMock(
$this->productLimitationMock = $this->createMock(
ProductLimitation::class
);
$productLimitationFactoryMock = $this->getMockBuilder(
Expand All @@ -201,7 +207,7 @@ protected function setUp(): void
->setMethods(['create'])->getMock();

$productLimitationFactoryMock->method('create')
->willReturn($productLimitationMock);
->willReturn($this->productLimitationMock);
$this->collection = $this->objectManager->getObject(
Collection::class,
[
Expand Down Expand Up @@ -432,4 +438,44 @@ public function testGetNewEmptyItem()
$secondItem = $this->collection->getNewEmptyItem();
$this->assertEquals($firstItem, $secondItem);
}

/**
* Test to add website filter in admin area
*/
public function testAddWebsiteFilterOnAdminStore(): void
{
$websiteIds = [2];
$websiteTable = 'catalog_product_website';
$joinCondition = 'join condition';
$this->productLimitationMock->expects($this->atLeastOnce())
->method('offsetSet')
->with('website_ids', $websiteIds);
$this->productLimitationMock->method('offsetExists')
->with('website_ids')
->willReturn(true);
$this->productLimitationMock->method('offsetGet')
->with('website_ids')
->willReturn($websiteIds);
$this->connectionMock->expects($this->once())
->method('quoteInto')
->with('product_website.website_id IN(?)', $websiteIds, 'int')
->willReturn($joinCondition);
$this->selectMock->method('getPart')->with(Select::FROM)->willReturn([]);
/** @var AbstractEntity|MockObject $eavEntity */
$eavEntity = $this->createMock(AbstractEntity::class);
$eavEntity->method('getTable')
->with('catalog_product_website')
->willReturn($websiteTable);
$this->selectMock->expects($this->once())
->method('join')
->with(
['product_website' => $websiteTable],
'product_website.product_id = e.entity_id AND ' . $joinCondition,
[]
);

$this->collection->setEntity($eavEntity);
$this->collection->setStoreId(Store::DEFAULT_STORE_ID);
$this->collection->addWebsiteFilter($websiteIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private function fetch() : array
$this->searchCriteriaBuilder->create(),
$this->attributeCodes,
false,
true
false
);

/** @var \Magento\Catalog\Model\Product $product */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function getList(

$this->collectionPreProcessor->process($collection, $searchCriteria, $attributes, $context);

if (!$isChildSearch) {
if ($isChildSearch) {
$visibilityIds = $isSearch
? $this->visibility->getVisibleInSearchIds()
: $this->visibility->getVisibleInCatalogIds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private function deleteProductsLinks(
if (!empty($linksToDelete) && Import::BEHAVIOR_APPEND === $importEntity->getBehavior()) {
foreach ($linksToDelete as $linkTypeId => $productIds) {
if (!empty($productIds)) {
$whereLinkId = $importEntity->getConnection()->quoteInto('link_type_id', $linkTypeId);
$whereLinkId = $importEntity->getConnection()->quoteInto('link_type_id = ?', $linkTypeId);
$whereProductId = $importEntity->getConnection()->quoteInto(
'product_id IN (?)',
array_unique($productIds)
Expand Down
51 changes: 40 additions & 11 deletions app/code/Magento/CatalogRule/Model/Indexer/ReindexRuleProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

namespace Magento\CatalogRule\Model\Indexer;

use Magento\CatalogRule\Model\Indexer\IndexerTableSwapperInterface as TableSwapper;
use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
use Magento\CatalogRule\Model\Indexer\IndexerTableSwapperInterface as TableSwapper;
use Magento\CatalogRule\Model\Rule;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
Expand All @@ -18,6 +18,8 @@
*/
class ReindexRuleProduct
{
private const ADMIN_WEBSITE_ID = 0;

/**
* @var ResourceConnection
*/
Expand All @@ -38,22 +40,30 @@ class ReindexRuleProduct
*/
private $localeDate;

/**
* @var bool
*/
private $useWebsiteTimezone;

/**
* @param ResourceConnection $resource
* @param ActiveTableSwitcher $activeTableSwitcher
* @param TableSwapper $tableSwapper
* @param TimezoneInterface $localeDate
* @param bool $useWebsiteTimezone
*/
public function __construct(
ResourceConnection $resource,
ActiveTableSwitcher $activeTableSwitcher,
TableSwapper $tableSwapper,
TimezoneInterface $localeDate
TimezoneInterface $localeDate,
bool $useWebsiteTimezone = true
) {
$this->resource = $resource;
$this->activeTableSwitcher = $activeTableSwitcher;
$this->tableSwapper = $tableSwapper;
$this->localeDate = $localeDate;
$this->useWebsiteTimezone = $useWebsiteTimezone;
}

/**
Expand Down Expand Up @@ -95,18 +105,18 @@ public function execute(Rule $rule, $batchCount, $useAdditionalTable = false)
$actionOperator = $rule->getSimpleAction();
$actionAmount = $rule->getDiscountAmount();
$actionStop = $rule->getStopRulesProcessing();
$fromTimeInAdminTz = $this->parseDateByWebsiteTz((string)$rule->getFromDate(), self::ADMIN_WEBSITE_ID);
$toTimeInAdminTz = $this->parseDateByWebsiteTz((string)$rule->getToDate(), self::ADMIN_WEBSITE_ID);

$rows = [];
foreach ($websiteIds as $websiteId) {
$scopeTz = new \DateTimeZone(
$this->localeDate->getConfigTimezone(ScopeInterface::SCOPE_WEBSITE, $websiteId)
);
$fromTime = $rule->getFromDate()
? (new \DateTime($rule->getFromDate(), $scopeTz))->getTimestamp()
: 0;
$toTime = $rule->getToDate()
? (new \DateTime($rule->getToDate(), $scopeTz))->getTimestamp() + IndexBuilder::SECONDS_IN_DAY - 1
: 0;
$fromTime = $this->useWebsiteTimezone
? $this->parseDateByWebsiteTz((string)$rule->getFromDate(), (int)$websiteId)
: $fromTimeInAdminTz;
$toTime = $this->useWebsiteTimezone
? $this->parseDateByWebsiteTz((string)$rule->getToDate(), (int)$websiteId)
+ ($rule->getToDate() ? IndexBuilder::SECONDS_IN_DAY - 1 : 0)
: $toTimeInAdminTz;

foreach ($productIds as $productId => $validationByWebsite) {
if (empty($validationByWebsite[$websiteId])) {
Expand Down Expand Up @@ -140,4 +150,23 @@ public function execute(Rule $rule, $batchCount, $useAdditionalTable = false)

return true;
}

/**
* Parse date value by the timezone of the website
*
* @param string $date
* @param int $websiteId
* @return int
*/
private function parseDateByWebsiteTz(string $date, int $websiteId): int
{
if (empty($date)) {
return 0;
}

$websiteTz = $this->localeDate->getConfigTimezone(ScopeInterface::SCOPE_WEBSITE, $websiteId);
$dateTime = new \DateTime($date, new \DateTimeZone($websiteTz));

return $dateTime->getTimestamp();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magento\CatalogRule\Model\Indexer;

use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;

/**
Expand Down Expand Up @@ -39,25 +40,33 @@ class ReindexRuleProductPrice
*/
private $pricesPersistor;

/**
* @var bool
*/
private $useWebsiteTimezone;

/**
* @param StoreManagerInterface $storeManager
* @param RuleProductsSelectBuilder $ruleProductsSelectBuilder
* @param ProductPriceCalculator $productPriceCalculator
* @param TimezoneInterface $localeDate
* @param RuleProductPricesPersistor $pricesPersistor
* @param bool $useWebsiteTimezone
*/
public function __construct(
StoreManagerInterface $storeManager,
RuleProductsSelectBuilder $ruleProductsSelectBuilder,
ProductPriceCalculator $productPriceCalculator,
TimezoneInterface $localeDate,
RuleProductPricesPersistor $pricesPersistor
RuleProductPricesPersistor $pricesPersistor,
bool $useWebsiteTimezone = true
) {
$this->storeManager = $storeManager;
$this->ruleProductsSelectBuilder = $ruleProductsSelectBuilder;
$this->productPriceCalculator = $productPriceCalculator;
$this->localeDate = $localeDate;
$this->pricesPersistor = $pricesPersistor;
$this->useWebsiteTimezone = $useWebsiteTimezone;
}

/**
Expand All @@ -82,11 +91,9 @@ public function execute(int $batchCount, ?int $productId = null, bool $useAdditi
$prevKey = null;

$storeGroup = $this->storeManager->getGroup($website->getDefaultGroupId());
$currentDate = $this->localeDate->scopeDate($storeGroup->getDefaultStoreId(), null, true);
$previousDate = (clone $currentDate)->modify('-1 day');
$previousDate->setTime(23, 59, 59);
$nextDate = (clone $currentDate)->modify('+1 day');
$nextDate->setTime(0, 0, 0);
$dateInterval = $this->useWebsiteTimezone
? $this->getDateInterval((int)$storeGroup->getDefaultStoreId())
: $this->getDateInterval(Store::DEFAULT_STORE_ID);

while ($ruleData = $productsStmt->fetch()) {
$ruleProductId = $ruleData['product_id'];
Expand All @@ -107,7 +114,7 @@ public function execute(int $batchCount, ?int $productId = null, bool $useAdditi
/**
* Build prices for each day
*/
foreach ([$previousDate, $currentDate, $nextDate] as $date) {
foreach ($dateInterval as $date) {
$time = $date->getTimestamp();
if (($ruleData['from_time'] == 0 ||
$time >= $ruleData['from_time']) && ($ruleData['to_time'] == 0 ||
Expand Down Expand Up @@ -157,4 +164,21 @@ public function execute(int $batchCount, ?int $productId = null, bool $useAdditi

return true;
}

/**
* Retrieve date sequence in store time zone
*
* @param int $storeId
* @return \DateTime[]
*/
private function getDateInterval(int $storeId): array
{
$currentDate = $this->localeDate->scopeDate($storeId, null, true);
$previousDate = (clone $currentDate)->modify('-1 day');
$previousDate->setTime(23, 59, 59);
$nextDate = (clone $currentDate)->modify('+1 day');
$nextDate->setTime(0, 0, 0);

return [$previousDate, $currentDate, $nextDate];
}
}
Loading

0 comments on commit 4b67412

Please sign in to comment.