Skip to content

Commit 387242c

Browse files
author
Oleksii Korshenko
committed
Merge pull request #62 from magento-extensibility/MAGETWO-51578-remove-cm-cache-backend-file
[Extensibility] Bug fixes
2 parents ef6ad27 + 65dcda2 commit 387242c

File tree

18 files changed

+367
-1847
lines changed

18 files changed

+367
-1847
lines changed

app/code/Magento/Catalog/Block/Product/View.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Catalog\Block\Product;
77

88
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Catalog\Model\Category;
910
use Magento\Catalog\Model\Product;
1011

1112
/**
@@ -55,7 +56,7 @@ class View extends AbstractProduct implements \Magento\Framework\DataObject\Iden
5556
* @var \Magento\Customer\Model\Session
5657
*/
5758
protected $customerSession;
58-
59+
5960
/**
6061
* @var ProductRepositoryInterface
6162
*/
@@ -371,7 +372,7 @@ public function getIdentities()
371372
$identities = $this->getProduct()->getIdentities();
372373
$category = $this->_coreRegistry->registry('current_category');
373374
if ($category) {
374-
$identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $category->getId();
375+
$identities[] = Category::CACHE_TAG . '_' . $category->getId();
375376
}
376377
return $identities;
377378
}

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2269,17 +2269,40 @@ public function getIdentities()
22692269
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
22702270
}
22712271
}
2272-
if ($this->getOrigData('status') != $this->getData('status')) {
2272+
2273+
if (($this->getOrigData('status') != $this->getData('status')) || $this->isStockStatusChanged()) {
22732274
foreach ($this->getCategoryIds() as $categoryId) {
22742275
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
22752276
}
22762277
}
22772278
if ($this->_appState->getAreaCode() == \Magento\Framework\App\Area::AREA_FRONTEND) {
22782279
$identities[] = self::CACHE_TAG;
22792280
}
2281+
22802282
return array_unique($identities);
22812283
}
22822284

2285+
/**
2286+
* Check whether stock status changed
2287+
*
2288+
* @return bool
2289+
*/
2290+
private function isStockStatusChanged()
2291+
{
2292+
$stockItem = null;
2293+
$extendedAttributes = $this->getExtensionAttributes();
2294+
if ($extendedAttributes !== null) {
2295+
$stockItem = $extendedAttributes->getStockItem();
2296+
}
2297+
$stockData = $this->getStockData();
2298+
return (
2299+
(is_array($stockData))
2300+
&& array_key_exists('is_in_stock', $stockData)
2301+
&& (null !== $stockItem)
2302+
&& ($stockItem->getIsInStock() != $stockData['is_in_stock'])
2303+
);
2304+
}
2305+
22832306
/**
22842307
* Reload PriceInfo object
22852308
*

app/code/Magento/Catalog/Test/Unit/Block/Product/ViewTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ public function testGetIdentities()
8484
]
8585
)
8686
);
87-
$this->assertEquals(['catalog_product_1', 'catalog_category_product_1'], $this->view->getIdentities());
87+
$this->assertEquals(['catalog_product_1', 'catalog_category_1'], $this->view->getIdentities());
8888
}
8989
}

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Magento\Catalog\Model\Product;
1212
use Magento\Framework\Api\Data\ImageContentInterface;
13+
use Magento\Framework\Api\ExtensibleDataInterface;
1314
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1415
use Magento\Catalog\Model\Product\Attribute\Source\Status as Status;
1516

@@ -658,6 +659,20 @@ public function testGetIdentities($expected, $origData, $data, $isDeleted = fals
658659
*/
659660
public function getIdentitiesProvider()
660661
{
662+
$extensionAttributesMock = $this->getMockBuilder(\Magento\Framework\Api\ExtensionAttributesInterface::class)
663+
->disableOriginalConstructor()
664+
->setMethods(['getStockItem'])
665+
->getMock();
666+
$stockItemMock = $this->getMockBuilder(\Magento\CatalogInventory\Api\Data\StockItemInterface::class)
667+
->disableOriginalConstructor()
668+
->getMock();
669+
$extensionAttributesMock->expects($this->any())
670+
->method('getStockItem')
671+
->willReturn($stockItemMock);
672+
$stockItemMock->expects($this->any())
673+
->method('getIsInStock')
674+
->willReturn(true);
675+
661676
return [
662677
'no changes' => [
663678
['catalog_product_1'],
@@ -708,7 +723,53 @@ public function getIdentitiesProvider()
708723
[0 => 'catalog_product_1'],
709724
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
710725
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
711-
]
726+
],
727+
'no stock status changes' => [
728+
[0 => 'catalog_product_1'],
729+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
730+
[
731+
'id' => 1,
732+
'name' => 'value',
733+
'category_ids' => [1],
734+
'status' => 1,
735+
'stock_data' => ['is_in_stock' => true],
736+
ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY => $extensionAttributesMock,
737+
],
738+
],
739+
'no stock status data 1' => [
740+
[0 => 'catalog_product_1'],
741+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
742+
[
743+
'id' => 1,
744+
'name' => 'value',
745+
'category_ids' => [1],
746+
'status' => 1,
747+
ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY => $extensionAttributesMock,
748+
],
749+
],
750+
'no stock status data 2' => [
751+
[0 => 'catalog_product_1'],
752+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
753+
[
754+
'id' => 1,
755+
'name' => 'value',
756+
'category_ids' => [1],
757+
'status' => 1,
758+
'stock_data' => ['is_in_stock' => true],
759+
],
760+
],
761+
'stock status changes' => [
762+
[0 => 'catalog_product_1', 1 => 'catalog_category_product_1'],
763+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
764+
[
765+
'id' => 1,
766+
'name' => 'value',
767+
'category_ids' => [1],
768+
'status' => 1,
769+
'stock_data' => ['is_in_stock' => false],
770+
ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY => $extensionAttributesMock,
771+
],
772+
],
712773
];
713774
}
714775

