Skip to content

Commit 9240974

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-95461' into 2.2-develop-pr8
2 parents b6c7278 + 0a1a807 commit 9240974

File tree

3 files changed

+127
-19
lines changed

3 files changed

+127
-19
lines changed

app/code/Magento/Catalog/Helper/Data.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Api\CategoryRepositoryInterface;
99
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Store\Model\ScopeInterface;
1011
use Magento\Customer\Model\Session as CustomerSession;
1112
use Magento\Framework\Exception\NoSuchEntityException;
1213
use Magento\Framework\Pricing\PriceCurrencyInterface;
@@ -269,7 +270,8 @@ public function setStoreId($store)
269270

270271
/**
271272
* Return current category path or get it from current category
272-
* and creating array of categories|product paths for breadcrumbs
273+
*
274+
* Creating array of categories|product paths for breadcrumbs
273275
*
274276
* @return array
275277
*/
@@ -378,6 +380,7 @@ public function getLastViewedUrl()
378380

379381
/**
380382
* Split SKU of an item by dashes and spaces
383+
*
381384
* Words will not be broken, unless this length is greater than $length
382385
*
383386
* @param string $sku
@@ -406,14 +409,15 @@ public function getAttributeHiddenFields()
406409
/**
407410
* Retrieve Catalog Price Scope
408411
*
409-
* @return int
412+
* @return int|null
410413
*/
411414
public function getPriceScope()
412415
{
413-
return $this->scopeConfig->getValue(
416+
$priceScope = $this->scopeConfig->getValue(
414417
self::XML_PATH_PRICE_SCOPE,
415-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
418+
ScopeInterface::SCOPE_STORE
416419
);
420+
return isset($priceScope) ? (int)$priceScope : null;
417421
}
418422

419423
/**
@@ -449,7 +453,7 @@ public function isUrlDirectivesParsingAllowed()
449453
{
450454
return $this->scopeConfig->isSetFlag(
451455
self::CONFIG_PARSE_URL_DIRECTIVES,
452-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
456+
ScopeInterface::SCOPE_STORE,
453457
$this->_storeId
454458
);
455459
}
@@ -466,19 +470,22 @@ public function getPageTemplateProcessor()
466470

467471
/**
468472
* Whether to display items count for each filter option
473+
*
469474
* @param int $storeId Store view ID
470475
* @return bool
471476
*/
472477
public function shouldDisplayProductCountOnLayer($storeId = null)
473478
{
474479
return $this->scopeConfig->isSetFlag(
475480
self::XML_PATH_DISPLAY_PRODUCT_COUNT,
476-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
481+
ScopeInterface::SCOPE_STORE,
477482
$storeId
478483
);
479484
}
480485

481486
/**
487+
* Convert tax address array to address data object with country id and postcode
488+
*
482489
* @param array $taxAddress
483490
* @return \Magento\Customer\Api\Data\AddressInterface|null
484491
*/

app/code/Magento/Catalog/Model/Product/Attribute/Backend/TierPrice/UpdateHandler.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ public function execute($entity, $arguments = [])
8282
__('Tier prices data should be array, but actually other type is received')
8383
);
8484
}
85-
$websiteId = $this->storeManager->getStore($entity->getStoreId())->getWebsiteId();
85+
$websiteId = (int)$this->storeManager->getStore($entity->getStoreId())->getWebsiteId();
8686
$isGlobal = $attribute->isScopeGlobal() || $websiteId === 0;
8787
$identifierField = $this->metadataPoll->getMetadata(ProductInterface::class)->getLinkField();
88-
$productId = $entity->getData($identifierField);
88+
$productId = (int)$entity->getData($identifierField);
8989

9090
// prepare original data to compare
9191
$origPrices = $entity->getOrigData($attribute->getName());
92-
$old = $this->prepareOriginalDataToCompare($origPrices, $isGlobal);
92+
$old = $this->prepareOldTierPriceToCompare($origPrices);
9393
// prepare data for save
9494
$new = $this->prepareNewDataForSave($priceRows, $isGlobal);
9595

@@ -262,19 +262,18 @@ private function isWebsiteGlobal(int $websiteId): bool
262262
}
263263

