Skip to content

Commit

Permalink
Merge branch '2.3-develop' into MAGETWO-98844
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii-balko committed May 15, 2019
2 parents f2b9cb1 + 211dd25 commit 6c2a841
Show file tree
Hide file tree
Showing 85 changed files with 2,366 additions and 310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ define([
element = $('#' + this.options.elementId),
self = this,
params = {},
msg = '';
msg = '',
fieldToCheck = this.options.fieldToCheck || 'success';

element.removeClass('success').addClass('fail');
$.each($.parseJSON(this.options.fieldMapping), function (key, el) {
Expand All @@ -49,9 +50,10 @@ define([
$.ajax({
url: this.options.url,
showLoader: true,
data: params
data: params,
headers: this.options.headers || {}
}).done(function (response) {
if (response.success) {
if (response[fieldToCheck]) {
element.removeClass('fail').addClass('success');
result = self.options.successText;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

namespace Magento\Catalog\Model\Product\Attribute\Backend\TierPrice;

use Magento\Framework\EntityManager\Operation\ExtensionInterface;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Locale\FormatInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
use Magento\Customer\Api\GroupManagementInterface;
Expand Down Expand Up @@ -40,26 +41,34 @@ class UpdateHandler extends AbstractHandler
*/
private $tierPriceResource;

/**
* @var FormatInterface
*/
private $localeFormat;

/**
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository
* @param \Magento\Customer\Api\GroupManagementInterface $groupManagement
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
* @param \Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Tierprice $tierPriceResource
* @param FormatInterface|null $localeFormat
*/
public function __construct(
StoreManagerInterface $storeManager,
ProductAttributeRepositoryInterface $attributeRepository,
GroupManagementInterface $groupManagement,
MetadataPool $metadataPool,
Tierprice $tierPriceResource
Tierprice $tierPriceResource,
FormatInterface $localeFormat = null
) {
parent::__construct($groupManagement);

$this->storeManager = $storeManager;
$this->attributeRepository = $attributeRepository;
$this->metadataPoll = $metadataPool;
$this->tierPriceResource = $tierPriceResource;
$this->localeFormat = $localeFormat ?: ObjectManager::getInstance()->get(FormatInterface::class);
}

/**
Expand Down Expand Up @@ -125,8 +134,9 @@ private function updateValues(array $valuesToUpdate, array $oldValues): bool
{
$isChanged = false;
foreach ($valuesToUpdate as $key => $value) {
if ((!empty($value['value']) && (float)$oldValues[$key]['price'] !== (float)$value['value'])
|| $this->getPercentage($oldValues[$key]) !== $this->getPercentage($value)
if ((!empty($value['value'])
&& (float)$oldValues[$key]['price'] !== $this->localeFormat->getNumber($value['value'])
) || $this->getPercentage($oldValues[$key]) !== $this->getPercentage($value)
) {
$price = new \Magento\Framework\DataObject(
[
Expand Down
50 changes: 30 additions & 20 deletions app/code/Magento/Catalog/Model/ResourceModel/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Magento\Framework\App\ObjectManager;
use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer;
use Magento\Eav\Model\Entity\Attribute\UniqueValidationInterface;
use Magento\Framework\EntityManager\EntityManager;
use Magento\Framework\Model\AbstractModel;

/**
* Product entity resource model
Expand Down Expand Up @@ -44,7 +46,7 @@ class Product extends AbstractResource
/**
* Category collection factory
*
* @var \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory
* @var Category\CollectionFactory
*/
protected $_categoryCollectionFactory;

Expand All @@ -64,7 +66,7 @@ class Product extends AbstractResource
protected $typeFactory;

/**
* @var \Magento\Framework\EntityManager\EntityManager
* @var EntityManager
* @since 101.0.0
*/
protected $entityManager;
Expand All @@ -81,7 +83,7 @@ class Product extends AbstractResource
protected $availableCategoryIdsCache = [];

/**
* @var \Magento\Catalog\Model\ResourceModel\Product\CategoryLink
* @var Product\CategoryLink
*/
private $productCategoryLink;

Expand Down Expand Up @@ -110,7 +112,7 @@ public function __construct(
\Magento\Eav\Model\Entity\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Catalog\Model\Factory $modelFactory,
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory,
Category\CollectionFactory $categoryCollectionFactory,
Category $catalogCategory,
\Magento\Framework\Event\ManagerInterface $eventManager,
\Magento\Eav\Model\Entity\Attribute\SetFactory $setFactory,
Expand Down Expand Up @@ -236,7 +238,7 @@ public function getWebsiteIdsByProductIds($productIds)
/**
* Retrieve product category identifiers
*
* @param \Magento\Catalog\Model\Product $product
* @param \Magento\Catalog\Model\Product $product
* @return array
*/
public function getCategoryIds($product)
Expand All @@ -248,7 +250,7 @@ public function getCategoryIds($product)
/**
* Get product identifier by sku
*
* @param string $sku
* @param string $sku
* @return int|false
*/
public function getIdBySku($sku)
Expand Down Expand Up @@ -348,11 +350,11 @@ protected function _saveCategories(\Magento\Framework\DataObject $object)
* Get collection of product categories
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Catalog\Model\ResourceModel\Category\Collection
* @return Category\Collection
*/
public function getCategoryCollection($product)
{
/** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $collection */
/** @var Category\Collection $collection */
$collection = $this->_categoryCollectionFactory->create();
$collection->joinField(
'product_id',
Expand Down Expand Up @@ -428,18 +430,26 @@ public function getDefaultAttributeSourceModel()
/**
* Check availability display product in category
*
* @param \Magento\Catalog\Model\Product $product
* @param \Magento\Catalog\Model\Product|int $product
* @param int $categoryId
* @return string
*/
public function canBeShowInCategory($product, $categoryId)
{
if ($product instanceof \Magento\Catalog\Model\Product) {
$productId = $product->getEntityId();
$storeId = $product->getStoreId();
} else {
$productId = $product;
$storeId = $this->_storeManager->getStore()->getId();
}

$select = $this->getConnection()->select()->from(
$this->tableMaintainer->getMainTable($product->getStoreId()),
$this->tableMaintainer->getMainTable($storeId),
'product_id'
)->where(
'product_id = ?',
(int)$product->getEntityId()
(int)$productId
)->where(
'category_id = ?',
(int)$categoryId
Expand Down Expand Up @@ -614,7 +624,7 @@ public function validate($object)
/**
* Reset firstly loaded attributes
*
* @param \Magento\Framework\Model\AbstractModel $object
* @param AbstractModel $object
* @param integer $entityId
* @param array|null $attributes
* @return $this
Expand Down Expand Up @@ -667,12 +677,12 @@ protected function evaluateDelete($object, $id, $connection)
/**
* Save entity's attributes into the object's resource
*
* @param \Magento\Framework\Model\AbstractModel $object
* @param AbstractModel $object
* @return $this
* @throws \Exception
* @since 101.0.0
*/
public function save(\Magento\Framework\Model\AbstractModel $object)
public function save(AbstractModel $object)
{
$this->getEntityManager()->save($object);
return $this;
Expand All @@ -681,13 +691,13 @@ public function save(\Magento\Framework\Model\AbstractModel $object)
/**
* Retrieve entity manager object
*
* @return \Magento\Framework\EntityManager\EntityManager
* @return EntityManager
*/
private function getEntityManager()
{
if (null === $this->entityManager) {
$this->entityManager = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\EntityManager\EntityManager::class);
$this->entityManager = ObjectManager::getInstance()
->get(EntityManager::class);
}
return $this->entityManager;
}
Expand All @@ -707,13 +717,13 @@ private function getProductWebsiteLink()
* Retrieve CategoryLink object
*
* @deprecated 101.1.0
* @return \Magento\Catalog\Model\ResourceModel\Product\CategoryLink
* @return Product\CategoryLink
*/
private function getProductCategoryLink()
{
if (null === $this->productCategoryLink) {
$this->productCategoryLink = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Catalog\Model\ResourceModel\Product\CategoryLink::class);
$this->productCategoryLink = ObjectManager::getInstance()
->get(Product\CategoryLink::class);
}
return $this->productCategoryLink;
}
Expand Down
70 changes: 32 additions & 38 deletions app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Catalog\Model\Product\Gallery\ReadHandler as GalleryReadHandler;
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory;
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
use Magento\CatalogUrlRewrite\Model\Storage\DbStorage;
use Magento\Customer\Api\GroupManagementInterface;
use Magento\Customer\Model\Indexer\CustomerGroupDimensionProvider;
use Magento\Framework\App\ObjectManager;
Expand Down Expand Up @@ -296,6 +297,11 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac
*/
private $emptyItem;

/**
* @var DbStorage
*/
private $urlFinder;

/**
* Collection constructor
*
Expand Down Expand Up @@ -388,6 +394,19 @@ public function __construct(
?: ObjectManager::getInstance()->get(DimensionFactory::class);
}

/**
* Retrieve urlFinder
*
* @return GalleryReadHandler
*/
private function getUrlFinder()
{
if ($this->urlFinder === null) {
$this->urlFinder = ObjectManager::getInstance()->get(DbStorage::class);
}
return $this->urlFinder;
}

/**
* Get cloned Select after dispatching 'catalog_prepare_price_select' event
*
Expand Down Expand Up @@ -1417,44 +1436,21 @@ protected function _addUrlRewrite()
foreach ($this->getItems() as $item) {
$productIds[] = $item->getEntityId();
}
if (!$productIds) {
return;
}

$select = $this->getConnection()
->select()
->from(['u' => $this->getTable('url_rewrite')], ['u.entity_id', 'u.request_path'])
->where('u.store_id = ?', $this->_storeManager->getStore($this->getStoreId())->getId())
->where('u.is_autogenerated = 1')
->where('u.entity_type = ?', ProductUrlRewriteGenerator::ENTITY_TYPE)
->where('u.entity_id IN(?)', $productIds);

$filter = [
'entity_type' => 'product',
'entity_id' => $productIds,
'store_id' => $this->getStoreId(),
'is_autogenerated' => 1
];
if ($this->_urlRewriteCategory) {
$select->joinInner(
['cu' => $this->getTable('catalog_url_rewrite_product_category')],
'u.url_rewrite_id=cu.url_rewrite_id'
)->where('cu.category_id IN (?)', $this->_urlRewriteCategory);
} else {
$select->joinLeft(
['cu' => $this->getTable('catalog_url_rewrite_product_category')],
'u.url_rewrite_id=cu.url_rewrite_id'
)->where('cu.url_rewrite_id IS NULL');
}

// more priority is data with category id
$urlRewrites = [];

foreach ($this->getConnection()->fetchAll($select) as $row) {
if (!isset($urlRewrites[$row['entity_id']])) {
$urlRewrites[$row['entity_id']] = $row['request_path'];
}
$filter['metadata']['category_id'] = $this->_urlRewriteCategory;
}

foreach ($this->getItems() as $item) {
if (isset($urlRewrites[$item->getEntityId()])) {
$item->setData('request_path', $urlRewrites[$item->getEntityId()]);
} else {
$item->setData('request_path', false);
$rewrites = $this->getUrlFinder()->findAllByData($filter);
foreach ($rewrites as $rewrite) {
if ($item = $this->getItemById($rewrite->getEntityId())) {
$item->setData('request_path', $rewrite->getRequestPath());
}
}
}
Expand Down Expand Up @@ -1976,8 +1972,7 @@ protected function _productLimitationPrice($joinLeft = false)
}
// Set additional field filters
foreach ($this->_priceDataFieldFilters as $filterData) {
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$select->where(call_user_func_array('sprintf', $filterData));
$select->where(sprintf(...$filterData));
}
} else {
$fromPart['price_index']['joinCondition'] = $joinCond;
Expand Down Expand Up @@ -2282,8 +2277,7 @@ private function getBackend()
public function addPriceDataFieldFilter($comparisonFormat, $fields)
{
if (!preg_match('/^%s( (<|>|=|<=|>=|<>) %s)*$/', $comparisonFormat)) {
// phpcs:ignore Magento2.Exceptions.DirectThrow
throw new \Exception('Invalid comparison format.');
throw new \InvalidArgumentException('Invalid comparison format.');
}

if (!is_array($fields)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,8 @@ public function getQuery(array $dimensions, string $productType, array $entityId
$select->where("e.type_id = ?", $productType);

if ($entityIds !== null) {
if (count($entityIds) > 1) {
$select->where(sprintf('e.entity_id BETWEEN %s AND %s', min($entityIds), max($entityIds)));
} else {
$select->where('e.entity_id = ?', $entityIds);
}
$select->where(sprintf('e.entity_id BETWEEN %s AND %s', min($entityIds), max($entityIds)));
$select->where('e.entity_id IN(?)', $entityIds);
}

/**
Expand Down
Loading

0 comments on commit 6c2a841

Please sign in to comment.