Skip to content

Commit

Permalink
Merge branch '2.4-develop' into bugfix/rest-api-pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
ihor-sviziev authored Mar 3, 2020
2 parents 6c171ce + 0d3defe commit 8c9189f
Show file tree
Hide file tree
Showing 83 changed files with 4,136 additions and 520 deletions.
23 changes: 0 additions & 23 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,6 @@

DirectoryIndex index.php

<IfModule mod_php5.c>
############################################
## adjust memory limit

php_value memory_limit 756M
php_value max_execution_time 18000

############################################
## disable automatic session start
## before autoload was initialized

php_flag session.auto_start off

############################################
## enable resulting html compression

#php_flag zlib.output_compression on

###########################################
## disable user agent verification to not break multiple image upload

php_flag suhosin.session.cryptua off
</IfModule>
<IfModule mod_php7.c>
############################################
## adjust memory limit
Expand Down
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 @@ -1911,6 +1911,7 @@ protected function _productLimitationJoinPrice()
* @param bool $joinLeft
* @return $this
* @see \Magento\Catalog\Model\ResourceModel\Product\Collection::_productLimitationJoinPrice()
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function _productLimitationPrice($joinLeft = false)
{
Expand All @@ -1929,14 +1930,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 @@ -4,11 +4,15 @@
* See COPYING.txt for license details.
*/
?>
<?php /** @var $block \Magento\Catalog\Block\Product\Image */ ?>
<?php
/** @var $block \Magento\Catalog\Block\Product\Image */
/** @var $escaper \Magento\Framework\Escaper */
?>

<img class="photo image <?= $block->escapeHtmlAttr($block->getClass()) ?>"
<?= $block->escapeHtml($block->getCustomAttributes()) ?>
src="<?= $block->escapeUrl($block->getImageUrl()) ?>"
width="<?= $block->escapeHtmlAttr($block->getWidth()) ?>"
height="<?= $block->escapeHtmlAttr($block->getHeight()) ?>"
alt="<?= /* @noEscape */ $block->stripTags($block->getLabel(), null, true) ?>" />
<img class="photo image <?= $escaper->escapeHtmlAttr($block->getClass()) ?>"
<?= $escaper->escapeHtml($block->getCustomAttributes()) ?>
src="<?= $escaper->escapeUrl($block->getImageUrl()) ?>"
loading="lazy"
width="<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>"
height="<?= $escaper->escapeHtmlAttr($block->getHeight()) ?>"
alt="<?= $escaper->escapeHtmlAttr($block->getLabel()) ?>" />
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
* See COPYING.txt for license details.
*/
?>
<?php /** @var $block \Magento\Catalog\Block\Product\Image */ ?>
<?php
/** @var $block \Magento\Catalog\Block\Product\Image */
/** @var $escaper \Magento\Framework\Escaper */
?>

<span class="product-image-container"
style="width:<?= $block->escapeHtmlAttr($block->getWidth()) ?>px;">
style="width:<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>px;">
<span class="product-image-wrapper"
style="padding-bottom: <?= ($block->getRatio() * 100) ?>%;">
<img class="<?= $block->escapeHtmlAttr($block->getClass()) ?>"
<?= $block->escapeHtmlAttr($block->getCustomAttributes()) ?>
src="<?= $block->escapeUrl($block->getImageUrl()) ?>"
max-width="<?= $block->escapeHtmlAttr($block->getWidth()) ?>"
max-height="<?= $block->escapeHtmlAttr($block->getHeight()) ?>"
alt="<?= /* @noEscape */ $block->stripTags($block->getLabel(), null, true) ?>"/></span>
<img class="<?= $escaper->escapeHtmlAttr($block->getClass()) ?>"
<?= $escaper->escapeHtmlAttr($block->getCustomAttributes()) ?>
src="<?= $escaper->escapeUrl($block->getImageUrl()) ?>"
loading="lazy"
width="<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>"
height="<?= $escaper->escapeHtmlAttr($block->getHeight()) ?>"
alt="<?= $escaper->escapeHtmlAttr($block->getLabel()) ?>"/></span>
</span>
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);
}
}
}
Loading

0 comments on commit 8c9189f

Please sign in to comment.