Skip to content

Commit

Permalink
Merge pull request #626 from magento-troll/MAGETWO-42468
Browse files Browse the repository at this point in the history
[Merchant Beta][MX] Bugfixes
  • Loading branch information
slopukhov committed Sep 23, 2015
2 parents f45f957 + fd2ca5b commit cb271b5
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 10 deletions.
9 changes: 9 additions & 0 deletions app/code/Magento/Catalog/Model/Product/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ class Link extends \Magento\Framework\Model\AbstractModel
*/
protected $_linkCollectionFactory;

/**
* @var \Magento\CatalogInventory\Helper\Stock
*/
protected $stockHelper;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Catalog\Model\Resource\Product\Link\CollectionFactory $linkCollectionFactory
* @param \Magento\Catalog\Model\Resource\Product\Link\Product\CollectionFactory $productCollectionFactory
* @param \Magento\CatalogInventory\Helper\Stock $stockHelper
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
Expand All @@ -63,12 +69,14 @@ public function __construct(
\Magento\Framework\Registry $registry,
\Magento\Catalog\Model\Resource\Product\Link\CollectionFactory $linkCollectionFactory,
\Magento\Catalog\Model\Resource\Product\Link\Product\CollectionFactory $productCollectionFactory,
\Magento\CatalogInventory\Helper\Stock $stockHelper,
\Magento\Framework\Model\Resource\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
$this->_linkCollectionFactory = $linkCollectionFactory;
$this->_productCollectionFactory = $productCollectionFactory;
$this->stockHelper = $stockHelper;
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
}

Expand Down Expand Up @@ -128,6 +136,7 @@ public function getAttributeTypeTable($type)
public function getProductCollection()
{
$collection = $this->_productCollectionFactory->create()->setLinkModel($this);
$this->stockHelper->addInStockFilterToCollection($collection);
return $collection;
}

Expand Down
32 changes: 27 additions & 5 deletions app/code/Magento/Catalog/Test/Unit/Model/Product/LinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ class LinkTest extends \PHPUnit_Framework_TestCase
*/
protected $resource;

/**
* @var \Magento\CatalogInventory\Helper\Stock|\PHPUnit_Framework_MockObject_MockObject
*/
protected $stockHelperMock;

/**
* @var \Magento\Catalog\Model\Resource\Product\Link\Product\Collection|\PHPUnit_Framework_MockObject_MockObject
*/
protected $productCollection;

