Skip to content

Commit 5744ef3

Browse files
author
Tang, Yu(ytang1)
committed
Merge pull request #100 from magento-dragons/BugFestW5
[Dragons] Bug fixes
2 parents c743dec + 9fa35aa commit 5744ef3

File tree

27 files changed

+457
-170
lines changed

27 files changed

+457
-170
lines changed

Diff for: app/code/Magento/CatalogInventory/Model/StockRegistryProvider.php

-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ public function getStockItem($productId, $websiteId)
148148
if (!isset($this->stockItems[$key])) {
149149
$criteria = $this->stockItemCriteriaFactory->create();
150150
$criteria->setProductsFilter($productId);
151-
$criteria->setWebsiteFilter($websiteId);
152151
$collection = $this->stockItemRepository->getList($criteria);
153152
$stockItem = current($collection->getItems());
154153
if ($stockItem && $stockItem->getItemId()) {

Diff for: app/code/Magento/CatalogInventory/Test/Unit/Model/Spi/StockRegistryProviderTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ public function testGetStock()
253253
public function testGetStockItem()
254254
{
255255
$this->stockItemCriteriaFactory->expects($this->once())->method('create')->willReturn($this->stockItemCriteria);
256-
$this->stockItemCriteria->expects($this->once())->method('setWebsiteFilter')->willReturn(null);
257256
$this->stockItemCriteria->expects($this->once())->method('setProductsFilter')->willReturn(null);
258257
$stockItemCollection = $this->getMock(
259258
'\Magento\CatalogInventory\Model\ResourceModel\Stock\Item\Collection',

Diff for: app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\CatalogUrlRewrite\Observer;
77

8+
use Magento\Catalog\Model\Product\Visibility;
89
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
910
use Magento\UrlRewrite\Model\UrlPersistInterface;
1011
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
@@ -53,7 +54,9 @@ public function execute(\Magento\Framework\Event\Observer $observer)
5354
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
5455
]);
5556
}
56-
$this->urlPersist->replace($this->productUrlRewriteGenerator->generate($product));
57+
if ($product->getVisibility() != Visibility::VISIBILITY_NOT_VISIBLE) {
58+
$this->urlPersist->replace($this->productUrlRewriteGenerator->generate($product));
59+
}
5760
}
5861
}
5962
}

Diff for: app/code/Magento/CatalogUrlRewrite/Observer/ProductToWebsiteChangeObserver.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ public function execute(\Magento\Framework\Event\Observer $observer)
7272
UrlRewrite::ENTITY_ID => $product->getId(),
7373
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
7474
]);
75-
$this->urlPersist->replace($this->productUrlRewriteGenerator->generate($product));
75+
if ($product->getVisibility() != Visibility::VISIBILITY_NOT_VISIBLE) {
76+
$this->urlPersist->replace($this->productUrlRewriteGenerator->generate($product));
77+
}
7678
}
7779
}
7880
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ConfigurableProduct\Model\Plugin;
7+
8+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
9+
10+
/**
11+
* Class PriceBackend
12+
*
13+
* Make price validation optional for configurable product
14+
*/
15+
class PriceBackend
16+
{
17+
/**
18+
* @param \Magento\Catalog\Model\Product\Attribute\Backend\Price $subject
19+
* @param \Closure $proceed
20+
* @param \Magento\Catalog\Model\Product|\Magento\Framework\DataObject $object
21+
* @return bool
22+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
23+
*/
24+
public function aroundValidate(
25+
\Magento\Catalog\Model\Product\Attribute\Backend\Price $subject,
26+
\Closure $proceed,
27+
$object
28+
) {
29+
if ($object instanceof \Magento\Catalog\Model\Product
30+
&& $object->getTypeId() == Configurable::TYPE_CODE
31+
) {
32+
return true;
33+
} else {
34+
return $proceed($object);
35+
}
36+
}
37+
}

Diff for: app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Type/Configurable/Attribute.php

+17-25
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
namespace Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable;
99

1010
use Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute as ConfigurableAttribute;
11+
use Magento\Store\Model\Store;
12+
use Magento\Store\Model\StoreManagerInterface;
1113

1214
class Attribute extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
1315
{
@@ -60,16 +62,6 @@ protected function _construct()
6062
$this->_labelTable = $this->getTable('catalog_product_super_attribute_label');
6163
}
6264

