-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
32977 Fixed text area for Customizable Options on the Checkout Cart Page #33256
Merged
magento-engcom-team
merged 3 commits into
magento:2.4-develop
from
AZiniukhin:32977-Fix-Text-Area-for-Customizable-Options
Jul 29, 2021
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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); |
120 changes: 120 additions & 0 deletions
120
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,120 @@ | ||
<?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('/Test product simple with | ||
custom option text area | ||
with more 50 characters/', $html); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...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,50 @@ | ||
<?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 = 'Test product simple with | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that heredoc syntax looks more clear |
||
custom option text area | ||
with more 50 characters'; | ||
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); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that heredoc syntax looks more clear