Skip to content

Commit

Permalink
Merge pull request #480 from magento-api/bug-fixes
Browse files Browse the repository at this point in the history
[API] Bug Fixes
  • Loading branch information
Korshenko, Oleksii(okorshenko) committed Mar 23, 2016
2 parents 4c437c3 + 231b34b commit 9f081a1
Show file tree
Hide file tree
Showing 52 changed files with 1,379 additions and 106 deletions.
18 changes: 11 additions & 7 deletions app/code/Magento/Backend/Helper/Dashboard/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ public function __construct(
}

/**
* @return \Magento\SalesRule\Model\RuleFactory
* The getter function to get the new StoreManager dependency
*
* @return \Magento\Store\Model\StoreManagerInterface
*
* @deprecated
*/
public function getStoreManager()
private function getStoreManager()
{
if ($this->_storeManager instanceof \Magento\Store\Model\StoreManagerInterface) {
$this->_storeManager = ObjectManager::getInstance()->get('\Magento\Store\Model\StoreManagerInterface');
if ($this->_storeManager === null) {
$this->_storeManager = ObjectManager::getInstance()->get('Magento\Store\Model\StoreManagerInterface');
}
return $this->_storeManager;
}

/**
Expand All @@ -57,15 +61,15 @@ protected function _initCollection()
if ($this->getParam('store')) {
$this->_collection->addFieldToFilter('store_id', $this->getParam('store'));
} elseif ($this->getParam('website')) {
$storeIds = $this->_storeManager->getWebsite($this->getParam('website'))->getStoreIds();
$storeIds = $this->getStoreManager()->getWebsite($this->getParam('website'))->getStoreIds();
$this->_collection->addFieldToFilter('store_id', ['in' => implode(',', $storeIds)]);
} elseif ($this->getParam('group')) {
$storeIds = $this->_storeManager->getGroup($this->getParam('group'))->getStoreIds();
$storeIds = $this->getStoreManager()->getGroup($this->getParam('group'))->getStoreIds();
$this->_collection->addFieldToFilter('store_id', ['in' => implode(',', $storeIds)]);
} elseif (!$this->_collection->isLive()) {
$this->_collection->addFieldToFilter(
'store_id',
['eq' => $this->_storeManager->getStore(\Magento\Store\Model\Store::ADMIN_CODE)->getId()]
['eq' => $this->getStoreManager()->getStore(\Magento\Store\Model\Store::ADMIN_CODE)->getId()]
);
}
$this->_collection->load();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ public function execute(\Magento\Framework\Event\Observer $observer)
$tags = [];
$pattern = "((^|,)%s(,|$))";
foreach ($object->getIdentities() as $tag) {
$tags[] = sprintf($pattern, preg_replace("~_\\d+$~", '', $tag));
$tags[] = sprintf($pattern, $tag);
}
$this->purgeCache->sendPurgeRequest(implode('|', array_unique($tags)));
if (!empty($tags)) {
$this->purgeCache->sendPurgeRequest(implode('|', array_unique($tags)));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function setUp()
public function testInvalidateVarnish()
{
$tags = ['cache_1', 'cache_group'];
$pattern = '((^|,)cache(,|$))|((^|,)cache_1(,|$))|((^|,)cache_group(,|$))';
$pattern = '((^|,)cache_1(,|$))|((^|,)cache_group(,|$))';

$this->configMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
$this->configMock->expects(
Expand Down
24 changes: 24 additions & 0 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
*/
protected $_productIdCached;

/**
* @var \Magento\Framework\App\State
*/
private $appState;

/**
* List of attributes in ProductInterface
* @var array
Expand Down Expand Up @@ -2263,6 +2268,9 @@ public function getIdentities()
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
}
}
if ($this->getAppState()->getAreaCode() == \Magento\Framework\App\Area::AREA_FRONTEND) {
$identities[] = self::CACHE_TAG;
}
return array_unique($identities);
}

Expand Down Expand Up @@ -2548,4 +2556,20 @@ public function setId($value)
{
return $this->setData('entity_id', $value);
}

/**
* Get application state
*
* @deprecated
* @return \Magento\Framework\App\State
*/
private function getAppState()
{
if (!$this->appState instanceof \Magento\Framework\App\State) {
$this->appState = \Magento\Framework\App\ObjectManager::getInstance()->get(
\Magento\Framework\App\State::class
);
}
return $this->appState;
}
}
13 changes: 13 additions & 0 deletions app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ class ProductTest extends \PHPUnit_Framework_TestCase
/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $mediaConfig;