264264
/**
265+
* Prepare old data to compare.
266+
*
265267
* @param array|null $origPrices
266-
* @param bool $isGlobal
267268
* @return array
268269
*/
269-
private function prepareOriginalDataToCompare($origPrices, $isGlobal = true): array
270+
private function prepareOldTierPriceToCompare($origPrices): array
270271
{
271272
$old = [];
272273
if (is_array($origPrices)) {
273274
foreach ($origPrices as $data) {
274-
if ($isGlobal === $this->isWebsiteGlobal((int)$data['website_id'])) {
275-
$key = $this->getPriceKey($data);
276-
$old[$key] = $data;
277-
}
275+
$key = $this->getPriceKey($data);
276+
$old[$key] = $data;
278277
}
279278
}
280279

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/ProductTest.php

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Magento\Framework\Data\Form\FormKey;
1010
use Magento\Framework\Message\Manager;
1111
use Magento\TestFramework\Helper\Bootstrap;
12+
use Magento\Catalog\Api\ProductRepositoryInterface;
13+
use Magento\Framework\Message\MessageInterface;
1214

1315
/**
1416
* @magentoAppArea adminhtml
@@ -21,7 +23,7 @@ public function testSaveActionWithDangerRequest()
2123
$this->dispatch('backend/catalog/product/save');
2224
$this->assertSessionMessages(
2325
$this->equalTo(['Unable to save product']),
24-
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
26+
MessageInterface::TYPE_ERROR
2527
);
2628
$this->assertRedirect($this->stringContains('/backend/catalog/product/new'));
2729
}
@@ -38,7 +40,7 @@ public function testSaveActionAndNew()
3840
$this->assertRedirect($this->stringStartsWith('http://localhost/index.php/backend/catalog/product/new/'));
3941
$this->assertSessionMessages(
4042
$this->contains('You saved the product.'),
41-
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
43+
MessageInterface::TYPE_SUCCESS
4244
);
4345
}
4446

@@ -61,11 +63,11 @@ public function testSaveActionAndDuplicate()
6163
);
6264
$this->assertSessionMessages(
6365
$this->contains('You saved the product.'),
64-
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
66+
MessageInterface::TYPE_SUCCESS
6567
);
6668
$this->assertSessionMessages(
6769
$this->contains('You duplicated the product.'),
68-
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
70+
MessageInterface::TYPE_SUCCESS
6971
);
7072
}
7173

@@ -236,4 +238,104 @@ public function saveActionWithAlreadyExistingUrlKeyDataProvider()
236238
]
237239
];
238240
}
241+
242+
/**
243+
* Test product save with selected tier price
244+
*
245+
* @dataProvider saveActionTierPriceDataProvider
246+
* @param array $postData
247+
* @param array $tierPrice
248+
* @magentoDataFixture Magento/Catalog/_files/product_has_tier_price_show_as_low_as.php
249+
* @magentoConfigFixture current_store catalog/price/scope 1
250+
*/
251+
public function testSaveActionTierPrice(array $postData, array $tierPrice)
252+
{
253+
$postData['product'] = $this->getProductData($tierPrice);
254+
$this->getRequest()->setPostValue($postData);
255+
$this->dispatch('backend/catalog/product/save/id/' . $postData['id']);
256+
$this->assertSessionMessages(
257+
$this->contains('You saved the product.'),
258+
MessageInterface::TYPE_SUCCESS
259+
);
260+
}
261+
262+
/**
263+
* Provide test data for testSaveActionWithAlreadyExistingUrlKey().
264+
*
265+
* @return array
266+
*/
267+
public function saveActionTierPriceDataProvider()
268+
{
269+
return [
270+
[
271+
'post_data' => [
272+
'id' => '1',
273+
'type' => 'simple',
274+
'store' => '0',
275+
'set' => '4',
276+
'back' => 'edit',
277+
'product' => [],
278+
'is_downloadable' => '0',
279+
'affect_configurable_product_attributes' => '1',
280+
'new_variation_attribute_set_id' => '4',
281+
'use_default' => [
282+
'gift_message_available' => '0',
283+
'gift_wrapping_available' => '0'
284+
],
285+
'configurable_matrix_serialized' => '[]',
286+
'associated_product_ids_serialized' => '[]'
287+
],
288+
'tier_price_for_request' => [
289+
[
290+
'price_id' => '1',
291+
'website_id' => '0',
292+
'cust_group' => '32000',
293+
'price' => '111.00',
294+
'price_qty' => '100',
295+
'website_price' => '111.0000',
296+
'initialize' => 'true',
297+
'record_id' => '1',
298+
'value_type' => 'fixed'
299+
],
300+
[
301+
'price_id' => '2',
302+
'website_id' => '1',
303+
'cust_group' => '32000',
304+
'price' => '222.00',
305+
'price_qty' => '200',
306+
'website_price' => '111.0000',
307+
'initialize' => 'true',
308+
'record_id' => '2',
309+
'value_type' => 'fixed'
310+
],
311+
[
312+
'price_id' => '3',
313+
'website_id' => '1',
314+
'cust_group' => '32000',
315+
'price' => '333.00',
316+
'price_qty' => '300',
317+
'website_price' => '111.0000',
318+
'initialize' => 'true',
319+
'record_id' => '3',
320+
'value_type' => 'fixed'
321+
]
322+
]
323+
]
324+
];
325+
}
326+
327+
/**
328+
* Return product data for test without entity_id for further save
329+
*
330+
* @param array $tierPrice
331+
* @return array
332+
*/
333+
private function getProductData(array $tierPrice)
334+
{
335+
$productRepositoryInterface = $this->_objectManager->get(ProductRepositoryInterface::class);
336+
$product = $productRepositoryInterface->get('tier_prices')->getData();
337+
$product['tier_price'] = $tierPrice;
338+
unset($product['entity_id']);
339+
return $product;
340+
}
239341
}

0 commit comments

Comments
 (0)