Skip to content

Commit

Permalink
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop
Browse files Browse the repository at this point in the history
Accepted Community Pull Requests:
 - #31776: Removed CliIndexerReindexActionGroup action group usage for Customer module (by @sergiy-v)
 - #31788: Removed CliIndexerReindexActionGroup action group usage for Sales module (by @sergiy-v)
 - #31507: [MFTF] Refactoring AdminMassOrdersCancelProcessingAndClosedTest (by @AnnaAPak)
 - #30883: Remove recursion in location of static files. (by @edspc)
 - #31636: Moving array access for CAPTCHA _.isEmpty check (by @MellenIO)
 - #31604: [MFTF] Adding AdminClickCreateNewStatusButtonOnOrderStatusPageActionGroup (by @AnnaAPak)
 - #31485: Fix delete special prices only for specified store (by @engcom-Charlie)
 - #31512: [MFTF] Refactoring AdminMassOrdersUpdateCancelPendingOrderTest (by @AnnaAPak)
 - #31502: [MFTF] Refactoring AdminPanelIsFrozenIfStorefrontIsOpenedViaCustomerViewTest (by @AnnaAPak)
 - #31510: [MFTF] Refactoring AdminMassOrdersHoldOnCompleteTest (by @AnnaAPak)
 - #31454: [MFTF] Adding AdminFillTaxIdentifierFilterOnTaxRateGridActionGroup (by @AnnaAPak)
 - #31488: [MFTF] Refactoring AdminValidateShippingTrackingNumberTest (by @AnnaAPak)
 - #30943: FIX Perfomance Issue for Backend EDIT of CMS #30936 (by @larsroettig)
 - #31299: fix reference layout cms_noroute_index core (by @PierW)
 - #30871: Update sortOrder load for async css plugin (by @mrtuvn)
 - #29804: Fixed Unable to apply data patch issue after upgrade in 2.4 #29365 (by @ravi-chandra3197)


Fixed GitHub Issues:
 - #31801: [Issue] Removed CliIndexerReindexActionGroup action group usage for Sales module (reported by @m2-assistant[bot]) has been fixed in #31788 by @sergiy-v in 2.4-develop branch
   Related commits:
     1. 9dd746a

 - #31517: [Issue] [MFTF] Refactoring AdminMassOrdersCancelProcessingAndClosedTest (reported by @m2-assistant[bot]) has been fixed in #31507 by @AnnaAPak in 2.4-develop branch
   Related commits:
     1. 7c478a9

 - #31530: [Issue] Remove recursion in location of static files. (reported by @m2-assistant[bot]) has been fixed in #30883 by @edspc in 2.4-develop branch
   Related commits:
     1. 9f3ab3a
     2. dc1662d

 - #31641: [Issue] Moving array access for CAPTCHA _.isEmpty check (reported by @m2-assistant[bot]) has been fixed in #31636 by @MellenIO in 2.4-develop branch
   Related commits:
     1. 36c031a

 - #31623: [Issue] [MFTF] Adding AdminClickCreateNewStatusButtonOnOrderStatusPageActionGroup (reported by @m2-assistant[bot]) has been fixed in #31604 by @AnnaAPak in 2.4-develop branch
   Related commits:
     1. 031c1dd
     2. 1666c33
     3. 2f31728

 - #25907: CatalogSpecialPriceStorage API delete does not delete by store id (reported by @nthurston) has been fixed in #31485 by @engcom-Charlie in 2.4-develop branch
   Related commits:
     1. de30e9c
     2. 8f843ef
     3. 8fccf46
     4. 287084c
     5. d30fea0
     6. cb230b5
     7. 9e51c8e
     8. 2d56b2e

 - #31514: [Issue] [MFTF] Refactoring AdminMassOrdersUpdateCancelPendingOrderTest (reported by @m2-assistant[bot]) has been fixed in #31512 by @AnnaAPak in 2.4-develop branch
   Related commits:
     1. 7aea8c5
     2. 7befff5

 - #31519: [Issue] [MFTF] Refactoring AdminPanelIsFrozenIfStorefrontIsOpenedViaCustomerViewTest (reported by @m2-assistant[bot]) has been fixed in #31502 by @AnnaAPak in 2.4-develop branch
   Related commits:
     1. e840a57
     2. 68cd8a8

 - #31515: [Issue] [MFTF] Refactoring AdminMassOrdersHoldOnCompleteTest (reported by @m2-assistant[bot]) has been fixed in #31510 by @AnnaAPak in 2.4-develop branch
   Related commits:
     1. 9efb105
     2. 4ff32df

 - #31520: [Issue] [MFTF] Refactoring AdminValidateShippingTrackingNumberTest (reported by @m2-assistant[bot]) has been fixed in #31488 by @AnnaAPak in 2.4-develop branch
   Related commits:
     1. 0406e76
     2. 7cedea5
     3. e00dec7

 - #30936: Perfomance:Cms/Model/Page/DataProvider.php#L103 loads full collection without any filter (reported by @larsroettig) has been fixed in #30943 by @larsroettig in 2.4-develop branch
   Related commits:
     1. 94a7467
     2. bb07bc0
     3. 3819438
     4. 3041fc6
     5. b9987d1
     6. 6de189f
     7. 17d3895
     8. cdecd30
     9. 17316ae
     10. 912374c
     11. 8ca6c5a
     12. 77ad90d
     13. dc965fc
     14. 65da3e6
     15. a2327c9
     16. 9ee832e
     17. 2900e74
     18. f11d277

 - #31300: [Issue] fix reference layout cms_noroute_index core (reported by @m2-assistant[bot]) has been fixed in #31299 by @PierW in 2.4-develop branch
   Related commits:
     1. 376676f

 - #30882: [Issue] Update sortOrder load for async css plugin (reported by @m2-assistant[bot]) has been fixed in #30871 by @mrtuvn in 2.4-develop branch
   Related commits:
     1. cc6d016

 - #29365: Magento 2.4 Upgrade issue Unable to apply data patch Magento\CatalogUrlRewrite\Setup\Patch\Data\UpdateUrlKeyForProducts (reported by @sunel) has been fixed in #29804 by @ravi-chandra3197 in 2.4-develop branch
   Related commits:
     1. b2b29ea
     2. a06ec39

 - #29805: Magento 2.4 upgrade fails if there is data under catalog_product_entity_varchar (reported by @HeiderSati) has been fixed in #29804 by @ravi-chandra3197 in 2.4-develop branch
   Related commits:
     1. b2b29ea
     2. a06ec39
  • Loading branch information