app/code/Magento/CatalogInventory/Model/Indexer/Stock/AbstractAction.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Magento\CatalogInventory\Model\Indexer\Stock;
1010

1111
use Magento\Catalog\Model\Category;
12+
use Magento\Catalog\Model\Product;
1213
use Magento\Framework\App\ResourceConnection;
1314

1415
/**
@@ -65,7 +66,6 @@ abstract class AbstractAction
6566
*/
6667
private $eventManager;
6768

68-
6969
/**
7070
* @param ResourceConnection $resource
7171
* @param \Magento\CatalogInventory\Model\ResourceModel\Indexer\StockFactory $indexerFactory
@@ -247,17 +247,10 @@ protected function _reindexRows($productIds = [])
247247
$indexer->reindexEntity($byType[$indexer->getTypeId()]);
248248
}
249249
}
250-
251-
$select = $connection->select()
252-
->distinct(true)
253-
->from($this->_getTable('catalog_category_product'), ['category_id'])
254-
->where('product_id IN(?)', $processIds);
255-
256-
$affectedCategories = $connection->fetchCol($select);
257-
$this->cacheContext->registerEntities(Category::CACHE_TAG, $affectedCategories);
258-
250+
251+
$this->cacheContext->registerEntities(Product::CACHE_TAG, $productIds);
259252
$this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]);
260-
253+
261254
return $this;
262255
}
263256

app/code/Magento/Deploy/Model/Filesystem.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ public function regenerateStatic(
138138
DirectoryList::TMP_MATERIALIZATION_DIR
139139
]
140140
);
141-
// Trigger static assets compilation and deployment
142-
$this->deployStaticContent($output);
141+
143142
// Trigger code generation
144143
$this->compile($output);
144+
// Trigger static assets compilation and deployment
145+
$this->deployStaticContent($output);
145146
}
146147

147148
/**

app/code/Magento/Deploy/Test/Unit/Model/FilesystemTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,23 +153,23 @@ public function testRegenerateStatic()
153153
$setupDiCompileCmd = $this->cmdPrefix . 'setup:di:compile';
154154
$this->shellMock->expects($this->at(0))
155155
->method('execute')
156-
->with($staticContentDeployCmd);
156+
->with($setupDiCompileCmd);
157157
$this->shellMock->expects($this->at(1))
158158
->method('execute')
159-
->with($setupDiCompileCmd);
159+
->with($staticContentDeployCmd);
160160

161161
$this->outputMock->expects($this->at(0))
162162
->method('writeln')
163-
->with('Starting deployment of static content');
163+
->with('Starting compilation');
164164
$this->outputMock->expects($this->at(2))
165165
->method('writeln')
166-
->with('Deployment of static content complete');
166+
->with('Compilation complete');
167167
$this->outputMock->expects($this->at(3))
168168
->method('writeln')
169-
->with('Starting compilation');
169+
->with('Starting deployment of static content');
170170
$this->outputMock->expects($this->at(5))
171171
->method('writeln')
172-
->with('Compilation complete');
172+
->with('Deployment of static content complete');
173173

174174
$this->filesystem->regenerateStatic($this->outputMock);
175175
}

app/code/Magento/Tax/Model/Plugin/OrderSave.php

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -112,66 +112,69 @@ protected function saveOrderTax(\Magento\Sales\Api\Data\OrderInterface $order)
112112

113113
foreach ($taxes as $row) {
114114
$id = $row['id'];
115-
foreach ($row['rates'] as $tax) {
116-
if ($row['percent'] == null) {
117-
$baseRealAmount = $row['base_amount'];
118-
} else {
119-
if ($row['percent'] == 0 || $tax['percent'] == 0) {
120-
continue;
115+
// @todo: should be refactored as part of MAGETWO-53366
116+
if (isset($row['rates'])) {
117+
foreach ($row['rates'] as $tax) {
118+
if ($row['percent'] == null) {
119+
$baseRealAmount = $row['base_amount'];
120+
} else {
121+
if ($row['percent'] == 0 || $tax['percent'] == 0) {
122+
continue;
123+
}
124+
$baseRealAmount = $row['base_amount'] / $row['percent'] * $tax['percent'];
121125
}
122-
$baseRealAmount = $row['base_amount'] / $row['percent'] * $tax['percent'];
123-
}
124-
$hidden = isset($row['hidden']) ? $row['hidden'] : 0;
125-
$priority = isset($tax['priority']) ? $tax['priority'] : 0;
126-
$position = isset($tax['position']) ? $tax['position'] : 0;
127-
$process = isset($row['process']) ? $row['process'] : 0;
128-
$data = [
129-
'order_id' => $order->getEntityId(),
130-
'code' => $tax['code'],
131-
'title' => $tax['title'],
132-
'hidden' => $hidden,
133-
'percent' => $tax['percent'],
134-
'priority' => $priority,
135-
'position' => $position,
136-
'amount' => $row['amount'],
137-
'base_amount' => $row['base_amount'],
138-
'process' => $process,
139-
'base_real_amount' => $baseRealAmount,
140-
];
126+
$hidden = isset($row['hidden']) ? $row['hidden'] : 0;
127+
$priority = isset($tax['priority']) ? $tax['priority'] : 0;
128+
$position = isset($tax['position']) ? $tax['position'] : 0;
129+
$process = isset($row['process']) ? $row['process'] : 0;
130+
$data = [
131+
'order_id' => $order->getEntityId(),
132+
'code' => $tax['code'],
133+
'title' => $tax['title'],
134+
'hidden' => $hidden,
135+
'percent' => $tax['percent'],
136+
'priority' => $priority,
137+
'position' => $position,
138+
'amount' => $row['amount'],
139+
'base_amount' => $row['base_amount'],
140+
'process' => $process,
141+
'base_real_amount' => $baseRealAmount,
142+
];
141143

142-
/** @var $orderTax \Magento\Tax\Model\Sales\Order\Tax */
143-
$orderTax = $this->orderTaxFactory->create();
144-
$result = $orderTax->setData($data)->save();
144+
/** @var $orderTax \Magento\Tax\Model\Sales\Order\Tax */
145+
$orderTax = $this->orderTaxFactory->create();
146+
$result = $orderTax->setData($data)->save();
145147

