Skip to content

Commit

Permalink
Merge pull request #62 from magento-extensibility/MAGETWO-51578-remov…
Browse files Browse the repository at this point in the history
…e-cm-cache-backend-file

[Extensibility] Bug fixes
  • Loading branch information
Oleksii Korshenko committed Jun 8, 2016
2 parents ef6ad27 + 65dcda2 commit 387242c
Show file tree
Hide file tree
Showing 18 changed files with 367 additions and 1,847 deletions.
5 changes: 3 additions & 2 deletions app/code/Magento/Catalog/Block/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Catalog\Block\Product;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Product;

/**
Expand Down Expand Up @@ -55,7 +56,7 @@ class View extends AbstractProduct implements \Magento\Framework\DataObject\Iden
* @var \Magento\Customer\Model\Session
*/
protected $customerSession;

/**
* @var ProductRepositoryInterface
*/
Expand Down Expand Up @@ -371,7 +372,7 @@ public function getIdentities()
$identities = $this->getProduct()->getIdentities();
$category = $this->_coreRegistry->registry('current_category');
if ($category) {
$identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $category->getId();
$identities[] = Category::CACHE_TAG . '_' . $category->getId();
}
return $identities;
}
Expand Down
25 changes: 24 additions & 1 deletion app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -2269,17 +2269,40 @@ public function getIdentities()
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
}
}
if ($this->getOrigData('status') != $this->getData('status')) {

if (($this->getOrigData('status') != $this->getData('status')) || $this->isStockStatusChanged()) {
foreach ($this->getCategoryIds() as $categoryId) {
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
}
}
if ($this->_appState->getAreaCode() == \Magento\Framework\App\Area::AREA_FRONTEND) {
$identities[] = self::CACHE_TAG;
}

return array_unique($identities);
}

/**
* Check whether stock status changed
*
* @return bool
*/
private function isStockStatusChanged()
{
$stockItem = null;
$extendedAttributes = $this->getExtensionAttributes();
if ($extendedAttributes !== null) {
$stockItem = $extendedAttributes->getStockItem();
}
$stockData = $this->getStockData();
return (
(is_array($stockData))
&& array_key_exists('is_in_stock', $stockData)
&& (null !== $stockItem)
&& ($stockItem->getIsInStock() != $stockData['is_in_stock'])
);
}

