14

How can we override this position in custom option to show it in another phtml file. enter image description here

added this code in checkout_cart_index.xml which override only the form.phtml not override the default.phtml file.

  <?xml version="1.0"?>
  <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<!-- <update handle="checkout_cart_item_renderers"/> -->
<body>
    <referenceContainer name="content">
        <referenceBlock name="checkout.cart.form">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Bespoke_Bespoke::cart/form.phtml</argument>
            </action>
    </referenceBlock> 
     <referenceBlock name="checkout.cart.item.renderers.override">
    <action method="setTemplate">
        <argument name="template" xsi:type="string">Bespoke_Bespoke::cart/item/default.phtml</argument>
    </action>
</referenceBlock>
    </referenceContainer>
</body>

i am getting error regarding the checkout.cart.item.renderers already has a child with alias 'simple' i have modify that file of checkout_cart_item_renderer.xml

 <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<!-- <update handle="checkout_item_price_renderers"/> -->
<body>
  <referenceBlock name="checkout.cart.form">
<action method="setOverriddenTemplates">
    <argument xsi:type="array">
        <!-- list override templates -->
        <item name="default" xsi:type="string">Bespoke_Bespoke::cart/item/default.phtml</item>
        <item name="simple" xsi:type="string">Bespoke_Bespoke::cart/item/default.phtml</item>
        <item name="virtual" xsi:type="string">Bespoke_Bespoke::cart/item/default.phtml</item>
    </argument>
  </action>
  </referenceBlock>
</body>
</page>

to override the file we useed etc/di.xml

 <config  xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
   <preference for="Magento\Checkout\Block\Cart\AbstractCart" type="AGS\Bespoke\Block\Checkout\Cart\AbstractCart"/><preference for="Magento\Catalog\Block\Product\View\Option" type="AGS\Bespoke\Block\Product\View\Option"/>
   <preference for=" Magento\Checkout\Block\Cart" type="AGS\Bespoke\Block\Checkout\Cart"/>
   <preference for="\Magento\Checkout\Block\Cart\Item\Renderer" type="AGS\Bespoke\Block\Checkout\Cart\Item\Renderer"/>
   <virtualType name="AGS\Bespoke\Model\ResourceModel\Bespoke\Bespoke\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">     
  <arguments><argument name="mainTable" xsi:type="string">ags_bespoke</argument><argument name="resourceModel" xsi:type="string">AGS\Bespoke\Model\ResourceModel\Bespoke</argument> 

  </arguments></virtualType><type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
<arguments><argument name="collections" xsi:type="array">
<item name="bespoke_record_bespoke_list_data_source" xsi:type="string">AGS\Bespoke\Model\ResourceModel\Bespoke\Bespoke\Collection</item>

  • remove the block in product detail page. add it in other page – Visakh B Sujathan Apr 12 '17 at 6:15
  • 3
    What are you trying to achieve? Because correct me if I'm wrong, but you need the options in order to be able to add the product to the cart in the first place. You cannot add a product with required options to the cart first, and select the options later. – Giel Berkers Apr 13 '17 at 9:30
5

Put the code in any other phtml page in product collection

custome option willl show on dropdown , select , multiselect , etc...

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$_productCollection = $block->getLoadedProductCollection();
?>
<?php foreach ($_productCollection as $_product): ?>
<?php
    $_product = $objectManager->create('Magento\Catalog\Model\Product')->load($_product->getId());
    $customOptions = $objectManager->get('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($_product); 
?>
  <?php 
    foreach($customOptions as $option){
      $values = $option->getValues();
      if (empty($values)) { 
          continue;
      } ?>
      <div class="custome-option">
          <?php foreach($values as $value) :  ?>
              <span><?php echo $value->getTitle(); ?></span>
          <?php endforeach; ?>
      </div>
  <?php }; ?>
<?php endforeach; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.