Skip to content

Commit

Permalink
Merge pull request #5416 from magento-tsg-csl3/2.4-develop-pr15
Browse files Browse the repository at this point in the history
[TSG-CSL3] For 2.4 (pr15)
  • Loading branch information
zakdma authored Mar 3, 2020
2 parents 45b624c + 475c521 commit 0d3defe
Show file tree
Hide file tree
Showing 20 changed files with 343 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*
* Service which allows to sync product widget information, such as product id with db. In order to reuse this info
* on different devices
*
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class Synchronizer
{
Expand Down Expand Up @@ -94,6 +96,7 @@ public function __construct(
*
* @param string $namespace
* @return int
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function getLifeTimeByNamespace($namespace)
{
Expand All @@ -119,6 +122,7 @@ private function getLifeTimeByNamespace($namespace)
* @param array $productsData (product action data, that came from frontend)
* @param string $typeId namespace (type of action)
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function filterNewestActions(array $productsData, $typeId)
{
Expand Down Expand Up @@ -166,6 +170,7 @@ private function getProductIdsByActions(array $actions)
* @param array $productsData
* @param string $typeId
* @return void
* @throws \Exception
*/
public function syncActions(array $productsData, $typeId)
{
Expand All @@ -189,16 +194,15 @@ public function syncActions(array $productsData, $typeId)
foreach ($collection as $item) {
$this->entityManager->delete($item);
}

foreach ($productsData as $productId => $productData) {
foreach ($productsData as $productData) {
/** @var ProductFrontendActionInterface $action */
$action = $this->productFrontendActionFactory->create(
[
'data' => [
'visitor_id' => $customerId ? null : $visitorId,
'customer_id' => $this->session->getCustomerId(),
'added_at' => $productData['added_at'],
'product_id' => $productId,
'product_id' => $productData['product_id'],
'type_id' => $typeId
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,7 @@ protected function _productLimitationJoinPrice()
* @see \Magento\Catalog\Model\ResourceModel\Product\Collection::_productLimitationJoinPrice()
* @param bool $joinLeft
* @return $this
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function _productLimitationPrice($joinLeft = false)
{
Expand All @@ -1922,14 +1923,14 @@ protected function _productLimitationPrice($joinLeft = false)

$connection = $this->getConnection();
$select = $this->getSelect();
$joinCond = join(
' AND ',
[
'price_index.entity_id = e.entity_id',
$connection->quoteInto('price_index.website_id = ?', $filters['website_id']),
$connection->quoteInto('price_index.customer_group_id = ?', $filters['customer_group_id'])
]
);
$joinCondArray = [];
$joinCondArray[] = 'price_index.entity_id = e.entity_id';
$joinCondArray[] = $connection->quoteInto('price_index.customer_group_id = ?', $filters['customer_group_id']);
// Add website condition only if it's different from admin scope
if (((int) $filters['website_id']) !== Store::DEFAULT_STORE_ID) {
$joinCondArray[] = $connection->quoteInto('price_index.website_id = ?', $filters['website_id']);
}
$joinCond = join(' AND ', $joinCondArray);

$fromPart = $select->getPart(\Magento\Framework\DB\Select::FROM);
if (!isset($fromPart['price_index'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ public function testFilterProductActions()
{
$typeId = 'recently_compared_product';
$productsData = [
1 => [
'website-1-1' => [
'added_at' => 12,
'product_id' => 1,
],
2 => [
'website-1-2' => [
'added_at' => 13,
'product_id' => '2',
],
3 => [
'website-2-3' => [
'added_at' => 14,
'product_id' => 3,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
// Can't add new translated strings in patch release
'invalidLayoutUpdate' => 'Invalid format.',
'insufficientPermissions' => 'Invalid format.',
ValidatorInterface::ERROR_SKU_MARGINAL_WHITESPACES => 'SKU contains marginal whitespaces'
];
//@codingStandardsIgnoreEnd

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ interface RowValidatorInterface extends \Magento\Framework\Validator\ValidatorIn

const ERROR_DUPLICATE_MULTISELECT_VALUES = 'duplicatedMultiselectValues';

const ERROR_SKU_MARGINAL_WHITESPACES = 'skuMarginalWhitespaces';

/**
* Value that means all entities (e.g. websites, groups etc.)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Magento\Catalog\Model\Product\Attribute\Backend\Sku;

/**
* Class Validator
* Product import model validator
*
* @api
* @since 100.0.2
Expand Down Expand Up @@ -72,8 +72,12 @@ protected function textValidation($attrCode, $type)
$val = $this->string->cleanString($this->_rowData[$attrCode]);
if ($type == 'text') {
$valid = $this->string->strlen($val) < Product::DB_MAX_TEXT_LENGTH;
} else if ($attrCode == Product::COL_SKU) {
} elseif ($attrCode == Product::COL_SKU) {
$valid = $this->string->strlen($val) <= SKU::SKU_MAX_LENGTH;
if ($this->string->strlen($val) !== $this->string->strlen(trim($val))) {
$this->_addMessages([RowValidatorInterface::ERROR_SKU_MARGINAL_WHITESPACES]);
return false;
}
} else {
$valid = $this->string->strlen($val) < Product::DB_MAX_VARCHAR_LENGTH;
}
Expand Down Expand Up @@ -359,5 +363,7 @@ public function init($context)
foreach ($this->validators as $validator) {
$validator->init($context);
}

return $this;
}
}
77 changes: 42 additions & 35 deletions app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\ProductCategoryList;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Store\Model\Store;

/**
Expand Down Expand Up @@ -122,59 +123,47 @@ protected function _addSpecialAttributes(array &$attributes)
/**
* Add condition to collection
*
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
* @param Collection $collection
* @return $this
*/
public function addToCollection($collection)
{
$attribute = $this->getAttributeObject();
$attributeCode = $attribute->getAttributeCode();
if ($attributeCode !== 'price' || !$collection->getLimitationFilters()->isUsingPriceIndex()) {
if ($collection->isEnabledFlat()) {
if ($attribute->isEnabledInFlat()) {
$alias = array_keys($collection->getSelect()->getPart('from'))[0];
$this->joinedAttributes[$attributeCode] = $alias . '.' . $attributeCode;
} else {
$alias = 'at_' . $attributeCode;
if (!in_array($alias, array_keys($collection->getSelect()->getPart('from')))) {
$collection->joinAttribute($attributeCode, "catalog_product/$attributeCode", 'entity_id');
}

if ($collection->isEnabledFlat()) {
if ($attribute->isEnabledInFlat()) {
$alias = array_keys($collection->getSelect()->getPart('from'))[0];
$this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.' . $attribute->getAttributeCode();
} else {
$alias = 'at_' . $attribute->getAttributeCode();
if (!in_array($alias, array_keys($collection->getSelect()->getPart('from')))) {
$collection->joinAttribute(
$attribute->getAttributeCode(),
'catalog_product/'.$attribute->getAttributeCode(),
'entity_id'
);
$this->joinedAttributes[$attributeCode] = $alias . '.value';
}

$this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.value';
} elseif ($attributeCode !== 'category_ids' && !$attribute->isStatic()) {
$this->addAttributeToCollection($attribute, $collection);
$attributes = $this->getRule()->getCollectedAttributes();
$attributes[$attributeCode] = true;
$this->getRule()->setCollectedAttributes($attributes);
}
return $this;
}

if ('category_ids' == $attribute->getAttributeCode() || $attribute->isStatic()) {
return $this;
}

if ($attribute->getBackend() && $attribute->isScopeGlobal()) {
$this->addGlobalAttribute($attribute, $collection);
} else {
$this->addNotGlobalAttribute($attribute, $collection);
}

$attributes = $this->getRule()->getCollectedAttributes();
$attributes[$attribute->getAttributeCode()] = true;
$this->getRule()->setCollectedAttributes($attributes);

return $this;
}

/**
* Adds Attributes that belong to Global Scope
*
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
* @param Collection $collection
* @return $this
*/
protected function addGlobalAttribute(
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute,
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
Collection $collection
) {
switch ($attribute->getBackendType()) {
case 'decimal':
Expand Down Expand Up @@ -207,12 +196,12 @@ protected function addGlobalAttribute(
* Adds Attributes that don't belong to Global Scope
*
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
* @param Collection $collection
* @return $this
*/
protected function addNotGlobalAttribute(
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute,
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
Collection $collection
) {
$storeId = $this->storeManager->getStore()->getId();
$values = $collection->getAllAttributeValues($attribute);
Expand Down Expand Up @@ -255,6 +244,8 @@ public function getMappedSqlField()
$result = parent::getMappedSqlField();
} elseif (isset($this->joinedAttributes[$this->getAttribute()])) {
$result = $this->joinedAttributes[$this->getAttribute()];
} elseif ($this->getAttribute() === 'price') {
$result = 'price_index.min_price';
} elseif ($this->getAttributeObject()->isStatic()) {
$result = $this->getAttributeObject()->getAttributeCode();
} elseif ($this->getValueParsed()) {
Expand All @@ -267,11 +258,27 @@ public function getMappedSqlField()
/**
* @inheritdoc
*
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection
* @param Collection $productCollection
* @return $this
*/
public function collectValidatedAttributes($productCollection)
{
return $this->addToCollection($productCollection);
}

/**
* Add attribute to collection based on scope
*
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
* @param Collection $collection
* @return void
*/
private function addAttributeToCollection($attribute, $collection): void
{
if ($attribute->getBackend() && $attribute->isScopeGlobal()) {
$this->addGlobalAttribute($attribute, $collection);
} else {
$this->addNotGlobalAttribute($attribute, $collection);
}
}
}
20 changes: 19 additions & 1 deletion app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Magento\Framework\Controller\Result\RawFactory;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Filesystem\Driver\File;

/**
* Process template text for wysiwyg editor.
Expand Down Expand Up @@ -67,6 +68,11 @@ class Directive extends Action implements HttpGetActionInterface
*/
private $filter;

/**
* @var File
*/
private $file;

/**
* Constructor
*
Expand All @@ -77,6 +83,7 @@ class Directive extends Action implements HttpGetActionInterface
* @param LoggerInterface|null $logger
* @param Config|null $config
* @param Filter|null $filter
* @param File|null $file
*/
public function __construct(
Context $context,
Expand All @@ -85,7 +92,8 @@ public function __construct(
AdapterFactory $adapterFactory = null,
LoggerInterface $logger = null,
Config $config = null,
Filter $filter = null
Filter $filter = null,
File $file = null
) {
parent::__construct($context);
$this->urlDecoder = $urlDecoder;
Expand All @@ -94,6 +102,7 @@ public function __construct(
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
$this->config = $config ?: ObjectManager::getInstance()->get(Config::class);
$this->filter = $filter ?: ObjectManager::getInstance()->get(Filter::class);
$this->file = $file ?: ObjectManager::getInstance()->get(File::class);
}

/**
Expand Down Expand Up @@ -127,6 +136,15 @@ public function execute()
$this->logger->warning($e);
}
}
$mimeType = $image->getMimeType();
unset($image);
// To avoid issues with PNG images with alpha blending we return raw file
// after validation as an image source instead of generating the new PNG image
// with image adapter
$content = $this->file->fileGetContents($imagePath);
$resultRaw->setHeader('Content-Type', $mimeType);
$resultRaw->setContents($content);

return $resultRaw;
}
}
Loading

0 comments on commit 0d3defe

Please sign in to comment.