protected function setUp()
{
$linkCollection = $this->getMockBuilder(
Expand All @@ -35,20 +45,20 @@ protected function setUp()
$linkCollectionFactory->expects($this->any())
->method('create')
->will($this->returnValue($linkCollection));
$productCollection = $this->getMockBuilder(
$this->productCollection = $this->getMockBuilder(
'Magento\Catalog\Model\Resource\Product\Link\Product\Collection'
)->disableOriginalConstructor()->setMethods(
['setLinkModel']
)->getMock();
$productCollection->expects($this->any())->method('setLinkModel')->will($this->returnSelf());
$this->productCollection->expects($this->any())->method('setLinkModel')->will($this->returnSelf());
$productCollectionFactory = $this->getMockBuilder(
'Magento\Catalog\Model\Resource\Product\Link\Product\CollectionFactory'
)->disableOriginalConstructor()->setMethods(
['create']
)->getMock();
$productCollectionFactory->expects($this->any())
->method('create')
->will($this->returnValue($productCollection));
->will($this->returnValue($this->productCollection));

$this->resource = $this->getMock(
'Magento\Framework\Model\Resource\AbstractResource',
Expand All @@ -64,11 +74,19 @@ protected function setUp()
]
);

$this->stockHelperMock = $this->getMockBuilder('Magento\CatalogInventory\Helper\Stock')
->disableOriginalConstructor()
->getMock();

$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->model = $objectManager->getObject(
'Magento\Catalog\Model\Product\Link',
['linkCollectionFactory' => $linkCollectionFactory, 'productCollectionFactory' => $productCollectionFactory,
'resource' => $this->resource]
[
'linkCollectionFactory' => $linkCollectionFactory,
'productCollectionFactory' => $productCollectionFactory,
'resource' => $this->resource,
'stockHelper' => $this->stockHelperMock
]
);
}

Expand Down Expand Up @@ -110,6 +128,10 @@ public function testGetAttributeTypeTable()

public function testGetProductCollection()
{
$this->stockHelperMock
->expects($this->once())
->method('addInStockFilterToCollection')
->with($this->productCollection);
$this->assertInstanceOf(
'Magento\Catalog\Model\Resource\Product\Link\Product\Collection',
$this->model->getProductCollection()
Expand Down
2 changes: 0 additions & 2 deletions app/code/Magento/Checkout/Block/Cart/Crosssell.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ protected function _getCollection()
);
$this->_addProductAttributesAndPrices($collection);

$this->stockHelper->addInStockFilterToCollection($collection);

return $collection;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class WebapiDocBlock extends \Magento\TestFramework\Bootstrap\DocBlock
protected function _getSubscribers(\Magento\TestFramework\Application $application)
{
$subscribers = parent::_getSubscribers($application);
array_unshift($subscribers, new \Magento\TestFramework\Annotation\ApiDataFixture($this->_fixturesBaseDir));
$subscribers[] = new \Magento\TestFramework\Annotation\ApiDataFixture($this->_fixturesBaseDir);
return $subscribers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\WebapiAbstract;

/**
* @magentoAppIsolation enabled
*/
class ProductLinkManagementInterfaceTest extends WebapiAbstract
{
const SERVICE_NAME = 'catalogProductLinkManagementV1';
Expand Down Expand Up @@ -85,7 +88,7 @@ protected function assertLinkedProducts($productSku, $linkType)

/**
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual_in_stock.php
*/
public function testAssign()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
namespace Magento\Catalog\Api;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\CatalogInventory\Api\Data\StockItemInterface;
use Magento\TestFramework\TestCase\WebapiAbstract;
use Magento\Framework\Webapi\Exception as HTTPExceptionCodes;

/**
* @magentoAppIsolation enabled
*/
class ProductRepositoryInterfaceTest extends WebapiAbstract
{
const SERVICE_NAME = 'catalogProductRepositoryV1';
Expand Down Expand Up @@ -139,6 +143,9 @@ public function testProductLinks()
ProductInterface::STATUS => 1,
ProductInterface::TYPE_ID => 'simple',
ProductInterface::ATTRIBUTE_SET_ID => 4,
ProductInterface::EXTENSION_ATTRIBUTES_KEY => [
'stock_item' => $this->getStockItemData()
]
];

$this->saveProduct($productData);
Expand Down Expand Up @@ -778,4 +785,36 @@ public function testTierPrices()
$response = $this->deleteProduct($productData[ProductInterface::SKU]);
$this->assertTrue($response);
}

/**
* @return array
*/
private function getStockItemData()
{
return [
StockItemInterface::IS_IN_STOCK => 1,
StockItemInterface::QTY => 100500,
StockItemInterface::IS_QTY_DECIMAL => 1,
StockItemInterface::SHOW_DEFAULT_NOTIFICATION_MESSAGE => 0,
StockItemInterface::USE_CONFIG_MIN_QTY => 0,
StockItemInterface::USE_CONFIG_MIN_SALE_QTY => 0,
StockItemInterface::MIN_QTY => 1,
StockItemInterface::MIN_SALE_QTY => 1,
StockItemInterface::MAX_SALE_QTY => 100,
StockItemInterface::USE_CONFIG_MAX_SALE_QTY => 0,
StockItemInterface::USE_CONFIG_BACKORDERS => 0,
StockItemInterface::BACKORDERS => 0,
StockItemInterface::USE_CONFIG_NOTIFY_STOCK_QTY => 0,
StockItemInterface::NOTIFY_STOCK_QTY => 0,
StockItemInterface::USE_CONFIG_QTY_INCREMENTS => 0,
StockItemInterface::QTY_INCREMENTS => 0,
StockItemInterface::USE_CONFIG_ENABLE_QTY_INC => 0,
StockItemInterface::ENABLE_QTY_INCREMENTS => 0,
StockItemInterface::USE_CONFIG_MANAGE_STOCK => 1,
StockItemInterface::MANAGE_STOCK => 1,
StockItemInterface::LOW_STOCK_DATE => null,
StockItemInterface::IS_DECIMAL_DIVIDED => 0,
StockItemInterface::STOCK_STATUS_CHANGED_AUTO => 0,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
namespace Magento\GroupedProduct\Api;

/**
* @magentoAppIsolation enabled
*/
class ProductLinkManagementTest extends \Magento\TestFramework\TestCase\WebapiAbstract
{
const SERVICE_NAME = 'catalogProductLinkManagementV1';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\GroupedProduct\Api;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\CatalogInventory\Api\Data\StockItemInterface;
use Magento\TestFramework\TestCase\WebapiAbstract;

class ProductRepositoryInterfaceTest extends WebapiAbstract
Expand Down Expand Up @@ -126,6 +127,9 @@ public function testProductLinks()
ProductInterface::STATUS => 1,
ProductInterface::TYPE_ID => 'simple',
ProductInterface::ATTRIBUTE_SET_ID => 4,
ProductInterface::EXTENSION_ATTRIBUTES_KEY => [
'stock_item' => $this->getStockItemData()
]
];

$this->saveProduct($productData);
Expand Down Expand Up @@ -200,4 +204,36 @@ public function testProductLinks()
$this->deleteProduct("product_simple_500");
$this->deleteProduct("group_product_500");
}

/**
* @return array
*/
private function getStockItemData()
{
return [
StockItemInterface::IS_IN_STOCK => 1,
StockItemInterface::QTY => 100500,
StockItemInterface::IS_QTY_DECIMAL => 1,
StockItemInterface::SHOW_DEFAULT_NOTIFICATION_MESSAGE => 0,
StockItemInterface::USE_CONFIG_MIN_QTY => 0,
StockItemInterface::USE_CONFIG_MIN_SALE_QTY => 0,
StockItemInterface::MIN_QTY => 1,
StockItemInterface::MIN_SALE_QTY => 1,
StockItemInterface::MAX_SALE_QTY => 100,
StockItemInterface::USE_CONFIG_MAX_SALE_QTY => 0,
StockItemInterface::USE_CONFIG_BACKORDERS => 0,
StockItemInterface::BACKORDERS => 0,
StockItemInterface::USE_CONFIG_NOTIFY_STOCK_QTY => 0,
StockItemInterface::NOTIFY_STOCK_QTY => 0,
StockItemInterface::USE_CONFIG_QTY_INCREMENTS => 0,
StockItemInterface::QTY_INCREMENTS => 0,
StockItemInterface::USE_CONFIG_ENABLE_QTY_INC => 0,
StockItemInterface::ENABLE_QTY_INCREMENTS => 0,
StockItemInterface::USE_CONFIG_MANAGE_STOCK => 1,
StockItemInterface::MANAGE_STOCK => 1,
StockItemInterface::LOW_STOCK_DATE => null,
StockItemInterface::IS_DECIMAL_DIVIDED => 0,
StockItemInterface::STOCK_STATUS_CHANGED_AUTO => 0,
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

/** @var $product \Magento\Catalog\Model\Product */
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product');
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL)
->setId(21)
->setAttributeSetId(4)
->setWebsiteIds([1])
->setName('Virtual Product')
->setSku('virtual-product')
->setPrice(10)
->setTaxClassId(0)
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
->setStockData(['is_in_stock' => 1])
->save();
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

/** @var \Magento\Framework\Registry $registry */
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry');

$registry->unregister('isSecureArea');
$registry->register('isSecureArea', true);

/** @var $product \Magento\Catalog\Model\Product */
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product');
$product->load(21);
if ($product->getId()) {
$product->delete();
}

$registry->unregister('isSecureArea');
$registry->register('isSecureArea', false);
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

require realpath(__DIR__ . '/../../') . '/Catalog/_files/product_simple_duplicated.php';
require realpath(__DIR__ . '/../../') . '/Catalog/_files/product_virtual.php';
require realpath(__DIR__ . '/../../') . '/Catalog/_files/product_virtual_in_stock.php';

/** @var $product \Magento\Catalog\Model\Product */
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product');
Expand Down

0 comments on commit cb271b5

Please sign in to comment.