/**
* @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject
*/
private $appStateMock;

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
Expand Down Expand Up @@ -365,6 +370,14 @@ protected function setUp()
]
);

$this->appStateMock = $this->getMockBuilder(\Magento\Framework\App\State::class)
->disableOriginalConstructor()
->setMethods([])
->getMock();
$modelReflection = new \ReflectionClass(get_class($this->model));
$appStateReflection = $modelReflection->getProperty('appState');
$appStateReflection->setAccessible(true);
$appStateReflection->setValue($this->model, $this->appStateMock);
}

public function testGetAttributes()
Expand Down
42 changes: 21 additions & 21 deletions app/code/Magento/Catalog/etc/webapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
<route url="/V1/products" method="GET">
<service class="Magento\Catalog\Api\ProductRepositoryInterface" method="getList"/>
<resources>
<resource ref="anonymous" />
<resource ref="Magento_Catalog::products" />
</resources>
</route>
<route url="/V1/products/:sku" method="GET">
<service class="Magento\Catalog\Api\ProductRepositoryInterface" method="get"/>
<resources>
<resource ref="anonymous" />
<resource ref="Magento_Catalog::products" />
</resources>
</route>

Expand All @@ -49,7 +49,7 @@
<route url="/V1/products/attributes/:attributeCode" method="GET">
<service class="Magento\Catalog\Api\ProductAttributeRepositoryInterface" method="get"/>
<resources>
<resource ref="anonymous" />
<resource ref="Magento_Catalog::attributes_attributes" />
</resources>
</route>
<route url="/V1/products/attributes" method="GET">
Expand Down Expand Up @@ -97,19 +97,19 @@
<route url="/V1/products/types" method="GET">
<service class="Magento\Catalog\Api\ProductTypeListInterface" method="getProductTypes"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::products"/>
</resources>
</route>
<route url="/V1/products/attribute-sets/sets/list" method="GET">
<service class="Magento\Catalog\Api\AttributeSetRepositoryInterface" method="getList"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::sets"/>
</resources>
</route>
<route url="/V1/products/attribute-sets/:attributeSetId" method="GET">
<service class="Magento\Catalog\Api\AttributeSetRepositoryInterface" method="get"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::sets"/>
</resources>
</route>
<route url="/V1/products/attribute-sets/:attributeSetId" method="DELETE">
Expand All @@ -133,7 +133,7 @@
<route url="/V1/products/attribute-sets/:attributeSetId/attributes" method="GET">
<service class="Magento\Catalog\Api\ProductAttributeManagementInterface" method="getAttributes"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::sets"/>
</resources>
</route>
<route url="/V1/products/attribute-sets/attributes" method="POST">
Expand All @@ -151,7 +151,7 @@
<route url="/V1/products/attribute-sets/groups/list" method="GET">
<service class="Magento\Catalog\Api\ProductAttributeGroupRepositoryInterface" method="getList"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::sets"/>
</resources>
</route>
<route url="/V1/products/attribute-sets/groups" method="POST">
Expand All @@ -175,7 +175,7 @@
<route url="/V1/products/attributes/:attributeCode/options" method="GET">
<service class="Magento\Catalog\Api\ProductAttributeOptionManagementInterface" method="getItems"/>
<resources>
<resource ref="anonymous" />
<resource ref="Magento_Catalog::attributes_attributes" />
</resources>
</route>
<route url="/V1/products/attributes/:attributeCode/options" method="POST">
Expand All @@ -193,13 +193,13 @@
<route url="/V1/products/media/types/:attributeSetName" method="GET">
<service class="Magento\Catalog\Api\ProductMediaAttributeManagementInterface" method="getList"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::attributes_attributes"/>
</resources>
</route>
<route url="/V1/products/:sku/media/:entryId" method="GET">
<service class="Magento\Catalog\Api\ProductAttributeMediaGalleryManagementInterface" method="get"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::attributes_attributes"/>
</resources>
</route>
<route url="/V1/products/:sku/media" method="POST">
Expand All @@ -223,15 +223,15 @@
<route url="/V1/products/:sku/media" method="GET">
<service class="Magento\Catalog\Api\ProductAttributeMediaGalleryManagementInterface" method="getList"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::catalog"/>
</resources>
</route>

