Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit b64e470

Browse files
author
Carlos Lizaga
authored
Merge pull request #2 from magento/2.2-develop
PR2
2 parents d4e666f + 08b20b5 commit b64e470

File tree

60 files changed

+2257
-569
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2257
-569
lines changed

app/bootstrap.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,17 @@
4949
unset($_SERVER['ORIG_PATH_INFO']);
5050
}
5151

52-
if (!empty($_SERVER['MAGE_PROFILER'])
52+
if (
53+
(!empty($_SERVER['MAGE_PROFILER']) || file_exists(BP . '/var/profiler.flag'))
5354
&& isset($_SERVER['HTTP_ACCEPT'])
5455
&& strpos($_SERVER['HTTP_ACCEPT'], 'text/html') !== false
5556
) {
57+
$profilerFlag = isset($_SERVER['MAGE_PROFILER']) && strlen($_SERVER['MAGE_PROFILER'])
58+
? $_SERVER['MAGE_PROFILER']
59+
: trim(file_get_contents(BP . '/var/profiler.flag'));
60+
5661
\Magento\Framework\Profiler::applyConfig(
57-
$_SERVER['MAGE_PROFILER'],
62+
$profilerFlag,
5863
BP,
5964
!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
6065
);

app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,14 @@ public function setCollection($collection)
192192
$this->_collection->setPageSize($limit);
193193
}
194194
if ($this->getCurrentOrder()) {
195-
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
195+
if ($this->getCurrentOrder() == 'position') {
196+
$this->_collection->addAttributeToSort(
197+
$this->getCurrentOrder(),
198+
$this->getCurrentDirection()
199+
)->addAttributeToSort('entity_id', $this->getCurrentDirection());
200+
} else {
201+
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
202+
}
196203
}
197204
return $this;
198205
}

app/code/Magento/Catalog/Model/Indexer/Category/Flat/AbstractAction.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,25 +369,55 @@ protected function getAttributeValues($entityIds, $storeId)
369369
}
370370
$values = [];
371371