/**
* Reload PriceInfo object
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ public function testGetIdentities()
]
)
);
$this->assertEquals(['catalog_product_1', 'catalog_category_product_1'], $this->view->getIdentities());
$this->assertEquals(['catalog_product_1', 'catalog_category_1'], $this->view->getIdentities());
}
}
63 changes: 62 additions & 1 deletion app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Magento\Catalog\Model\Product;
use Magento\Framework\Api\Data\ImageContentInterface;
use Magento\Framework\Api\ExtensibleDataInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Catalog\Model\Product\Attribute\Source\Status as Status;

Expand Down Expand Up @@ -658,6 +659,20 @@ public function testGetIdentities($expected, $origData, $data, $isDeleted = fals
*/
public function getIdentitiesProvider()
{
$extensionAttributesMock = $this->getMockBuilder(\Magento\Framework\Api\ExtensionAttributesInterface::class)
->disableOriginalConstructor()
->setMethods(['getStockItem'])
->getMock();
$stockItemMock = $this->getMockBuilder(\Magento\CatalogInventory\Api\Data\StockItemInterface::class)
->disableOriginalConstructor()
->getMock();
$extensionAttributesMock->expects($this->any())
->method('getStockItem')
->willReturn($stockItemMock);
$stockItemMock->expects($this->any())
->method('getIsInStock')
->willReturn(true);

return [
'no changes' => [
['catalog_product_1'],
Expand Down Expand Up @@ -708,7 +723,53 @@ public function getIdentitiesProvider()
[0 => 'catalog_product_1'],
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
]
],
'no stock status changes' => [
[0 => 'catalog_product_1'],
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
[
'id' => 1,
'name' => 'value',
'category_ids' => [1],
'status' => 1,
'stock_data' => ['is_in_stock' => true],
ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY => $extensionAttributesMock,
],
],
'no stock status data 1' => [
[0 => 'catalog_product_1'],
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
[
'id' => 1,
'name' => 'value',
'category_ids' => [1],
'status' => 1,
ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY => $extensionAttributesMock,
],
],
'no stock status data 2' => [
[0 => 'catalog_product_1'],
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
[
'id' => 1,
'name' => 'value',
'category_ids' => [1],
'status' => 1,
'stock_data' => ['is_in_stock' => true],
],
],
'stock status changes' => [
[0 => 'catalog_product_1', 1 => 'catalog_category_product_1'],
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
[
'id' => 1,
'name' => 'value',
'category_ids' => [1],
'status' => 1,
'stock_data' => ['is_in_stock' => false],
ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY => $extensionAttributesMock,
],
],
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Magento\CatalogInventory\Model\Indexer\Stock;

use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Product;
use Magento\Framework\App\ResourceConnection;

/**
Expand Down Expand Up @@ -65,7 +66,6 @@ abstract class AbstractAction
*/
private $eventManager;


/**
* @param ResourceConnection $resource
* @param \Magento\CatalogInventory\Model\ResourceModel\Indexer\StockFactory $indexerFactory
Expand Down Expand Up @@ -247,17 +247,10 @@ protected function _reindexRows($productIds = [])
$indexer->reindexEntity($byType[$indexer->getTypeId()]);
}
}

$select = $connection->select()
->distinct(true)
->from($this->_getTable('catalog_category_product'), ['category_id'])
->where('product_id IN(?)', $processIds);

$affectedCategories = $connection->fetchCol($select);
$this->cacheContext->registerEntities(Category::CACHE_TAG, $affectedCategories);


$this->cacheContext->registerEntities(Product::CACHE_TAG, $productIds);
$this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]);

return $this;
}

Expand Down
5 changes: 3 additions & 2 deletions app/code/Magento/Deploy/Model/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@ public function regenerateStatic(
DirectoryList::TMP_MATERIALIZATION_DIR
]
);
// Trigger static assets compilation and deployment
$this->deployStaticContent($output);

// Trigger code generation
$this->compile($output);
// Trigger static assets compilation and deployment
$this->deployStaticContent($output);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions app/code/Magento/Deploy/Test/Unit/Model/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,23 @@ public function testRegenerateStatic()
$setupDiCompileCmd = $this->cmdPrefix . 'setup:di:compile';
$this->shellMock->expects($this->at(0))
->method('execute')
->with($staticContentDeployCmd);
->with($setupDiCompileCmd);
$this->shellMock->expects($this->at(1))
->method('execute')
->with($setupDiCompileCmd);
->with($staticContentDeployCmd);

$this->outputMock->expects($this->at(0))
->method('writeln')
->with('Starting deployment of static content');
->with('Starting compilation');
$this->outputMock->expects($this->at(2))
->method('writeln')
->with('Deployment of static content complete');
->with('Compilation complete');
$this->outputMock->expects($this->at(3))
->method('writeln')
->with('Starting compilation');
->with('Starting deployment of static content');
$this->outputMock->expects($this->at(5))
->method('writeln')
->with('Compilation complete');
->with('Deployment of static content complete');

$this->filesystem->regenerateStatic($this->outputMock);
}
Expand Down
115 changes: 59 additions & 56 deletions app/code/Magento/Tax/Model/Plugin/OrderSave.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,66 +112,69 @@ protected function saveOrderTax(\Magento\Sales\Api\Data\OrderInterface $order)

foreach ($taxes as $row) {
$id = $row['id'];
foreach ($row['rates'] as $tax) {
if ($row['percent'] == null) {
$baseRealAmount = $row['base_amount'];
} else {
if ($row['percent'] == 0 || $tax['percent'] == 0) {
continue;
// @todo: should be refactored as part of MAGETWO-53366
if (isset($row['rates'])) {
foreach ($row['rates'] as $tax) {
if ($row['percent'] == null) {
$baseRealAmount = $row['base_amount'];
} else {
if ($row['percent'] == 0 || $tax['percent'] == 0) {
continue;
}
$baseRealAmount = $row['base_amount'] / $row['percent'] * $tax['percent'];
}
$baseRealAmount = $row['base_amount'] / $row['percent'] * $tax['percent'];
}
$hidden = isset($row['hidden']) ? $row['hidden'] : 0;
$priority = isset($tax['priority']) ? $tax['priority'] : 0;
$position = isset($tax['position']) ? $tax['position'] : 0;
$process = isset($row['process']) ? $row['process'] : 0;
$data = [
'order_id' => $order->getEntityId(),
'code' => $tax['code'],
'title' => $tax['title'],
'hidden' => $hidden,
'percent' => $tax['percent'],
'priority' => $priority,
'position' => $position,
'amount' => $row['amount'],
'base_amount' => $row['base_amount'],
'process' => $process,
'base_real_amount' => $baseRealAmount,
];
$hidden = isset($row['hidden']) ? $row['hidden'] : 0;
$priority = isset($tax['priority']) ? $tax['priority'] : 0;
$position = isset($tax['position']) ? $tax['position'] : 0;
$process = isset($row['process']) ? $row['process'] : 0;
$data = [
'order_id' => $order->getEntityId(),
'code' => $tax['code'],
'title' => $tax['title'],
'hidden' => $hidden,
'percent' => $tax['percent'],
'priority' => $priority,
'position' => $position,
'amount' => $row['amount'],
'base_amount' => $row['base_amount'],
'process' => $process,
'base_real_amount' => $baseRealAmount,
];

/** @var $orderTax \Magento\Tax\Model\Sales\Order\Tax */
$orderTax = $this->orderTaxFactory->create();
$result = $orderTax->setData($data)->save();
/** @var $orderTax \Magento\Tax\Model\Sales\Order\Tax */
$orderTax = $this->orderTaxFactory->create();
$result = $orderTax->setData($data)->save();

if (isset($ratesIdQuoteItemId[$id])) {
foreach ($ratesIdQuoteItemId[$id] as $quoteItemId) {
if ($quoteItemId['code'] == $tax['code']) {
$itemId = null;
$associatedItemId = null;
if (isset($quoteItemId['id'])) {
//This is a product item
$item = $order->getItemByQuoteItemId($quoteItemId['id']);
$itemId = $item->getId();
} elseif (isset($quoteItemId['associated_item_id'])) {
//This item is associated with a product item
$item = $order->getItemByQuoteItemId($quoteItemId['associated_item_id']);
$associatedItemId = $item->getId();
}
if (isset($ratesIdQuoteItemId[$id])) {
foreach ($ratesIdQuoteItemId[$id] as $quoteItemId) {
if ($quoteItemId['code'] == $tax['code']) {
$itemId = null;
$associatedItemId = null;
if (isset($quoteItemId['id'])) {
//This is a product item
$item = $order->getItemByQuoteItemId($quoteItemId['id']);
$itemId = $item->getId();
} elseif (isset($quoteItemId['associated_item_id'])) {
//This item is associated with a product item
$item = $order->getItemByQuoteItemId($quoteItemId['associated_item_id']);
$associatedItemId = $item->getId();
}

$data = [
'item_id' => $itemId,
'tax_id' => $result->getTaxId(),
'tax_percent' => $quoteItemId['percent'],
'associated_item_id' => $associatedItemId,
'amount' => $quoteItemId['amount'],
'base_amount' => $quoteItemId['base_amount'],
'real_amount' => $quoteItemId['real_amount'],
'real_base_amount' => $quoteItemId['real_base_amount'],
'taxable_item_type' => $quoteItemId['item_type'],
];
/** @var $taxItem \Magento\Sales\Model\Order\Tax\Item */
$taxItem = $this->taxItemFactory->create();
$taxItem->setData($data)->save();
$data = [
'item_id' => $itemId,
'tax_id' => $result->getTaxId(),
'tax_percent' => $quoteItemId['percent'],
'associated_item_id' => $associatedItemId,
'amount' => $quoteItemId['amount'],
'base_amount' => $quoteItemId['base_amount'],
'real_amount' => $quoteItemId['real_amount'],
'real_base_amount' => $quoteItemId['real_base_amount'],
'taxable_item_type' => $quoteItemId['item_type'],
];
/** @var $taxItem \Magento\Sales\Model\Order\Tax\Item */
$taxItem = $this->taxItemFactory->create();
$taxItem->setData($data)->save();
}
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"magento/zendframework1": "1.12.16",
"colinmollenhour/credis": "1.6",
"colinmollenhour/php-redis-session-abstract": "1.1",
"colinmollenhour/cache-backend-redis": "1.9",
"colinmollenhour/cache-backend-file": "1.4",
"composer/composer": "1.0.0-beta1",
"monolog/monolog": "1.16.0",
"oyejorge/less.php": "~1.7.0",
Expand Down Expand Up @@ -188,17 +190,16 @@
"magento/language-zh_hans_cn": "100.1.0-rc2",
"magento/framework": "100.1.0-rc2",
"trentrichardson/jquery-timepicker-addon": "1.4.3",
"colinmollenhour/cache-backend-redis": "1.8",
"components/jquery": "1.11.0",
"blueimp/jquery-file-upload": "5.6.14",
"components/jqueryui": "1.10.4",
"twbs/bootstrap": "3.1.0",
"tinymce/tinymce": "3.4.7"
"tinymce/tinymce": "3.4.7",
"magento-hackathon/magento-composer-installer": "*"
},
"extra": {
"component_paths": {
"trentrichardson/jquery-timepicker-addon": "lib/web/jquery/jquery-ui-timepicker-addon.js",
"colinmollenhour/cache-backend-redis": "lib/internal/Cm/Cache/Backend/Redis.php",
"components/jquery": [
"lib/web/jquery.js",
"lib/web/jquery/jquery.min.js",
Expand Down
Loading

0 comments on commit 387242c

Please sign in to comment.