<!-- Tier Price -->
<route url="/V1/products/:sku/group-prices/:customerGroupId/tiers" method="GET">
<service class="Magento\Catalog\Api\ProductTierPriceManagementInterface" method="getList"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::catalog"/>
</resources>
</route>
<route url="/V1/products/:sku/group-prices/:customerGroupId/tiers/:qty/price/:price" method="POST">
Expand All @@ -256,7 +256,7 @@
<route url="/V1/categories/:categoryId" method="GET">
<service class="Magento\Catalog\Api\CategoryRepositoryInterface" method="get" />
<resources>
<resource ref="anonymous" />
<resource ref="Magento_Catalog::categories" />
</resources>
</route>
<route url="/V1/categories" method="POST">
Expand All @@ -268,7 +268,7 @@
<route url="/V1/categories" method="GET">
<service class="Magento\Catalog\Api\CategoryManagementInterface" method="getTree" />
<resources>
<resource ref="anonymous" />
<resource ref="Magento_Catalog::categories" />
</resources>
</route>
<route url="/V1/categories/:id" method="PUT">
Expand All @@ -294,13 +294,13 @@
<route url="/V1/products/:sku/options" method="GET">
<service class="Magento\Catalog\Api\ProductCustomOptionRepositoryInterface" method="getList"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::catalog"/>
</resources>
</route>
<route url="/V1/products/:sku/options/:optionId" method="GET">
<service class="Magento\Catalog\Api\ProductCustomOptionRepositoryInterface" method="get"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::catalog"/>
</resources>
</route>
<route url="/V1/products/options" method="POST">
Expand All @@ -326,19 +326,19 @@
<route url="/V1/products/links/types" method="GET">
<service class="Magento\Catalog\Api\ProductLinkTypeListInterface" method="getItems"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::catalog"/>
</resources>
</route>
<route url="/V1/products/links/:type/attributes" method="GET">
<service class="Magento\Catalog\Api\ProductLinkTypeListInterface" method="getItemAttributes"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::catalog"/>
</resources>
</route>
<route url="/V1/products/:sku/links/:type" method="GET">
<service class="Magento\Catalog\Api\ProductLinkManagementInterface" method="getLinkedItemsByType"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::catalog"/>
</resources>
</route>
<route url="/V1/products/:sku/links" method="POST">
Expand All @@ -364,7 +364,7 @@
<route url="/V1/categories/:categoryId/products" method="GET">
<service class="Magento\Catalog\Api\CategoryLinkManagementInterface" method="getAssignedProducts" />
<resources>
<resource ref="anonymous" />
<resource ref="Magento_Catalog::categories" />
</resources>
</route>
<route url="/V1/categories/:categoryId/products" method="POST">
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogInventory/etc/webapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<route url="/V1/stockStatuses/:productSku" method="GET">
<service class="Magento\CatalogInventory\Api\StockRegistryInterface" method="getStockStatusBySku"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_CatalogInventory::cataloginventory"/>
</resources>
</route>
</routes>
4 changes: 2 additions & 2 deletions app/code/Magento/Cms/etc/webapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<route url="/V1/cmsPage/:pageId" method="GET">
<service class="Magento\Cms\Api\PageRepositoryInterface" method="getById"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Cms::page"/>
</resources>
</route>
<route url="/V1/cmsPage/search" method="GET">
Expand Down Expand Up @@ -42,7 +42,7 @@
<route url="/V1/cmsBlock/:blockId" method="GET">
<service class="Magento\Cms\Api\BlockRepositoryInterface" method="getById"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Cms::block"/>
</resources>
</route>
<route url="/V1/cmsBlock/search" method="GET">
Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/ConfigurableProduct/etc/webapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<route url="/V1/configurable-products/:sku/children" method="GET">
<service class="Magento\ConfigurableProduct\Api\LinkManagementInterface" method="getChildren"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::products"/>
</resources>
</route>
<route url="/V1/configurable-products/:sku/children/:childSku" method="DELETE">
Expand All @@ -34,13 +34,13 @@
<route url="/V1/configurable-products/:sku/options/:id" method="GET">
<service class="Magento\ConfigurableProduct\Api\OptionRepositoryInterface" method="get"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::products"/>
</resources>
</route>
<route url="/V1/configurable-products/:sku/options/all" method="GET">
<service class="Magento\ConfigurableProduct\Api\OptionRepositoryInterface" method="getList"/>
<resources>
<resource ref="anonymous"/>
<resource ref="Magento_Catalog::products"/>
</resources>
</route>
<route url="/V1/configurable-products/:sku/options" method="POST">
Expand Down
Loading

0 comments on commit 9f081a1

Please sign in to comment.