Skip to content

Commit bd9298d

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-95753' into 2.3-develop-pr11
2 parents 9186f4a + 24b7d98 commit bd9298d

File tree

3 files changed

+129
-22
lines changed

3 files changed

+129
-22
lines changed

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

Lines changed: 15 additions & 8 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;
@@ -273,7 +274,8 @@ public function setStoreId($store)
273274

274275
/**
275276
* Return current category path or get it from current category
276-
* and creating array of categories|product paths for breadcrumbs
277+
*
278+
* Creating array of categories|product paths for breadcrumbs
277279
*
278280
* @return array
279281
*/
@@ -382,6 +384,7 @@ public function getLastViewedUrl()
382384

383385
/**
384386
* Split SKU of an item by dashes and spaces
387+
*
385388
* Words will not be broken, unless this length is greater than $length
386389
*
387390
* @param string $sku
@@ -410,14 +413,15 @@ public function getAttributeHiddenFields()
410413
/**
411414
* Retrieve Catalog Price Scope
412415
*
413-
* @return int
416+
* @return int|null
414417
*/
415-
public function getPriceScope()
418+
public function getPriceScope(): ?int
416419
{
417-
return $this->scopeConfig->getValue(
420+
$priceScope = $this->scopeConfig->getValue(
418421
self::XML_PATH_PRICE_SCOPE,
419-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
422+
ScopeInterface::SCOPE_STORE
420423
);
424+
return isset($priceScope) ? (int)$priceScope : null;
421425
}
422426

423427
/**
@@ -439,7 +443,7 @@ public function isUsingStaticUrlsAllowed()
439443
{
440444
return $this->scopeConfig->isSetFlag(
441445
self::CONFIG_USE_STATIC_URLS,
442-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
446+
ScopeInterface::SCOPE_STORE
443447
);
444448
}
445449

@@ -454,7 +458,7 @@ public function isUrlDirectivesParsingAllowed()
454458
{
455459
return $this->scopeConfig->isSetFlag(
456460
self::CONFIG_PARSE_URL_DIRECTIVES,
457-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
461+
ScopeInterface::SCOPE_STORE,
458462
$this->_storeId
459463
);
460464
}
@@ -472,19 +476,22 @@ public function getPageTemplateProcessor()
472476

473477
/**
474478
* Whether to display items count for each filter option
479+
*
475480
* @param int $storeId Store view ID
476481
* @return bool
477482
*/
478483
public function shouldDisplayProductCountOnLayer($storeId = null)
479484
{
480485
return $this->scopeConfig->isSetFlag(
481486
self::XML_PATH_DISPLAY_PRODUCT_COUNT,
482-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
487+
ScopeInterface::SCOPE_STORE,
483488
$storeId
484489
);
485490
}
486491

487492
/**
493+
* Convert tax address array to address data object with country id and postcode
494+
*
488495
* @param array $taxAddress
489496
* @return \Magento\Customer\Api\Data\AddressInterface|null
490497
*/

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ public function execute($entity, $arguments = [])
8686
__('Tier prices data should be array, but actually other type is received')
8787
);
8888
}
89-
$websiteId = $this->storeManager->getStore($entity->getStoreId())->getWebsiteId();
89+
$websiteId = (int)$this->storeManager->getStore($entity->getStoreId())->getWebsiteId();
9090
$isGlobal = $attribute->isScopeGlobal() || $websiteId === 0;
9191
$identifierField = $this->metadataPoll->getMetadata(ProductInterface::class)->getLinkField();
92-
$productId = (int) $entity->getData($identifierField);
92+
$productId = (int)$entity->getData($identifierField);
9393

9494
// prepare original data to compare
9595
$origPrices = [];
@@ -98,7 +98,7 @@ public function execute($entity, $arguments = [])
9898
$origPrices = $entity->getOrigData($attribute->getName());
9999
}
100100

101-
$old = $this->prepareOriginalDataToCompare($origPrices, $isGlobal);
101+
$old = $this->prepareOldTierPriceToCompare($origPrices);
102102
// prepare data for save
103103
$new = $this->prepareNewDataForSave($priceRows, $isGlobal);
104104

@@ -271,21 +271,18 @@ private function isWebsiteGlobal(int $websiteId): bool
271271
}
272272

273273
/**
274-
* Prepare original data to compare.
274+
* Prepare old data to compare.
275275
*
276276
* @param array|null $origPrices
277-
* @param bool $isGlobal
278277
* @return array
279278
*/
280-
private function prepareOriginalDataToCompare(?array $origPrices, bool $isGlobal = true): array
279+
private function prepareOldTierPriceToCompare(?array $origPrices): array
281280
{
282281
$old = [];
283282
if (is_array($origPrices)) {
284283
foreach ($origPrices as $data) {
285-
if ($isGlobal === $this->isWebsiteGlobal((int)$data['website_id'])) {
286-
$key = $this->getPriceKey($data);
287-
$old[$key] = $data;
288-
}
284+
$key = $this->getPriceKey($data);
285+
$old[$key] = $data;
289286
}
290287
}
291288

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

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Framework\App\Request\DataPersistorInterface;
99
use Magento\Framework\Message\Manager;
1010
use Magento\Framework\App\Request\Http as HttpRequest;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Framework\Message\MessageInterface;
1113

1214
/**
1315
* @magentoAppArea adminhtml
@@ -24,7 +26,7 @@ public function testSaveActionWithDangerRequest()
2426
$this->dispatch('backend/catalog/product/save');
2527
$this->assertSessionMessages(
2628
$this->equalTo(['The product was unable to be saved. Please try again.']),
27-
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
29+
MessageInterface::TYPE_ERROR
2830
);
2931
$this->assertRedirect($this->stringContains('/backend/catalog/product/new'));
3032
}
@@ -44,7 +46,7 @@ public function testSaveActionAndNew()
4446
$this->assertRedirect($this->stringStartsWith('http://localhost/index.php/backend/catalog/product/new/'));
4547
$this->assertSessionMessages(
4648
$this->contains('You saved the product.'),
47-
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
49+
MessageInterface::TYPE_SUCCESS
4850
);
4951
}
5052

@@ -71,11 +73,11 @@ public function testSaveActionAndDuplicate()
7173
);
7274
$this->assertSessionMessages(
7375
$this->contains('You saved the product.'),
74-
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
76+
MessageInterface::TYPE_SUCCESS
7577
);
7678
$this->assertSessionMessages(
7779
$this->contains('You duplicated the product.'),
78-
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
80+
MessageInterface::TYPE_SUCCESS
7981
);
8082
}
8183

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

0 commit comments

Comments
 (0)