Skip to content

Commit b2d2e78

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-87966' into 2.2-develop-pr35
2 parents 12994f6 + 3d62f77 commit b2d2e78

File tree

45 files changed

+1210
-429
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1210
-429
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public function imagePreprocessing($data)
279279
continue;
280280
}
281281

282-
$data[$attributeCode] = false;
282+
$data[$attributeCode] = '';
283283
}
284284

285285
return $data;

app/code/Magento/Catalog/Model/ResourceModel/Product/Gallery.php

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -160,63 +160,74 @@ protected function createBaseLoadSelect($entityId, $storeId, $attributeId)
160160
public function createBatchBaseSelect($storeId, $attributeId)
161161
{
162162
$linkField = $this->metadata->getLinkField();
163+
$conn = $this->getConnection();
163164

164-
$positionCheckSql = $this->getConnection()->getCheckSql(
165+
$positionCheckSql = $conn->getCheckSql(
165166
'value.position IS NULL',
166167
'default_value.position',
167168
'value.position'
168169
);
169170

170171
$mainTableAlias = $this->getMainTableAlias();
171172

172-
$select = $this->getConnection()->select()->from(
173-
[$mainTableAlias => $this->getMainTable()],
174-
[
175-
'value_id',
176-
'file' => 'value',
177-
'media_type'
178-
]
179-
)->joinInner(
180-
['entity' => $this->getTable(self::GALLERY_VALUE_TO_ENTITY_TABLE)],
181-
$mainTableAlias . '.value_id = entity.value_id',
182-
[$linkField]
183-
)->joinLeft(
184-
['value' => $this->getTable(self::GALLERY_VALUE_TABLE)],
185-
implode(
186-
' AND ',
187-
[
188-
$mainTableAlias . '.value_id = value.value_id',
189-
$this->getConnection()->quoteInto('value.store_id = ?', (int)$storeId),
190-
'value.' . $linkField . ' = entity.' . $linkField,
191-
]
192-
),
193-
[]
194-
)->joinLeft(
195-
['default_value' => $this->getTable(self::GALLERY_VALUE_TABLE)],
196-
implode(
197-
' AND ',
173+
$storeCondition = $conn->quoteInto('value.store_id = ?', (int)$storeId);
174+
$defStoreCondition = $conn->quoteInto('default_value.store_id = ?', Store::DEFAULT_STORE_ID);
175+
$select = $conn->select()
176+
->from(
177+
[$mainTableAlias => $this->getMainTable()],
198178
[
199-
$mainTableAlias . '.value_id = default_value.value_id',
200-
$this->getConnection()->quoteInto('default_value.store_id = ?', Store::DEFAULT_STORE_ID),
201-
'default_value.' . $linkField . ' = entity.' . $linkField,
179+
'value_id',
180+
'file' => 'value',
181+
'media_type'
202182
]
203-
),
204-
[]
205-
)->columns([
206-
'label' => $this->getConnection()->getIfNullSql('`value`.`label`', '`default_value`.`label`'),
207-
'position' => $this->getConnection()->getIfNullSql('`value`.`position`', '`default_value`.`position`'),
208-
'disabled' => $this->getConnection()->getIfNullSql('`value`.`disabled`', '`default_value`.`disabled`'),
209-
'label_default' => 'default_value.label',
210-
'position_default' => 'default_value.position',
211-
'disabled_default' => 'default_value.disabled'
212-
])->where(
213-
$mainTableAlias . '.attribute_id = ?',
214-
$attributeId
215-
)->where(
216-
$mainTableAlias . '.disabled = 0'
217-
)->order(
218-
$positionCheckSql . ' ' . \Magento\Framework\DB\Select::SQL_ASC
219-
);
183+
)
184+
->joinInner(
185+
['entity' => $this->getTable(self::GALLERY_VALUE_TO_ENTITY_TABLE)],
186+
$mainTableAlias . '.value_id = entity.value_id',
187+
[$linkField]
188+
)
189+
->joinLeft(
190+
['value' => $this->getTable(self::GALLERY_VALUE_TABLE)],
191+
implode(
192+
' AND ',
193+
[
194+
$mainTableAlias . '.value_id = value.value_id',
195+
$storeCondition,
196+
'value.' . $linkField . ' = entity.' . $linkField,
197+
]
198+
),
199+
[]
200+
)
201+
->joinLeft(
202+
['default_value' => $this->getTable(self::GALLERY_VALUE_TABLE)],
203+
implode(
204+
' AND ',
205+
[
206+
$mainTableAlias . '.value_id = default_value.value_id',
207+
$defStoreCondition,
208+
'default_value.' . $linkField . ' = entity.' . $linkField,
209+
]
210+
),
211+
[]
212+
)
213+
->columns([
214+
'label' => $conn->getIfNullSql('`value`.`label`', '`default_value`.`label`'),
215+
'position' => $conn->getIfNullSql('`value`.`position`', '`default_value`.`position`'),
216+
'disabled' => $conn->getIfNullSql('`value`.`disabled`', '`default_value`.`disabled`'),
217+
'label_default' => 'default_value.label',
218+
'position_default' => 'default_value.position',
219+
'disabled_default' => 'default_value.disabled'
220+
])
221+
->where($mainTableAlias . '.attribute_id = ?', $attributeId)
222+
->where($mainTableAlias . '.disabled = 0');
223+
224+
// filter entities by store
225+
if ($storeId > 0) {
226+
$orWhere = $storeCondition . ' OR '. $defStoreCondition;
227+
$select->where($orWhere);
228+
}
229+
230+
$select->order($positionCheckSql . ' ' . \Magento\Framework\DB\Select::SQL_ASC);
220231

221232
return $select;
222233
}

app/code/Magento/Catalog/Test/Mftf/Test/AdminApplyTierPriceToProductTest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProduct1">
4545
<argument name="product" value="$$createSimpleProduct$$"/>
4646
</actionGroup>
47+
<scrollToTopOfPage stepKey="scrollToTopOfPage1"/>
4748
<click selector="{{AdminProductFormSection.advancedPricingLink}}" stepKey="clickOnAdvancedPricingButton1"/>
4849
<waitForElement selector="{{AdminProductFormAdvancedPricingSection.customerGroupPriceAddButton}}" stepKey="waitForCustomerGroupPriceAddButton1"/>
4950
<click selector="{{AdminProductFormAdvancedPricingSection.customerGroupPriceAddButton}}" stepKey="addCustomerGroupAllGroupsQty1PriceDiscountAnd10percent"/>
@@ -73,6 +74,7 @@
7374
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProduct2">
7475
<argument name="product" value="$$createSimpleProduct$$"/>
7576
</actionGroup>
77+
<scrollToTopOfPage stepKey="scrollToTopOfPage2"/>
7678
<click selector="{{AdminProductFormSection.advancedPricingLink}}" stepKey="clickOnAdvancedPricingButton2"/>
7779
<waitForElement selector="{{AdminProductFormAdvancedPricingSection.customerGroupPriceAddButton}}" stepKey="waitForcustomerGroupPriceAddButton2"/>
7880
<waitForElement selector="{{AdminProductFormAdvancedPricingSection.productTierPriceCustGroupSelect('0')}}" time="30" stepKey="waitForSelectCustomerGroupNameAttribute1"/>
@@ -97,6 +99,7 @@
9799
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProduct3">
98100
<argument name="product" value="$$createSimpleProduct$$"/>
99101
</actionGroup>
102+
<scrollToTopOfPage stepKey="scrollToTopOfPage3"/>
100103
<click selector="{{AdminProductFormSection.advancedPricingLink}}" stepKey="clickOnAdvancedPricingButton3"/>
101104
<waitForElement selector="{{AdminProductFormAdvancedPricingSection.customerGroupPriceAddButton}}" stepKey="waitForcustomerGroupPriceAddButton3"/>
102105
<waitForElement selector="{{AdminProductFormAdvancedPricingSection.productTierPriceCustGroupSelect('0')}}" stepKey="waitForSelectCustomerGroupNameAttribute2"/>
@@ -162,6 +165,7 @@
162165
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProduct4">
163166
<argument name="product" value="$$createSimpleProduct$$"/>
164167
</actionGroup>
168+
<scrollToTopOfPage stepKey="scrollToTopOfPage4"/>
165169
<click selector="{{AdminProductFormSection.advancedPricingLink}}" stepKey="clickOnAdvancedPricingButton4"/>
166170
<waitForElement selector="{{AdminProductFormAdvancedPricingSection.customerGroupPriceAddButton}}" stepKey="waitForcustomerGroupPriceAddButton4"/>
167171
<fillField selector="{{AdminProductFormAdvancedPricingSection.productTierPricePercentageValuePriceInput('1')}}" userInput="25" stepKey="selectProductTierPricePercentageValue2"/>
@@ -229,12 +233,14 @@
229233
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProduct5">
230234
<argument name="product" value="$$createSimpleProduct$$"/>
231235
</actionGroup>
236+
<scrollToTopOfPage stepKey="scrollToTopOfPage5"/>
232237
<click selector="{{AdminProductFormSection.advancedPricingLink}}" stepKey="clickOnAdvancedPricingButton5"/>
233238
<waitForElement selector="{{AdminProductFormAdvancedPricingSection.customerGroupPriceDeleteButton}}" stepKey="waitForcustomerGroupPriceDeleteButton"/>
234239
<click selector="{{AdminProductFormAdvancedPricingSection.customerGroupPriceDeleteButton}}" stepKey="deleteFirstRowOfCustomerGroupPrice"/>
235240
<click selector="{{AdminProductFormAdvancedPricingSection.customerGroupPriceDeleteButton}}" stepKey="deleteSecondRowOfCustomerGroupPrice"/>
236241
<click selector="{{AdminProductFormAdvancedPricingSection.doneButton}}" stepKey="clickDoneButton5"/>
237242
<actionGroup ref="SaveProductOnProductPageOnAdmin" stepKey="saveProduct5"/>
243+
<scrollToTopOfPage stepKey="scrollToTopOfPage6"/>
238244
<click selector="{{AdminProductFormSection.advancedPricingLink}}" stepKey="clickOnAdvancedPricingButton6"/>
239245
<waitForElement selector="{{AdminProductFormAdvancedPricingSection.customerGroupPriceAddButton}}" stepKey="waitForcustomerGroupPriceAddButton5"/>
240246
<dontSeeElement selector="{{AdminProductFormAdvancedPricingSection.productTierPriceQtyInput('0')}}" stepKey="dontSeeQtyInputOfFirstRow"/>

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php

Lines changed: 27 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Category;
77

8-
use Magento\Catalog\Controller\Adminhtml\Category\Save as Model;
9-
108
/**
119
* Class SaveTest
1210
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -463,18 +461,35 @@ public function dataProviderExecute()
463461
*/
464462
public function imagePreprocessingDataProvider()
465463
{
464+
$dataWithImage = [
465+
'image' => 'path.jpg',
466+
'name' => 'category',
467+
'description' => '',
468+
'parent' => 0
469+
];
470+
$expectedSameAsDataWithImage = $dataWithImage;
471+
472+
$dataWithoutImage = [
473+
'name' => 'category',
474+
'description' => '',
475+
'parent' => 0
476+
];
477+
$expectedIfDataWithoutImage = $dataWithoutImage;
478+
$expectedIfDataWithoutImage['image'] = '';
479+
466480
return [
467-
[['attribute1' => null, 'attribute2' => 123]],
468-
[['attribute2' => 123]]
481+
'categoryPostData contains image' => [$dataWithImage, $expectedSameAsDataWithImage],
482+
'categoryPostData doesn\'t contain image' => [$dataWithoutImage, $expectedIfDataWithoutImage],
469483
];
470484
}
471485

472486
/**
473487
* @dataProvider imagePreprocessingDataProvider
474488
*
475489
* @param array $data
490+
* @param array $expected
476491
*/
477-
public function testImagePreprocessingWithoutValue($data)
492+
public function testImagePreprocessing($data, $expected)
478493
{
479494
$eavConfig = $this->createPartialMock(\Magento\Eav\Model\Config::class, ['getEntityType']);
480495

@@ -484,68 +499,30 @@ public function testImagePreprocessingWithoutValue($data)
484499

485500
$collection = new \Magento\Framework\DataObject(['attribute_collection' => [
486501
new \Magento\Framework\DataObject([
487-
'attribute_code' => 'attribute1',
502+
'attribute_code' => 'image',
488503
'backend' => $imageBackendModel
489504
]),
490505
new \Magento\Framework\DataObject([
491-
'attribute_code' => 'attribute2',
506+
'attribute_code' => 'name',
492507
'backend' => new \Magento\Framework\DataObject()
493-
])
494-
]]);
495-
496-
$eavConfig->expects($this->once())
497-
->method('getEntityType')
498-
->with(\Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE)
499-
->will($this->returnValue($collection));
500-
501-
$model = $this->objectManager->getObject(\Magento\Catalog\Controller\Adminhtml\Category\Save::class, [
502-
'eavConfig' => $eavConfig
503-
]);
504-
505-
$result = $model->imagePreprocessing($data);
506-
507-
$this->assertEquals([
508-
'attribute1' => false,
509-
'attribute2' => 123
510-
], $result);
511-
}
512-
513-
public function testImagePreprocessingWithValue()
514-
{
515-
$eavConfig = $this->createPartialMock(\Magento\Eav\Model\Config::class, ['getEntityType']);
516-
517-
$imageBackendModel = $this->objectManager->getObject(
518-
\Magento\Catalog\Model\Category\Attribute\Backend\Image::class
519-
);
520-
521-
$collection = new \Magento\Framework\DataObject(['attribute_collection' => [
522-
new \Magento\Framework\DataObject([
523-
'attribute_code' => 'attribute1',
524-
'backend' => $imageBackendModel
525508
]),
526509
new \Magento\Framework\DataObject([
527-
'attribute_code' => 'attribute2',
510+
'attribute_code' => 'level',
528511
'backend' => new \Magento\Framework\DataObject()
529-
])
512+
]),
530513
]]);
531514

532515
$eavConfig->expects($this->once())
533516
->method('getEntityType')
534517
->with(\Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE)
535518
->will($this->returnValue($collection));
536519

537-
$model = $this->objectManager->getObject(Model::class, [
520+
$model = $this->objectManager->getObject(\Magento\Catalog\Controller\Adminhtml\Category\Save::class, [
538521
'eavConfig' => $eavConfig
539522
]);
540523

541-
$result = $model->imagePreprocessing([
542-
'attribute1' => 'somevalue',
543-
'attribute2' => null
544-
]);
524+
$result = $model->imagePreprocessing($data);
545525

546-
$this->assertEquals([
547-
'attribute1' => 'somevalue',
548-
'attribute2' => null
549-
], $result);
526+
$this->assertEquals($expected, $result);
550527
}
551528
}

0 commit comments

Comments
 (0)