146-
if (isset($ratesIdQuoteItemId[$id])) {
147-
foreach ($ratesIdQuoteItemId[$id] as $quoteItemId) {
148-
if ($quoteItemId['code'] == $tax['code']) {
149-
$itemId = null;
150-
$associatedItemId = null;
151-
if (isset($quoteItemId['id'])) {
152-
//This is a product item
153-
$item = $order->getItemByQuoteItemId($quoteItemId['id']);
154-
$itemId = $item->getId();
155-
} elseif (isset($quoteItemId['associated_item_id'])) {
156-
//This item is associated with a product item
157-
$item = $order->getItemByQuoteItemId($quoteItemId['associated_item_id']);
158-
$associatedItemId = $item->getId();
159-
}
148+
if (isset($ratesIdQuoteItemId[$id])) {
149+
foreach ($ratesIdQuoteItemId[$id] as $quoteItemId) {
150+
if ($quoteItemId['code'] == $tax['code']) {
151+
$itemId = null;
152+
$associatedItemId = null;
153+
if (isset($quoteItemId['id'])) {
154+
//This is a product item
155+
$item = $order->getItemByQuoteItemId($quoteItemId['id']);
156+
$itemId = $item->getId();
157+
} elseif (isset($quoteItemId['associated_item_id'])) {
158+
//This item is associated with a product item
159+
$item = $order->getItemByQuoteItemId($quoteItemId['associated_item_id']);
160+
$associatedItemId = $item->getId();
161+
}
160162

161-
$data = [
162-
'item_id' => $itemId,
163-
'tax_id' => $result->getTaxId(),
164-
'tax_percent' => $quoteItemId['percent'],
165-
'associated_item_id' => $associatedItemId,
166-
'amount' => $quoteItemId['amount'],
167-
'base_amount' => $quoteItemId['base_amount'],
168-
'real_amount' => $quoteItemId['real_amount'],
169-
'real_base_amount' => $quoteItemId['real_base_amount'],
170-
'taxable_item_type' => $quoteItemId['item_type'],
171-
];
172-
/** @var $taxItem \Magento\Sales\Model\Order\Tax\Item */
173-
$taxItem = $this->taxItemFactory->create();
174-
$taxItem->setData($data)->save();
163+
$data = [
164+
'item_id' => $itemId,
165+
'tax_id' => $result->getTaxId(),
166+
'tax_percent' => $quoteItemId['percent'],
167+
'associated_item_id' => $associatedItemId,
168+
'amount' => $quoteItemId['amount'],
169+
'base_amount' => $quoteItemId['base_amount'],
170+
'real_amount' => $quoteItemId['real_amount'],
171+
'real_base_amount' => $quoteItemId['real_base_amount'],
172+
'taxable_item_type' => $quoteItemId['item_type'],
173+
];
174+
/** @var $taxItem \Magento\Sales\Model\Order\Tax\Item */
175+
$taxItem = $this->taxItemFactory->create();
176+
$taxItem->setData($data)->save();
177+
}
175178
}
176179
}
177180
}

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
"magento/zendframework1": "1.12.16",
3535
"colinmollenhour/credis": "1.6",
3636
"colinmollenhour/php-redis-session-abstract": "1.1",
37+
"colinmollenhour/cache-backend-redis": "1.9",
38+
"colinmollenhour/cache-backend-file": "1.4",
3739
"composer/composer": "1.0.0-beta1",
3840
"monolog/monolog": "1.16.0",
3941
"oyejorge/less.php": "~1.7.0",
@@ -188,17 +190,16 @@
188190
"magento/language-zh_hans_cn": "100.1.0-rc2",
189191
"magento/framework": "100.1.0-rc2",
190192
"trentrichardson/jquery-timepicker-addon": "1.4.3",
191-
"colinmollenhour/cache-backend-redis": "1.8",
192193
"components/jquery": "1.11.0",
193194
"blueimp/jquery-file-upload": "5.6.14",
194195
"components/jqueryui": "1.10.4",
195196
"twbs/bootstrap": "3.1.0",
196-
"tinymce/tinymce": "3.4.7"
197+
"tinymce/tinymce": "3.4.7",
198+
"magento-hackathon/magento-composer-installer": "*"
197199
},
198200
"extra": {
199201
"component_paths": {
200202
"trentrichardson/jquery-timepicker-addon": "lib/web/jquery/jquery-ui-timepicker-addon.js",
201-
"colinmollenhour/cache-backend-redis": "lib/internal/Cm/Cache/Backend/Redis.php",
202203
"components/jquery": [
203204
"lib/web/jquery.js",
204205
"lib/web/jquery/jquery.min.js",

0 commit comments

Comments
 (0)