372-
foreach ($entityIds as $entityId) {
373-
$values[$entityId] = [];
372+
$linkIds = $this->getLinkIds($entityIds);
373+
foreach ($linkIds as $linkId) {
374+
$values[$linkId] = [];
374375
}
376+
375377
$attributes = $this->getAttributes();
376378
$attributesType = ['varchar', 'int', 'decimal', 'text', 'datetime'];
379+
$linkField = $this->getCategoryMetadata()->getLinkField();
377380
foreach ($attributesType as $type) {
378381
foreach ($this->getAttributeTypeValues($type, $entityIds, $storeId) as $row) {
379-
if (isset($row[$this->getCategoryMetadata()->getLinkField()]) && isset($row['attribute_id'])) {
382+
if (isset($row[$linkField]) && isset($row['attribute_id'])) {
380383
$attributeId = $row['attribute_id'];
381384
if (isset($attributes[$attributeId])) {
382385
$attributeCode = $attributes[$attributeId]['attribute_code'];
383-
$values[$row[$this->getCategoryMetadata()->getLinkField()]][$attributeCode] = $row['value'];
386+
$values[$row[$linkField]][$attributeCode] = $row['value'];
384387
}
385388
}
386389
}
387390
}
391+
388392
return $values;
389393
}
390394

395+
/**
396+
* Translate entity ids into link ids
397+
*
398+
* Used for rows with no EAV attributes set.
399+
*
400+
* @param array $entityIds
401+
* @return array
402+
*/
403+
private function getLinkIds(array $entityIds)
404+
{
405+
$linkField = $this->getCategoryMetadata()->getLinkField();
406+
if ($linkField === 'entity_id') {
407+
return $entityIds;
408+
}
409+
410+
$select = $this->connection->select()->from(
411+
['e' => $this->connection->getTableName($this->getTableName('catalog_category_entity'))],
412+
[$linkField]
413+
)->where(
414+
'e.entity_id IN (?)',
415+
$entityIds
416+
);
417+
418+
return $this->connection->fetchCol($select);
419+
}
420+
391421
/**
392422
* Return attribute values for given entities and store of specific attribute type
393423
*

app/code/Magento/Catalog/Model/Indexer/Category/Flat/Action/Full.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,22 @@ protected function populateFlatTables(array $stores)
6464
}
6565
/** @TODO Do something with chunks */
6666
$categoriesIdsChunks = array_chunk($categoriesIds[$store->getRootCategoryId()], 500);
67+
6768
foreach ($categoriesIdsChunks as $categoriesIdsChunk) {
6869
$attributesData = $this->getAttributeValues($categoriesIdsChunk, $store->getId());
70+
$linkField = $this->categoryMetadata->getLinkField();
71+
6972
$data = [];
7073
foreach ($categories[$store->getRootCategoryId()] as $category) {
71-
if (!isset($attributesData[$category[$this->categoryMetadata->getLinkField()]])) {
74+
if (!isset($attributesData[$category[$linkField]])) {
7275
continue;
7376
}
7477
$category['store_id'] = $store->getId();
7578
$data[] = $this->prepareValuesToInsert(
76-
array_merge($category, $attributesData[$category[$this->categoryMetadata->getLinkField()]])
79+
array_merge($category, $attributesData[$category[$linkField]])
7780
);
7881
}
82+
7983
$this->connection->insertMultiple(
8084
$this->addTemporaryTableSuffix($this->getMainStoreTable($store->getId())),
8185
$data

app/code/Magento/Catalog/Model/Indexer/Category/Flat/Action/Rows.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,24 @@ public function reindex(array $entityIds = [], $useTempTable = false)
6969
$categoriesIdsChunk = $this->filterIdsByStore($categoriesIdsChunk, $store);
7070

7171
$attributesData = $this->getAttributeValues($categoriesIdsChunk, $store->getId());
72+
$linkField = $this->categoryMetadata->getLinkField();
7273
$data = [];
7374
foreach ($categoriesIdsChunk as $categoryId) {
74-
if (!isset($attributesData[$categoryId])) {
75-
continue;
76-
}
77-
7875
try {
7976
$category = $this->categoryRepository->get($categoryId);
8077
} catch (NoSuchEntityException $e) {
8178
continue;
8279
}
8380

81+
$categoryData = $category->getData();
82+
if (!isset($attributesData[$categoryData[$linkField]])) {
83+
continue;
84+
}
85+
8486
$data[] = $this->prepareValuesToInsert(
8587
array_merge(
86-
$category->getData(),
87-
$attributesData[$categoryId],
88+
$categoryData,
89+
$attributesData[$categoryData[$linkField]],
8890
['store_id' => $store->getId()]
8991
)
9092
);

app/code/Magento/Catalog/Model/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ public function isInStock()
17121712
* Get attribute text by its code
17131713
*
17141714
* @param string $attributeCode Code of the attribute
1715-
* @return string
1715+
* @return string|array|null
17161716
*/
17171717
public function getAttributeText($attributeCode)
17181718
{

app/code/Magento/Catalog/Model/Product/Option/Value.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ public function getProduct()
190190
public function saveValues()
191191
{
192192
foreach ($this->getValues() as $value) {
193+
$this->isDeleted(false);
193194
$this->setData(
194195
$value
195196
)->setData(

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Catalog\Model\Product\Visibility;
1010
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface as ValidatorInterface;
1111
use Magento\Framework\App\Filesystem\DirectoryList;
12+
use Magento\Framework\Exception\LocalizedException;
1213
use Magento\Framework\Filesystem;
1314
use Magento\Framework\Model\ResourceModel\Db\ObjectRelationProcessor;
1415
use Magento\Framework\Model\ResourceModel\Db\TransactionManagerInterface;
@@ -712,7 +713,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
712713
* @param \Magento\CatalogInventory\Model\Spi\StockStateProviderInterface $stockStateProvider
713714
* @param \Magento\Catalog\Helper\Data $catalogData
714715
* @param \Magento\ImportExport\Model\Import\Config $importConfig
715-
* @param Proxy\Product\ResourceFactory $resourceFactory
716+
* @param Proxy\Product\ResourceModelFactory $resourceFactory
716717
* @param Product\OptionFactory $optionFactory
717718
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $setColFactory
718719
* @param Product\Type\Factory $productTypeFactory
@@ -1084,12 +1085,12 @@ protected function _initTypeModels()
10841085
$params = [$this, $productTypeName];
10851086
if (!($model = $this->_productTypeFactory->create($productTypeConfig['model'], ['params' => $params]))
10861087
) {
1087-
throw new \Magento\Framework\Exception\LocalizedException(
1088+
throw new LocalizedException(
10881089
__('Entity type model \'%1\' is not found', $productTypeConfig['model'])
10891090
);
10901091
}
10911092
if (!$model instanceof \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType) {
1092-
throw new \Magento\Framework\Exception\LocalizedException(
1093+
throw new LocalizedException(
10931094
__(
10941095
'Entity type model must be an instance of '
10951096
. \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType::class
@@ -1551,6 +1552,7 @@ public function getImagesFromRow(array $rowData)
15511552
* @SuppressWarnings(PHPMD.NPathComplexity)
15521553
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
15531554
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
1555+
* @throws LocalizedException
15541556
*/
15551557
protected function _saveProducts()
15561558
{
@@ -1611,7 +1613,7 @@ protected function _saveProducts()
16111613

16121614
// wrong attribute_set_code was received
16131615
if (!$attributeSetId) {
1614-
throw new \Magento\Framework\Exception\LocalizedException(
1616+
throw new LocalizedException(
16151617
__(
16161618
'Wrong attribute set code "%1", please correct it and try again.',
16171619
$rowData['attribute_set_code']
@@ -1998,7 +2000,7 @@ protected function _getUploader()
19982000
}
19992001

20002002
if (!$this->_fileUploader->setTmpDir($tmpPath)) {
2001-
throw new \Magento\Framework\Exception\LocalizedException(
2003+
throw new LocalizedException(
20022004
__('File directory \'%1\' is not readable.', $tmpPath)
20032005
);
20042006
}
@@ -2007,7 +2009,7 @@ protected function _getUploader()
20072009

20082010
$this->_mediaDirectory->create($destinationPath);
20092011
if (!$this->_fileUploader->setDestDir($destinationPath)) {
2010-
throw new \Magento\Framework\Exception\LocalizedException(
2012+
throw new LocalizedException(
20112013
__('File directory \'%1\' is not writable.', $destinationPath)
20122014
);
20132015
}
@@ -2029,6 +2031,7 @@ public function getUploader()
20292031
* Return a new file name if the same file is already exists.
20302032
*
20312033
* @param string $fileName
2034+
* @param bool $renameFileOff
20322035
* @return string
20332036
*/
20342037
protected function uploadMediaFiles($fileName, $renameFileOff = false)
@@ -2753,9 +2756,7 @@ private function _customFieldsMapping($rowData)
27532756
}
27542757

27552758
/**
2756-
* Validate data rows and save bunches to DB
2757-
*
2758-
* @return $this
2759+
* {@inheritdoc}
27592760
*/
27602761
protected function _saveValidatedBunches()
27612762
{

app/code/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ public function prepareAttributesWithDefaultValueForSave(array $rowData, $withDe
534534
public function clearEmptyData(array $rowData)
535535
{
536536
foreach ($this->_getProductAttributes($rowData) as $attrCode => $attrParams) {
537-
if (!$attrParams['is_static'] && empty($rowData[$attrCode])) {
537+
if (!$attrParams['is_static'] && !isset($rowData[$attrCode])) {
538538
unset($rowData[$attrCode]);
539539
}
540540
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogInventory\Observer;
8+
9+
use Magento\Catalog\Model\Product;
10+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
11+
use Magento\CatalogInventory\Api\StockConfigurationInterface;
12+
use Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory;
13+
use Magento\CatalogInventory\Api\StockItemRepositoryInterface;
14+
use Magento\Framework\Event\Observer;
15+
use Magento\Framework\Event\ObserverInterface;
16+
17+
/**
18+
* Add Stock items to product collection.
19+
*/
20+
class AddStockItemsObserver implements ObserverInterface
21+
{
22+
/**
23+
* @var StockItemCriteriaInterfaceFactory
24+
*/
25+
private $criteriaInterfaceFactory;
26+
27+
/**
28+
* @var StockItemRepositoryInterface
29+
*/
30+
private $stockItemRepository;
31+
32+
/**
33+
* @var StockConfigurationInterface
34+
*/
35+
private $stockConfiguration;
36+
37+
/**
38+
* AddStockItemsObserver constructor.
39+
*
40+
* @param StockItemCriteriaInterfaceFactory $criteriaInterfaceFactory
41+
* @param StockItemRepositoryInterface $stockItemRepository
42+
* @param StockConfigurationInterface $stockConfiguration
43+
*/
44+
public function __construct(
45+
StockItemCriteriaInterfaceFactory $criteriaInterfaceFactory,
46+
StockItemRepositoryInterface $stockItemRepository,
47+
StockConfigurationInterface $stockConfiguration
48+
) {
49+
$this->criteriaInterfaceFactory = $criteriaInterfaceFactory;
50+
$this->stockItemRepository = $stockItemRepository;
51+
$this->stockConfiguration = $stockConfiguration;
52+
}
53+
54+
/**
55+
* Add stock items to products in collection.
56+
*
57+
* @param Observer $observer
58+
* @return void
59+
*/
60+
public function execute(Observer $observer)
61+
{
62+
/** @var Collection $productCollection */
63+
$productCollection = $observer->getData('collection');
64+
$productIds = array_keys($productCollection->getItems());
65+
$criteria = $this->criteriaInterfaceFactory->create();
66+
$criteria->setProductsFilter($productIds);
67+
$criteria->setScopeFilter($this->stockConfiguration->getDefaultScopeId());
68+
$stockItemCollection = $this->stockItemRepository->getList($criteria);
69+
foreach ($stockItemCollection->getItems() as $item) {
70+
/** @var Product $product */
71+
$product = $productCollection->getItemById($item->getProductId());
72+
$productExtension = $product->getExtensionAttributes();
73+
$productExtension->setStockItem($item);
74+
$product->setExtensionAttributes($productExtension);
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)