Skip to content

Commit fd7e325

Browse files
committed
Merge remote-tracking branch 'remotes/origin/MAGETWO-44744' into BugFestW5
2 parents 61dcae4 + 55888b1 commit fd7e325

File tree

3 files changed

+110
-29
lines changed

3 files changed

+110
-29
lines changed

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

Lines changed: 17 additions & 25 deletions
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

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+
}

app/code/Magento/Downloadable/etc/webapi.xml

Lines changed: 4 additions & 4 deletions
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)