gabrieldagama authored Feb 5, 2021
2 parents f5c5db7 + 47e385d commit 3b397a9
Show file tree
Hide file tree
Showing 72 changed files with 843 additions and 478 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ define([
*/
checkCustomerData: function (formId, captchaData, captcha) {
if (!_.isEmpty(captchaData) &&
!_.isEmpty(captchaData)[formId] &&
!_.isEmpty(captchaData[formId]) &&
captchaData[formId].timestamp > captcha.timestamp
) {
if (!captcha.isRequired() && captchaData[formId].isRequired) {
Expand Down
222 changes: 110 additions & 112 deletions app/code/Magento/Catalog/Model/Product/Price/SpecialPriceStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,82 @@

namespace Magento\Catalog\Model\Product\Price;

use Magento\Catalog\Api\Data\SpecialPriceInterface;
use Magento\Catalog\Api\Data\SpecialPriceInterfaceFactory;
use Magento\Catalog\Api\SpecialPriceStorageInterface;
use Magento\Catalog\Model\Product\Price\Validation\InvalidSkuProcessor;
use Magento\Catalog\Model\Product\Price\Validation\Result;
use Magento\Catalog\Model\ProductIdLocatorInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Catalog\Helper\Data;
use Magento\Store\Api\StoreRepositoryInterface;

/**
* Special price storage presents efficient price API and is used to retrieve, update or delete special prices.
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class SpecialPriceStorage implements \Magento\Catalog\Api\SpecialPriceStorageInterface
class SpecialPriceStorage implements SpecialPriceStorageInterface
{
/**
* @var \Magento\Catalog\Api\SpecialPriceInterface
*/
private $specialPriceResource;

/**
* @var \Magento\Catalog\Api\Data\SpecialPriceInterfaceFactory
* @var SpecialPriceInterfaceFactory
*/
private $specialPriceFactory;

/**
* @var \Magento\Catalog\Model\ProductIdLocatorInterface
* @var ProductIdLocatorInterface
*/
private $productIdLocator;

/**
* @var \Magento\Store\Api\StoreRepositoryInterface
* @var StoreRepositoryInterface
*/
private $storeRepository;

/**
* @var \Magento\Catalog\Model\Product\Price\Validation\Result
* @var Result
*/
private $validationResult;

/**
* @var \Magento\Catalog\Model\Product\Price\Validation\InvalidSkuProcessor
* @var InvalidSkuProcessor
*/
private $invalidSkuProcessor;

/**
* @var array
*/
private $allowedProductTypes = [];
private $allowedProductTypes;

/**
* @var Data
*/
private $catalogData;

/**
* @param \Magento\Catalog\Api\SpecialPriceInterface $specialPriceResource
* @param \Magento\Catalog\Api\Data\SpecialPriceInterfaceFactory $specialPriceFactory
* @param \Magento\Catalog\Model\ProductIdLocatorInterface $productIdLocator
* @param \Magento\Store\Api\StoreRepositoryInterface $storeRepository
* @param \Magento\Catalog\Model\Product\Price\Validation\Result $validationResult
* @param \Magento\Catalog\Model\Product\Price\Validation\InvalidSkuProcessor $invalidSkuProcessor
* @param array $allowedProductTypes [optional]
* @param SpecialPriceInterfaceFactory $specialPriceFactory
* @param ProductIdLocatorInterface $productIdLocator
* @param StoreRepositoryInterface $storeRepository
* @param Result $validationResult
* @param InvalidSkuProcessor $invalidSkuProcessor
* @param array $allowedProductTypes
* @param Data|null $catalogData
*/
public function __construct(
\Magento\Catalog\Api\SpecialPriceInterface $specialPriceResource,
\Magento\Catalog\Api\Data\SpecialPriceInterfaceFactory $specialPriceFactory,
\Magento\Catalog\Model\ProductIdLocatorInterface $productIdLocator,
\Magento\Store\Api\StoreRepositoryInterface $storeRepository,
\Magento\Catalog\Model\Product\Price\Validation\Result $validationResult,
\Magento\Catalog\Model\Product\Price\Validation\InvalidSkuProcessor $invalidSkuProcessor,
array $allowedProductTypes = []
SpecialPriceInterfaceFactory $specialPriceFactory,
ProductIdLocatorInterface $productIdLocator,
StoreRepositoryInterface $storeRepository,
Result $validationResult,
InvalidSkuProcessor $invalidSkuProcessor,
array $allowedProductTypes = [],
?Data $catalogData = null
) {
$this->specialPriceResource = $specialPriceResource;
$this->specialPriceFactory = $specialPriceFactory;
Expand All @@ -73,10 +90,11 @@ public function __construct(
$this->validationResult = $validationResult;
$this->invalidSkuProcessor = $invalidSkuProcessor;
$this->allowedProductTypes = $allowedProductTypes;
$this->catalogData = $catalogData ?: ObjectManager::getInstance()->get(Data::class);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function get(array $skus)
{
Expand All @@ -85,7 +103,7 @@ public function get(array $skus)

$prices = [];
foreach ($rawPrices as $rawPrice) {
/** @var \Magento\Catalog\Api\Data\SpecialPriceInterface $price */
/** @var SpecialPriceInterface $price */
$price = $this->specialPriceFactory->create();
$sku = isset($rawPrice['sku'])
? $rawPrice['sku']
Expand All @@ -102,7 +120,7 @@ public function get(array $skus)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function update(array $prices)
{
Expand All @@ -113,7 +131,7 @@ public function update(array $prices)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function delete(array $prices)
{
Expand All @@ -140,52 +158,14 @@ private function retrieveValidPrices(array $prices)

foreach ($prices as $key => $price) {
if (!$price->getSku() || in_array($price->getSku(), $failedSkus)) {
$this->validationResult->addFailedItem(
$key,
__(
'The product that was requested doesn\'t exist. Verify the product and try again. '
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.',
[
'SKU' => $price->getSku(),
'storeId' => $price->getStoreId(),
'priceFrom' => $price->getPriceFrom(),
'priceTo' => $price->getPriceTo()
]
),
[
'SKU' => $price->getSku(),
'storeId' => $price->getStoreId(),
'priceFrom' => $price->getPriceFrom(),
'priceTo' => $price->getPriceTo()
]
);
$errorMessage = 'The product that was requested doesn\'t exist. Verify the product and try again. '
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.';
$this->addFailedItemPrice($price, $key, $errorMessage, []);
}
$this->checkStore($price, $key);
$this->checkPrice($price, $key);
$this->checkDate($price, $price->getPriceFrom(), 'Price From', $key);
$this->checkDate($price, $price->getPriceTo(), 'Price To', $key);
try {
$this->storeRepository->getById($price->getStoreId());
} catch (NoSuchEntityException $e) {
$this->validationResult->addFailedItem(
$key,
__(
'Requested store is not found. '
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.',
[
'SKU' => $price->getSku(),
'storeId' => $price->getStoreId(),
'priceFrom' => $price->getPriceFrom(),
'priceTo' => $price->getPriceTo()
]
),
[
'SKU' => $price->getSku(),
'storeId' => $price->getStoreId(),
'priceFrom' => $price->getPriceFrom(),
'priceTo' => $price->getPriceTo()
]
);
}
}

foreach ($this->validationResult->getFailedRowIds() as $id) {
Expand All @@ -195,77 +175,95 @@ private function retrieveValidPrices(array $prices)
return $prices;
}

/**
* Check that store exists and is global when price scope is global and otherwise add error to aggregator.
*
* @param SpecialPriceInterface $price
* @param int $key
* @return void
*/
private function checkStore(SpecialPriceInterface $price, int $key): void
{
if ($this->catalogData->isPriceGlobal() && $price->getStoreId() !== 0) {
$errorMessage = 'Could not change non global Price when price scope is global. '
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.';
$this->addFailedItemPrice($price, $key, $errorMessage, []);
}

try {
$this->storeRepository->getById($price->getStoreId());
} catch (NoSuchEntityException $e) {
$errorMessage = 'Requested store is not found. '
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.';
$this->addFailedItemPrice($price, $key, $errorMessage, []);
}
}

/**
* Check that date value is correct and add error to aggregator if it contains incorrect data.
*
* @param \Magento\Catalog\Api\Data\SpecialPriceInterface $price
* @param SpecialPriceInterface $price
* @param string $value
* @param string $label
* @param int $key
* @return void
*/
private function checkDate(\Magento\Catalog\Api\Data\SpecialPriceInterface $price, $value, $label, $key)
private function checkDate(SpecialPriceInterface $price, $value, $label, $key)
{
if ($value && !$this->isCorrectDateValue($value)) {
$this->validationResult->addFailedItem(
$key,
__(
'Invalid attribute %label = %priceTo. '
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.',
[
'label' => $label,
'SKU' => $price->getSku(),
'storeId' => $price->getStoreId(),
'priceFrom' => $price->getPriceFrom(),
'priceTo' => $price->getPriceTo()
]
),
[
'label' => $label,
'SKU' => $price->getSku(),
'storeId' => $price->getStoreId(),
'priceFrom' => $price->getPriceFrom(),
'priceTo' => $price->getPriceTo()
]
);
$errorMessage = 'Invalid attribute %label = %priceTo. '
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.';
$this->addFailedItemPrice($price, $key, $errorMessage, ['label' => $label]);
}
}

/**
* Check that provided price value is not empty and not lower then zero and add error to aggregator if price
* Check price.
*
* Verify that provided price value is not empty and not lower then zero and add error to aggregator if price
* contains not valid data.
*
* @param \Magento\Catalog\Api\Data\SpecialPriceInterface $price
* @param SpecialPriceInterface $price
* @param int $key
* @return void
*/
private function checkPrice(\Magento\Catalog\Api\Data\SpecialPriceInterface $price, $key)
private function checkPrice(SpecialPriceInterface $price, int $key): void
{
if (null === $price->getPrice() || $price->getPrice() < 0) {
$this->validationResult->addFailedItem(
$key,
__(
'Invalid attribute Price = %price. '
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.',
[
'price' => $price->getPrice(),
'SKU' => $price->getSku(),
'storeId' => $price->getStoreId(),
'priceFrom' => $price->getPriceFrom(),
'priceTo' => $price->getPriceTo()
]
),
[
'price' => $price->getPrice(),
'SKU' => $price->getSku(),
'storeId' => $price->getStoreId(),
'priceFrom' => $price->getPriceFrom(),
'priceTo' => $price->getPriceTo()
]
);
$errorMessage = 'Invalid attribute Price = %price. '
. 'Row ID: SKU = %SKU, Store ID: %storeId, Price From: %priceFrom, Price To: %priceTo.';
$this->addFailedItemPrice($price, $key, $errorMessage, ['price' => $price->getPrice()]);
}
}

/**
* Adds failed item price to validation result
*
* @param SpecialPriceInterface $price
* @param int $key
* @param string $message
* @param array $firstParam
* @return void
*/
private function addFailedItemPrice(
SpecialPriceInterface $price,
int $key,
string $message,
array $firstParam
): void {
$additionalInfo = [];
if ($firstParam) {
$additionalInfo = array_merge($additionalInfo, $firstParam);
}

$additionalInfo['SKU'] = $price->getSku();
$additionalInfo['storeId'] = $price->getStoreId();
$additionalInfo['priceFrom'] = $price->getPriceFrom();
$additionalInfo['priceTo'] = $price->getPriceTo();

$this->validationResult->addFailedItem($key, __($message, $additionalInfo), $additionalInfo);
}

/**
* Retrieve SKU by product ID.
*
Expand Down
Loading

0 comments on commit 3b397a9

Please sign in to comment.