forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/MC-29689' into 2.4-develop-com-pr2
- Loading branch information
Showing
6 changed files
with
354 additions
and
42 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
...ation/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Save/AdvancedPricingTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Catalog\Controller\Adminhtml\Product\Save; | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Customer\Api\Data\GroupInterface; | ||
use Magento\Framework\App\Request\Http; | ||
use Magento\Framework\Message\MessageInterface; | ||
use Magento\TestFramework\TestCase\AbstractBackendController; | ||
|
||
/** | ||
* Test cases for set advanced price to product. | ||
* | ||
* @magentoAppArea adminhtml | ||
* @magentoDbIsolation enabled | ||
*/ | ||
class AdvancedPricingTest extends AbstractBackendController | ||
{ | ||
/** | ||
* @var ProductRepositoryInterface | ||
*/ | ||
private $productRepository; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class); | ||
} | ||
|
||
/** | ||
* Assert that special price correctly saved to product. | ||
* | ||
* @magentoDataFixture Magento/Catalog/_files/product_without_options.php | ||
* | ||
* @return void | ||
*/ | ||
public function testAddSpecialPriceToProduct(): void | ||
{ | ||
$product = $this->productRepository->get('simple'); | ||
$postData = [ | ||
'product' => [ | ||
'special_price' => 8, | ||
], | ||
]; | ||
$this->assertNull($product->getSpecialPrice()); | ||
$this->dispatchWithData((int)$product->getEntityId(), $postData); | ||
$product = $this->productRepository->get('simple', false, null, true); | ||
$this->assertEquals(8, $product->getSpecialPrice()); | ||
} | ||
|
||
/** | ||
* Assert that tier price correctly saved to product. | ||
* | ||
* @magentoDataFixture Magento/Catalog/_files/product_without_options.php | ||
* | ||
* @return void | ||
*/ | ||
public function testAddTierPriceToProduct(): void | ||
{ | ||
$product = $this->productRepository->get('simple'); | ||
$postData = [ | ||
'product' => [ | ||
'tier_price' => [ | ||
[ | ||
'website_id' => '0', | ||
'cust_group' => GroupInterface::CUST_GROUP_ALL, | ||
'price_qty' => '100', | ||
'price' => 5, | ||
'value_type' => 'fixed', | ||
] | ||
], | ||
], | ||
]; | ||
$this->assertEquals(10, $product->getTierPrice(100)); | ||
$this->dispatchWithData((int)$product->getEntityId(), $postData); | ||
$product = $this->productRepository->get('simple', false, null, true); | ||
$this->assertEquals(5, $product->getTierPrice(100)); | ||
} | ||
|
||
/** | ||
* Dispatch product save with data. | ||
* | ||
* @param int $productId | ||
* @param array $productPostData | ||
* @return void | ||
*/ | ||
private function dispatchWithData(int $productId, array $productPostData): void | ||
{ | ||
$this->getRequest()->setPostValue($productPostData); | ||
$this->getRequest()->setMethod(Http::METHOD_POST); | ||
$this->dispatch('backend/catalog/product/save/id/' . $productId); | ||
$this->assertSessionMessages( | ||
$this->contains('You saved the product.'), | ||
MessageInterface::TYPE_SUCCESS | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...ation/testsuite/Magento/Catalog/_files/simple_product_with_tier_price_for_logged_user.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
require __DIR__ . '/product_simple.php'; | ||
|
||
$product = $productRepository->get('simple', false, null, true); | ||
$tierPrices = $product->getTierPrices() ?? []; | ||
$tierPriceExtensionAttributes = $tpExtensionAttributesFactory->create()->setWebsiteId($adminWebsite->getId()); | ||
$tierPrices[] = $tierPriceFactory->create( | ||
[ | ||
'data' => [ | ||
'customer_group_id' => 1, | ||
'qty' => 3, | ||
'value' => 1 | ||
] | ||
] | ||
)->setExtensionAttributes($tierPriceExtensionAttributes); | ||
$product->setTierPrices($tierPrices); | ||
$productRepository->save($product); |
Oops, something went wrong.