Skip to content

Commit

Permalink
Merge pull request magento#147 from magento-troll/troll_p2
Browse files Browse the repository at this point in the history
[Troll] bugfixes p2
  • Loading branch information
rganin authored Jul 13, 2016
2 parents c20c8e9 + 77ad0b4 commit 71c58ad
Show file tree
Hide file tree
Showing 28 changed files with 454 additions and 55 deletions.
5 changes: 3 additions & 2 deletions app/code/Magento/Catalog/Block/Adminhtml/Product/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ protected function _getStore()
*/
protected function _prepareCollection()
{
parent::_prepareCollection();

$store = $this->_getStore();
$collection = $this->_productFactory->create()->getCollection()->addAttributeToSelect(
'sku'
Expand Down Expand Up @@ -184,6 +182,9 @@ protected function _prepareCollection()
$this->setCollection($collection);

$this->getCollection()->addWebsiteNamesToResult();

parent::_prepareCollection();

return $this;
}

Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/Catalog/Block/Product/View/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ public function getGalleryImagesJson()
}
if (empty($imagesItems)) {
$imagesItems[] = [
'thumb' => $this->_imageHelper->getDefaultPlaceholderUrl('thumbnail'),
'img' => $this->_imageHelper->getDefaultPlaceholderUrl('image'),
'full' => $this->_imageHelper->getDefaultPlaceholderUrl('image'),
'thumb' => $this->getImage($this->getProduct(), 'product_thumbnail_image')->getImageUrl(),
'img' => $this->getImage($this->getProduct(), 'product_base_image')->getImageUrl(),
'full' => $this->getImage($this->getProduct(), 'product_page_image_large')->getImageUrl(),
'caption' => '',
'position' => '0',
'isMain' => true,
Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/Catalog/Helper/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ public function placeholder($fileName)
*
* @param null|string $placeholder
* @return string
*
* @deprecated Returns only default placeholder.
* Does not take into account custom placeholders set in Configuration.
*/
public function getPlaceholder($placeholder = null)
{
Expand Down Expand Up @@ -544,6 +547,9 @@ public function getResizedImageInfo()
/**
* @param null|string $placeholder
* @return string
*
* @deprecated Returns only default placeholder.
* Does not take into account custom placeholders set in Configuration.
*/
public function getDefaultPlaceholderUrl($placeholder = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,27 @@ public function afterSave()
{
if ($this->isValueChanged()) {
$this->updateSuffixForUrlRewrites();
if ($this->isCategorySuffixChanged()) {
$this->cacheTypeList->invalidate([
\Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER,
\Magento\Framework\App\Cache\Type\Collection::TYPE_IDENTIFIER
]);
}
}
return parent::afterSave();
}

/**
* Check is category suffix changed
*
* @return bool
*/
private function isCategorySuffixChanged()
{
return $this->isValueChanged()
&& ($this->getPath() == CategoryUrlPathGenerator::XML_PATH_CATEGORY_URL_SUFFIX);
}

/**
* Update suffix for url rewrites
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Test\Unit\Model\System\Config\Backend\Catalog\Url\Rewrite;

class SuffixTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Framework\Model\Context
*/
protected $context;

/**
* @var \Magento\Framework\Event\ManagerInterface
*/
protected $eventDispatcher;

/**
* @var \Magento\Framework\Registry
*/
protected $registry;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $config;

/**
* @var \Magento\Framework\App\Cache\TypeListInterface
*/
protected $cacheTypeList;

/**
* @var \Magento\UrlRewrite\Helper\UrlRewrite
*/
protected $urlRewriteHelper;

/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;

/**
* @var \Magento\Framework\App\ResourceConnection
*/
protected $appResource;

/**
* @var \Magento\UrlRewrite\Model\UrlFinderInterface
*/
protected $urlFinder;

/**
* @var \Magento\Catalog\Model\System\Config\Backend\Catalog\Url\Rewrite\Suffix
*/
protected $suffixModel;

public function setUp()
{
$this->eventDispatcher = $this->getMockBuilder('\Magento\Framework\Event\ManagerInterface')
->disableOriginalConstructor()
->setMethods(['dispatch'])
->getMock();
$this->eventDispatcher->method('dispatch')->willReturnSelf();
$this->context = $this->getMockBuilder('\Magento\Framework\Model\Context')
->disableOriginalConstructor()
->setMethods(['getEventDispatcher'])
->getMock();
$this->context->method('getEventDispatcher')->willReturn($this->eventDispatcher);

$this->registry = $this->getMock('\Magento\Framework\Registry');
$this->config = $this->getMock('\Magento\Framework\App\Config\ScopeConfigInterface');
$this->cacheTypeList = $this->getMockBuilder('\Magento\Framework\App\Cache\TypeList')
->disableOriginalConstructor()
->setMethods(['invalidate'])
->getMock();

$this->urlRewriteHelper = $this->getMockBuilder('\Magento\UrlRewrite\Helper\UrlRewrite')
->disableOriginalConstructor()
->getMock();
$this->storeManager = $this->getMockBuilder('\Magento\Store\Model\StoreManager')
->disableOriginalConstructor()
->setMethods(['getStores'])
->getMock();
$this->storeManager->method('getStores')->willReturn([]);

$this->appResource =$this->getMockBuilder('\Magento\Framework\App\ResourceConnection')
->disableOriginalConstructor()
->getMock();
$this->urlFinder =$this->getMockBuilder('\Magento\UrlRewrite\Model\UrlFinderInterface')
->setMethods(['findAllByData', 'findOneByData'])
->getMock();
$this->urlFinder->method('findAllByData')->willReturn([]);

$this->suffixModel = new \Magento\Catalog\Model\System\Config\Backend\Catalog\Url\Rewrite\Suffix(
$this->context,
$this->registry,
$this->config,
$this->cacheTypeList,
$this->urlRewriteHelper,
$this->storeManager,
$this->appResource,
$this->urlFinder
);
}

public function testAfterSaveCleanCache()
{
$this->suffixModel->setValue('new');
$this->suffixModel->setPath(\Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator::XML_PATH_CATEGORY_URL_SUFFIX);
$this->cacheTypeList->expects($this->exactly(2))->method('invalidate')->withConsecutive(
[$this->equalTo([
\Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER,
\Magento\Framework\App\Cache\Type\Collection::TYPE_IDENTIFIER
])],
[$this->equalTo('config')]
);
$this->suffixModel->afterSave();
}

public function testAfterSaveWithoutChanges()
{
$this->suffixModel->setValue('');
$this->suffixModel->setPath(\Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator::XML_PATH_CATEGORY_URL_SUFFIX);
$this->cacheTypeList->expects($this->never())->method('invalidate');
$this->suffixModel->afterSave();
}

public function testAfterSaveProduct()
{
$this->suffixModel->setValue('new');
$this->suffixModel->setPath(\Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator::XML_PATH_PRODUCT_URL_SUFFIX);
$this->cacheTypeList->expects($this->once())->method('invalidate')->with('config');
$this->suffixModel->afterSave();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ protected function getTierPriceStructure($tierPricePath)
'dataType' => Number::NAME,
'label' => __('Quantity'),
'dataScope' => 'price_qty',
'validation' => [
'required-entry' => true,
'validate-greater-than-zero' => true,
'validate-digits' => true,
],
],
],
],
Expand All @@ -497,6 +502,11 @@ protected function getTierPriceStructure($tierPricePath)
'addbefore' => $this->locator->getStore()
->getBaseCurrency()
->getCurrencySymbol(),
'validation' => [
'required-entry' => true,
'validate-greater-than-zero' => true,
'validate-number' => true,
],
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
</item>
<item name="template" xsi:type="string">ui/form/field</item>
<item name="source" xsi:type="string">category</item>
<item name="label" xsi:type="string" translate="true">Description</item>
<item name="wysiwyg" xsi:type="boolean">true</item>
<item name="dataScope" xsi:type="string">description</item>
<item name="sortOrder" xsi:type="number">50</item>
Expand Down Expand Up @@ -217,6 +218,7 @@
<item name="sortOrder" xsi:type="number">70</item>
<item name="dataType" xsi:type="string">string</item>
<item name="formElement" xsi:type="string">select</item>
<item name="label" xsi:type="string" translate="true">Display Mode</item>
</item>
</argument>
</field>
Expand Down Expand Up @@ -244,7 +246,6 @@
<item name="component" xsi:type="string">Magento_Ui/js/form/components/group</item>
<item name="required" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">90</item>
<item name="label" xsi:type="string" translate="true">Sort Products By</item>
</item>
</argument>
<field name="available_sort_by">
Expand All @@ -253,6 +254,7 @@
<item name="additionalClasses" xsi:type="string">admin__field-default</item>
<item name="formElement" xsi:type="string">multiselect</item>
<item name="source" xsi:type="string">category</item>
<item name="label" xsi:type="string" translate="true">Available Product Listing Sort By</item>
</item>
</argument>
</field>
Expand All @@ -279,7 +281,6 @@
<item name="config" xsi:type="array">
<item name="breakLine" xsi:type="boolean">true</item>
<item name="component" xsi:type="string">Magento_Ui/js/form/components/group</item>
<item name="label" xsi:type="string" translate="true">Default Product Sorting</item>
<item name="required" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">100</item>
</item>
Expand All @@ -290,6 +291,7 @@
<item name="additionalClasses" xsi:type="string">admin__field-default</item>
<item name="formElement" xsi:type="string">select</item>
<item name="source" xsi:type="string">category</item>
<item name="label" xsi:type="string" translate="true">Default Product Listing Sort By</item>
</item>
</argument>
</field>
Expand All @@ -316,7 +318,6 @@
<item name="config" xsi:type="array">
<item name="breakLine" xsi:type="boolean">true</item>
<item name="component" xsi:type="string">Magento_Ui/js/form/components/group</item>
<item name="label" xsi:type="string" translate="true">Layered Navigation Price Step</item>
<item name="required" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">110</item>
</item>
Expand All @@ -327,6 +328,7 @@
<item name="additionalClasses" xsi:type="string">admin__field-small</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">category</item>
<item name="label" xsi:type="string" translate="true">Layered Navigation Price Step</item>
<item name="addbefore" xsi:type="string">$</item>
</item>
</argument>
Expand Down Expand Up @@ -362,7 +364,6 @@
<item name="type" xsi:type="string">group</item>
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/components/group</item>
<item name="label" xsi:type="string" translate="true">URL Key</item>
<item name="required" xsi:type="boolean">false</item>
<item name="sortOrder" xsi:type="number">120</item>
</item>
Expand All @@ -372,6 +373,7 @@
<item name="config" xsi:type="array">
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">category</item>
<item name="label" xsi:type="string" translate="true">URL Key</item>
<item name="sortOrder" xsi:type="number">10</item>
<item name="imports" xsi:type="array">
<item name="disabled" xsi:type="string">${ $.provider }:data.use_default.url_key</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ $_helper = $this->helper('Magento\Catalog\Helper\Output');
</button>
</form>
<?php else: ?>
<?php if ($_product->getIsSalable()): ?>
<?php if ($_product->isAvailable()): ?>
<div class="stock available"><span><?php /* @escapeNotVerified */ echo __('In stock') ?></span></div>
<?php else: ?>
<div class="stock unavailable"><span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span></div>
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogInventory/Model/Stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Stock extends AbstractExtensibleModel implements StockInterface
*
* @var string
*/
protected $eventPrefix = 'cataloginventory_stock';
protected $_eventPrefix = 'cataloginventory_stock';

/**
* Parameter name in event
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogInventory/Model/Stock/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Item extends AbstractExtensibleModel implements StockItemInterface
*
* @var string
*/
protected $eventPrefix = 'cataloginventory_stock_item';
protected $_eventPrefix = 'cataloginventory_stock_item';

const WEBSITE_ID = 'website_id';

Expand Down
Loading

0 comments on commit 71c58ad

Please sign in to comment.