From f724fece9f6704af67ca2a14ffe3c8d5adf38e7e Mon Sep 17 00:00:00 2001 From: AZiniukhin Date: Wed, 16 Jun 2021 11:30:46 +0300 Subject: [PATCH 1/3] 32977 Fixed text area for Customizable Options on the Checkout Cart Page --- .../Checkout/view/frontend/templates/cart/item/default.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Checkout/view/frontend/templates/cart/item/default.phtml b/app/code/Magento/Checkout/view/frontend/templates/cart/item/default.phtml index 6a0be41151e80..c590d9419cf99 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/cart/item/default.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/cart/item/default.phtml @@ -48,7 +48,7 @@ $canApplyMsrp = $helper->isShowBeforeOrderConfirm($product) && $helper->isMinima
escapeHtml($_option['label']) ?>
- escapeHtml($_formatedOptionValue['full_view']) ?> + escapeHtml($_formatedOptionValue['full_view'], ['span', 'a']) ?> escapeHtml($_formatedOptionValue['value'], ['span', 'a']) ?> From a3bf2977c53b96de2a5ab271624b90a7ec4dcac1 Mon Sep 17 00:00:00 2001 From: AZiniukhin Date: Fri, 25 Jun 2021 10:51:31 +0300 Subject: [PATCH 2/3] 32977 Added test --- ...ct_simple_with_custom_option_text_area.php | 83 ++++++++++++ .../Checkout/Block/Cart/Item/RendererTest.php | 120 ++++++++++++++++++ ...le_product_and_custom_option_text_area.php | 50 ++++++++ 3 files changed, 253 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_custom_option_text_area.php create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/Block/Cart/Item/RendererTest.php create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/cart_with_simple_product_and_custom_option_text_area.php diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_custom_option_text_area.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_custom_option_text_area.php new file mode 100644 index 0000000000000..12b82f13d6c7f --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_custom_option_text_area.php @@ -0,0 +1,83 @@ +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 html tag') + ->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); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/Block/Cart/Item/RendererTest.php b/dev/tests/integration/testsuite/Magento/Checkout/Block/Cart/Item/RendererTest.php new file mode 100644 index 0000000000000..41cdb6067c31a --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/Block/Cart/Item/RendererTest.php @@ -0,0 +1,120 @@ +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); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/cart_with_simple_product_and_custom_option_text_area.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/cart_with_simple_product_and_custom_option_text_area.php new file mode 100644 index 0000000000000..c22affb358c6d --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/cart_with_simple_product_and_custom_option_text_area.php @@ -0,0 +1,50 @@ +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 +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); From b506bb4a357b53c35176ca9e175de53144110623 Mon Sep 17 00:00:00 2001 From: AZiniukhin Date: Fri, 25 Jun 2021 13:50:47 +0300 Subject: [PATCH 3/3] 32977 Added heredoc syntax --- .../Magento/Checkout/Block/Cart/Item/RendererTest.php | 7 +++++-- ...art_with_simple_product_and_custom_option_text_area.php | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Checkout/Block/Cart/Item/RendererTest.php b/dev/tests/integration/testsuite/Magento/Checkout/Block/Cart/Item/RendererTest.php index 41cdb6067c31a..1a9f00b06ac7a 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/Block/Cart/Item/RendererTest.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/Block/Cart/Item/RendererTest.php @@ -113,8 +113,11 @@ public function testTextAreaCustomOption() $this->renderer->getLayout()->setBlock('checkout.item.price.row', $priceBlock); $html = $this->renderer->toHtml(); - $this->assertMatchesRegularExpression('/Test product simple with + $this->assertMatchesRegularExpression(<<getValues()); break; default: - $value = 'Test product simple with + $value = <<getId()] = $value;