-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-9139: 32977 Fixed text area for Customizable Options on the Ch…
…eckout Cart Page #33256 - Merge Pull Request #33256 from AZiniukhin/magento2:32977-Fix-Text-Area-for-Customizable-Options - Merged commits: 1. f724fec 2. a3bf297 3. b506bb4
- Loading branch information
Showing
4 changed files
with
259 additions
and
1 deletion.
There are no files selected for viewing
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
83 changes: 83 additions & 0 deletions
83
...egration/testsuite/Magento/Catalog/_files/product_simple_with_custom_option_text_area.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,83 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
use Magento\Catalog\Api\CategoryLinkManagementInterface; | ||
use Magento\Catalog\Api\Data\ProductCustomOptionInterface; | ||
use Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory; | ||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\Catalog\Model\Product\Attribute\Source\Status; | ||
use Magento\Catalog\Model\Product\Type; | ||
use Magento\Catalog\Model\Product\Visibility; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
Bootstrap::getInstance()->reinitialize(); | ||
|
||
/** @var \Magento\TestFramework\ObjectManager $objectManager */ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
|
||
/** @var CategoryLinkManagementInterface $categoryLinkManagement */ | ||
$categoryLinkManagement = $objectManager->create(CategoryLinkManagementInterface::class); | ||
|
||
/** @var $product Product */ | ||
$product = $objectManager->create(Product::class); | ||
$product->isObjectNew(true); | ||
$product->setTypeId(Type::TYPE_SIMPLE) | ||
->setAttributeSetId(4) | ||
->setWebsiteIds([1]) | ||
->setName('Simple Product') | ||
->setSku('simple_with_custom_option_text_area') | ||
->setPrice(10) | ||
->setWeight(1) | ||
->setShortDescription("Short description") | ||
->setTaxClassId(0) | ||
->setDescription('Description with <b>html tag</b>') | ||
->setMetaTitle('meta title') | ||
->setMetaKeyword('meta keyword') | ||
->setMetaDescription('meta description') | ||
->setVisibility(Visibility::VISIBILITY_BOTH) | ||
->setStatus(Status::STATUS_ENABLED) | ||
->setStockData( | ||
[ | ||
'use_config_manage_stock' => 1, | ||
'qty' => 100, | ||
'is_qty_decimal' => 0, | ||
'is_in_stock' => 1, | ||
] | ||
)->setCanSaveCustomOptions(true) | ||
->setHasOptions(true); | ||
|
||
$oldOptions = [ | ||
[ | ||
'title' => 'area option', | ||
'type' => 'area', | ||
'is_require' => false, | ||
'sort_order' => 1, | ||
'price' => 20.0, | ||
'price_type' => 'percent', | ||
'sku' => 'sku_test', | ||
'max_characters' => 350 | ||
] | ||
]; | ||
|
||
$options = []; | ||
|
||
/** @var ProductCustomOptionInterfaceFactory $customOptionFactory */ | ||
$customOptionFactory = $objectManager->create(ProductCustomOptionInterfaceFactory::class); | ||
|
||
foreach ($oldOptions as $option) { | ||
/** @var ProductCustomOptionInterface $option */ | ||
$option = $customOptionFactory->create(['data' => $option]); | ||
$option->setProductSku($product->getSku()); | ||
|
||
$options[] = $option; | ||
} | ||
|
||
$product->setOptions($options); | ||
|
||
/** @var ProductRepositoryInterface $productRepositoryFactory */ | ||
$productRepositoryFactory = $objectManager->create(ProductRepositoryInterface::class); | ||
$productRepositoryFactory->save($product); |
123 changes: 123 additions & 0 deletions
123
dev/tests/integration/testsuite/Magento/Checkout/Block/Cart/Item/RendererTest.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,123 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Checkout\Block\Cart\Item; | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\Framework\Api\SearchCriteriaBuilder; | ||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\Quote\Api\CartRepositoryInterface; | ||
use Magento\Quote\Model\Quote; | ||
use Magento\Quote\Model\Quote\Item; | ||
use PHPUnit\Framework\TestCase; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
/** | ||
* Class RendererTest | ||
* @package Magento\Checkout\Block\Cart\Item | ||
* @magentoAppArea frontend | ||
*/ | ||
class RendererTest extends TestCase | ||
{ | ||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var mixed | ||
*/ | ||
private $renderer; | ||
|
||
/** | ||
* @var mixed | ||
*/ | ||
public $productRepository; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->objectManager = Bootstrap::getObjectManager(); | ||
$this->renderer = $this->objectManager->get(Renderer::class); | ||
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class); | ||
} | ||
|
||
/** | ||
* Gets quote by reserved order id. | ||
* | ||
* @param string $reservedOrderId | ||
* @return Quote | ||
*/ | ||
private function getQuote($reservedOrderId) | ||
{ | ||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */ | ||
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class); | ||
$searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId) | ||
->create(); | ||
|
||
/** @var CartRepositoryInterface $quoteRepository */ | ||
$quoteRepository = $this->objectManager->get(CartRepositoryInterface::class); | ||
|
||
/** @var Quote[] $items */ | ||
$items = $quoteRepository->getList($searchCriteria)->getItems(); | ||
|
||
return $items[0]; | ||
} | ||
|
||
/** | ||
* Gets \Magento\Quote\Model\Quote\Item from \Magento\Quote\Model\Quote by product id | ||
* | ||
* @param Quote $quote | ||
* @param string|int $productId | ||
* | ||
* @return Item|null | ||
*/ | ||
private function _getQuoteItemIdByProductId($quote, $productId) | ||
{ | ||
/** @var $quoteItems Item[] */ | ||
$quoteItems = $quote->getAllItems(); | ||
foreach ($quoteItems as $quoteItem) { | ||
if ($productId == $quoteItem->getProductId()) { | ||
return $quoteItem; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* @magentoDataFixture Magento/Checkout/_files/cart_with_simple_product_and_custom_option_text_area.php | ||
*/ | ||
public function testTextAreaCustomOption() | ||
{ | ||
$quote = $this->getQuote('test_order_item_with_custom_option_text_area'); | ||
|
||
/** @var $product Product */ | ||
$product = $this->productRepository->get('simple_with_custom_option_text_area'); | ||
|
||
$quoteItem = $this->_getQuoteItemIdByProductId($quote, $product->getId()); | ||
$this->assertNotNull($quoteItem, 'Cannot get quote item for simple product with custom option text area'); | ||
|
||
$template = 'Magento_Checkout::cart/item/default.phtml'; | ||
$this->renderer->setTemplate($template); | ||
$this->renderer->setItem($quoteItem); | ||
|
||
$priceBlock = $this->objectManager->create(\Magento\Checkout\Block\Item\Price\Renderer::class); | ||
$this->renderer->getLayout()->setBlock('checkout.item.price.unit', $priceBlock); | ||
$this->renderer->getLayout()->setBlock('checkout.item.price.row', $priceBlock); | ||
$html = $this->renderer->toHtml(); | ||
|
||
$this->assertMatchesRegularExpression(<<<EOT | ||
/Test product simple with | ||
custom option text area | ||
with more 50 characters/ | ||
EOT | ||
, $html); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...estsuite/Magento/Checkout/_files/cart_with_simple_product_and_custom_option_text_area.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,52 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Catalog\Api\Data\ProductCustomOptionInterface; | ||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Catalog\Model\Product\Option; | ||
use Magento\Checkout\Model\Session; | ||
use Magento\Framework\DataObject; | ||
use Magento\Quote\Model\Quote; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver; | ||
|
||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_with_custom_option_text_area.php'); | ||
|
||
/** @var ProductRepositoryInterface $productRepository */ | ||
$productRepository = Bootstrap::getObjectManager() | ||
->create(ProductRepositoryInterface::class); | ||
$product = $productRepository->get('simple_with_custom_option_text_area'); | ||
|
||
$options = []; | ||
/** @var $option Option */ | ||
foreach ($product->getOptions() as $option) { | ||
switch ($option->getGroupByType()) { | ||
case ProductCustomOptionInterface::OPTION_GROUP_SELECT: | ||
$value = key($option->getValues()); | ||
break; | ||
default: | ||
$value = <<<EOT | ||
Test product simple with | ||
custom option text area | ||
with more 50 characters | ||
EOT; | ||
break; | ||
} | ||
$options[$option->getId()] = $value; | ||
} | ||
|
||
$requestInfo = new DataObject(['qty' => 1, 'options' => $options]); | ||
|
||
/** @var $cart \Magento\Checkout\Model\Cart */ | ||
$quote = Bootstrap::getObjectManager()->create(Quote::class); | ||
$quote->setReservedOrderId('test_order_item_with_custom_option_text_area'); | ||
$quote->addProduct($product, $requestInfo); | ||
$quote->save(); | ||
|
||
/** @var $objectManager \Magento\TestFramework\ObjectManager */ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
$objectManager->removeSharedInstance(Session::class); |