63-
/**
64-
* Retrieve Catalog Helper
65-
*
66-
* @return \Magento\Catalog\Helper\Data
67-
*/
68-
public function getCatalogHelper()
69-
{
70-
return $this->_catalogData;
71-
}
72-
7365
/**
7466
* Save Custom labels for Attribute name
7567
*
@@ -90,26 +82,26 @@ public function saveLabel($attribute)
9082
);
9183
$bind = [
9284
'product_super_attribute_id' => (int)$attribute->getId(),
93-
'store_id' => (int)$attribute->getStoreId(),
85+
'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
9486
];
9587
$valueId = $connection->fetchOne($select, $bind);
9688
if ($valueId) {
97-
$connection->update(
98-
$this->_labelTable,
99-
['use_default' => (int)$attribute->getUseDefault(), 'value' => $attribute->getLabel()],
100-
$connection->quoteInto('value_id = ?', (int)$valueId)
101-
);
89+
$storeId = (int)$attribute->getStoreId() ?: $this->_storeManager->getStore()->getId();
10290
} else {
103-
$connection->insert(
104-
$this->_labelTable,
105-
[
106-
'product_super_attribute_id' => (int)$attribute->getId(),
107-
'store_id' => (int)$attribute->getStoreId(),
108-
'use_default' => (int)$attribute->getUseDefault(),
109-
'value' => $attribute->getLabel()
110-
]
111-
);
91+
// if attribute label not exists, always store on default store (0)
92+
$storeId = Store::DEFAULT_STORE_ID;
11293
}
94+
$connection->insertOnDuplicate(
95+
$this->_labelTable,
96+
[
97+
'product_super_attribute_id' => (int)$attribute->getId(),
98+
'use_default' => (int)$attribute->getUseDefault(),
99+
'store_id' => $storeId,
100+
'value' => $attribute->getLabel(),
101+
],
102+
['value', 'use_default']
103+
);
104+
113105
return $this;
114106
}
115107

Diff for: app/code/Magento/ConfigurableProduct/Setup/InstallData.php

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
4747
'minimal_price',
4848
'msrp',
4949
'msrp_display_actual_price_type',
50+
'price',
5051
'special_price',
5152
'special_from_date',
5253
'special_to_date',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\ConfigurableProduct\Test\Unit\Model\Plugin;
8+
9+
use Magento\ConfigurableProduct\Model\Plugin\PriceBackend;
10+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
11+
use Magento\Catalog\Model\Product\Type;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
14+
class PriceBackendTest extends \PHPUnit_Framework_TestCase
15+
{
16+
const CLOSURE_VALUE = 'CLOSURE';
17+
/** @var PriceBackend */
18+
private $priceBackendPlugin;
19+
/** @var \PHPUnit_Framework_MockObject_MockObject */
20+
private $priceAttributeMock;
21+
/** @var \Closure */
22+
private $closure;
23+
/** @var \PHPUnit_Framework_MockObject_MockObject */
24+
private $productMock;
25+
26+
protected function setUp()
27+
{
28+
$objectManager = new ObjectManager($this);
29+
$this->priceBackendPlugin = $objectManager->getObject('Magento\ConfigurableProduct\Model\Plugin\PriceBackend');
30+
31+
$this->closure = function () {
32+
return static::CLOSURE_VALUE;
33+
};
34+
$this->priceAttributeMock = $this->getMockBuilder('Magento\Catalog\Model\Product\Attribute\Backend\Price')
35+
->disableOriginalConstructor()
36+
->getMock();
37+
$this->productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
38+
->disableOriginalConstructor()
39+
->setMethods(['getTypeId', 'getPriceType', '__wakeUp'])
40+
->getMock();
41+
}
42+
43+
/**
44+
* @dataProvider aroundValidateDataProvider
45+
*
46+
* @param $typeId
47+
* @param $expectedResult
48+
*/
49+
public function testAroundValidate($typeId, $expectedResult)
50+
{
51+
$this->productMock->expects($this->any())->method('getTypeId')->will($this->returnValue($typeId));
52+
$result = $this->priceBackendPlugin->aroundValidate(
53+
$this->priceAttributeMock,
54+
$this->closure,
55+
$this->productMock
56+
);
57+
$this->assertEquals($expectedResult, $result);
58+
}
59+
60+
/**
61+
* Data provider for testAroundValidate
62+
*
63+
* @return array
64+
*/
65+
public function aroundValidateDataProvider()
66+
{
67+
return [
68+
['type' => Configurable::TYPE_CODE, 'result' => true],
69+
['type' => Type::TYPE_VIRTUAL, 'result' => static::CLOSURE_VALUE],
70+
];
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\ConfigurableProduct\Test\Unit\Model\ResourceModel\Product\Type\Configurable;
8+
9+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute as AttributeModel;
10+
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute;
11+
use Magento\Framework\DB\Select;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
13+
14+
class AttributeTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/** @var \PHPUnit_Framework_MockObject_MockObject */
17+
protected $connection;
18+
/**
19+
* @var Attribute
20+
*/
21+
protected $attribute;
22+
23+
/**
24+
* @var ObjectManagerHelper
25+
*/
26+
protected $objectManagerHelper;
27+
28+
/**
29+
* @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
protected $resource;
32+
33+
/**
34+
* @var \Magento\Catalog\Model\ResourceModel\Product\Relation|\PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
protected $relation;
37+
38+
protected function setUp()
39+
{
40+
$this->connection = $this->getMockBuilder('\Magento\Framework\DB\Adapter\AdapterInterface')->getMock();
41+
42+
$this->resource = $this->getMock('Magento\Framework\App\ResourceConnection', [], [], '', false);
43+
$this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection));
44+
$this->resource->expects($this->any())->method('getTableName')->willReturnArgument(0);
45+
46+
$this->objectManagerHelper = new ObjectManagerHelper($this);
47+
$this->attribute = $this->objectManagerHelper->getObject(
48+
Attribute::class,
49+
[
50+
'resource' => $this->resource,
51+
]
52+
);
53+
}
54+
55+
public function testSaveLabel()
56+
{
57+
$attributeId = 4354;
58+
59+
$select = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock();
60+
$this->connection->expects($this->once())->method('select')->willReturn($select);
61+
$select->expects($this->once())->method('from')->willReturnSelf();
62+
$select->expects($this->at(1))->method('where')->willReturnSelf();
63+
$select->expects($this->at(2))->method('where')->willReturnSelf();
64+
$this->connection->expects($this->once())->method('fetchOne')->with(
65+
$select,
66+
[
67+
'product_super_attribute_id' => $attributeId,
68+
'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
69+
]
70+
)->willReturn(0);
71+
72+
$this->connection->expects($this->once())->method('insertOnDuplicate')->with(
73+
'catalog_product_super_attribute_label',
74+
[
75+
'product_super_attribute_id' => $attributeId,
76+
'use_default' => 0,
77+
'store_id' => 0,
78+
'value' => 'test',
79+
]
80+
);
81+
$attributeMode = $this->getMockBuilder(AttributeModel::class)->setMethods(
82+
['getId', 'getUseDefault', 'getLabel']
83+
)->disableOriginalConstructor()->getMock();
84+
$attributeMode->expects($this->any())->method('getId')->willReturn($attributeId);
85+
$attributeMode->expects($this->any())->method('getUseDefault')->willReturn(0);
86+
$attributeMode->expects($this->any())->method('getLabel')->willReturn('test');
87+
$this->assertEquals($this->attribute, $this->attribute->saveLabel($attributeMode));
88+
}
89+
}

Diff for: app/code/Magento/ConfigurableProduct/etc/di.xml

+3
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,7 @@
123123
<argument name="priceResolver" xsi:type="object">ConfigurableRegularPriceResolver</argument>
124124
</arguments>
125125
</type>
126+
<type name="Magento\Catalog\Model\Product\Attribute\Backend\Price">
127+
<plugin name="configurable" type="Magento\ConfigurableProduct\Model\Plugin\PriceBackend" sortOrder="100" />
128+
</type>
126129
</config>

Diff for: app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/variations.js

+12
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ define([
159159
this.attributes(attributes);
160160
this.initImageUpload();
161161
this.disableConfigurableAttributes(attributes);
162+
this.showPrice();
162163
},
163164
changeButtonWizard: function () {
164165
var $button = $('[data-action=open-steps-wizard] [data-role=button-label]');
@@ -212,6 +213,7 @@ define([
212213
$('[data-attribute-code="' + attribute.code + '"] select').removeProp('disabled');
213214
});
214215
}
216+
this.showPrice();
215217
},
216218
toggleProduct: function (rowIndex) {
217219
var product, row, productChanged = {};
@@ -369,6 +371,16 @@ define([
369371
.prop('disabled', true);
370372
});
371373
},
374+
showPrice: function () {
375+
var priceContainer = $('[id="attribute-price-container"]');
376+
if (this.productMatrix().length !== 0) {
377+
priceContainer.hide();
378+
priceContainer.find('input').prop('disabled', true);
379+
} else {
380+
priceContainer.show();
381+
priceContainer.find('input').prop('disabled', false);
382+
}
383+
},
372384

373385
/**
374386
* Get currency symbol

Diff for: app/code/Magento/Downloadable/etc/webapi.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
</route>
4646
<route url="/V1/products/:sku/downloadable-links/samples/:id" method="PUT">
4747
<service class="Magento\Downloadable\Api\SampleRepositoryInterface" method="save"/>
48-
<resources>
49-
<resource ref="Magento_Downloadable::downloadable" />
50-
</resources>
51-
</route>
48+
<resources>
49+
<resource ref="Magento_Downloadable::downloadable" />
50+
</resources>
51+
</route>
5252
<route url="/V1/products/downloadable-links/samples/:id" method="DELETE">
5353
<service class="Magento\Downloadable\Api\SampleRepositoryInterface" method="delete"/>
5454
<resources>

0 commit comments

Comments
 (0)