1

I have been making modifications to an existing Magento project. I want to add custom attribute to the product in Checkout page's order summary section. For this, I created a plugin following the answer in Magento2 - How can I display a product attribute value in Order Summary block? enter image description here

After page load completes my custom attribute is not present. enter image description here

Please help me to solve this issue.

Thanks in advance.....!

Below is my magento2 Code

di.xml

enter image description here

Module.xml

enter image description here

ConfigProviderPlugin.php


<?php

namespace Custom\Checkout\Plugin;

class ConfigProviderPlugin extends \Magento\Framework\Model\AbstractModel
{

    public function afterGetConfig(\Magento\Checkout\Model\DefaultConfigProvider $subject, array $result)
    {

        $items = $result['totalsData']['items'];

        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        for($i=0;$i<count($items);$i++){
            $qty = $items[$i]['qty'];

            $quoteId = $items[$i]['item_id'];
            $quote = $objectManager->create('\Magento\Quote\Model\Quote\Item')->load($quoteId);
            $productId = $quote->getProductId();
            $product = $objectManager->create('\Magento\Catalog\Model\Product')->load($productId);
            $box_per_lens = $product->getResource()->getAttribute('box_per_lens')->getFrontend()->getValue($product);   
            $use_quantity_type = $product->getResource()->getAttribute('use_quantity_type')->getFrontend()->getValue($product);
            $quantity_type = $product->getResource()->getAttribute('quantity_type')->getFrontend()->getValue($product);         
            $quantity_type1 ='';
            $box_per_lens1 ='';
            $qData = '';
            if($use_quantity_type == 'No' || $use_quantity_type == 'NA'){
               $quantity_type1='Quantity';
               $qData = $qty.' '.$quantity_type1;

            }else{
                if($quantity_type == 'No' || $quantity_type == 'NA'){

                   $quantity_type1 ='';
                }else{
                     $quantity_type1 = $quantity_type;
                }
                if($box_per_lens == 'No' || $box_per_lens == 'NA'){
                    $box_per_lens1 = "";
                     $qData = $qty.' '.$quantity_type1;
                 }
                 else{
                     $box_per_lens1  = $box_per_lens;
                      $qData = $qty.' '.$quantity_type1.'('.($qty*$box_per_lens1).' lenses)';
                 }

            }


            $items[$i]['flavor'] = "call66";
            $items[$i]['qtyData'] = $qData;
        } 


        $result['totalsData']['items'] = $items;
        return $result;
    }

}

details.html

Override location: app/design/frontend/Theme/luma/Mageplaza_Osc/web/template/container/summary/item/details.html

<td class="a-left product ">


    <div class="product-item-detail">
        <div class="product-item-inner">
            <div class="product-item-name-block">
                <!-- ko if: getProductUrl($parent) -->
                <a data-bind="attr:{href: getProductUrl($parent)}" target="_blank">
                    <strong class="product-item-name" data-bind="text: $parent.name"></strong>
                </a>
                <!-- /ko -->
                <!-- ko ifnot: getProductUrl($parent)-->
                <strong class="product-item-name" data-bind="text: $parent.name"></strong>
                <!-- /ko -->
                <!-- <span class="product-item-qty" data-bind="text: $parent.qty"></span> -->
                <span class="product-item-qtyData" data-bind="text: $parent.qtyData"></span>
            </div>
        </div>

    </div>

    <!-- ko if: isItemAvailable($parent.item_id) -->
    <div class="gift-message-item-content">
        <div class="gift-message-item" data-bind="attr: { id: 'item' +$parent.item_id, title: giftMessageItemsTitleHover},click: loadGiftMessageItem.bind($data,$parent.item_id)">
            <i class="fa fa-gift fa-2x" aria-hidden="true"></i>
        </div>
        <div style="display: none" data-bind="attr: { id: 'item' + $parent.item_id,title: $parent.name},afterRender: setModalElement">
            <div class="gift-options-content">
                <div class="fieldset">
                    <div class="field field-from col-mp mp-6">
                        <!-- ko ifnot: window.checkoutConfig.oscConfig.isUsedMaterialDesign -->
                        <label for="gift-message-whole-from" class="label">
                            <span data-bind="i18n: 'From:'"></span>
                        </label>
                        <!-- /ko -->
                        <div class="control input-field">
                            <input type="text" id="gift-message-whole-from" class="input-text" required>
                            <!-- ko if: window.checkoutConfig.oscConfig.isUsedMaterialDesign -->
                            <label for="gift-message-whole-from" class="label">
                                <span data-bind="i18n: 'From:'"></span>
                            </label>
                            <!-- /ko -->
                        </div>
                    </div>
                    <div class="field field-to col-mp mp-6">
                        <!-- ko ifnot: window.checkoutConfig.oscConfig.isUsedMaterialDesign -->
                        <label for="gift-message-whole-to" class="label">
                            <span data-bind="i18n: 'To:'"></span>
                        </label>
                        <!-- /ko -->
                        <div class="control input-field">
                            <input type="text" id="gift-message-whole-to" class="input-text" required>
                            <!-- ko if: window.checkoutConfig.oscConfig.isUsedMaterialDesign -->
                            <label for="gift-message-whole-to" class="label">
                                <span data-bind="i18n: 'To:'"></span>
                            </label>
                            <!-- /ko -->
                        </div>
                    </div>
                    <div class="field text col-mp mp-12">
                        <!-- ko ifnot: window.checkoutConfig.oscConfig.isUsedMaterialDesign -->
                        <label for="gift-message-whole-message" class="label">
                            <span data-bind="i18n: 'Message:'"></span>
                        </label>
                        <div class="control">
                            <textarea id="gift-message-whole-message" class="input-text" rows="5" cols="10"></textarea>
                        </div>
                        <!-- /ko -->
                        <!-- ko if: window.checkoutConfig.oscConfig.isUsedMaterialDesign -->
                        <div class="control">
                            <textarea id="gift-message-whole-message" class="input-text" rows="3" cols="10" data-bind="attr:{placeholder: $t('Message')}"></textarea>
                        </div>
                        <!-- /ko -->
                    </div>
                </div>
            </div>
            <div class="actions-toolbar">
                <div class="primary">
                    <button type="submit" name="update" class="action update"  data-bind="click: updateGiftMessageItem.bind($data,$parent.item_id)">
                        <span data-bind="i18n: 'Update'"></span>
                    </button>
                </div>
                <div class="primary">
                    <button type="submit" name="delete" class="action delete" data-bind="click: deleteGiftMessageItem.bind($data,$parent.item_id)">
                        <span data-bind="i18n: 'Delete'"></span>
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!-- /ko -->
</td>
<!-- <td class="a-center details-qty">
    <div class="qty-wrapper">
        <a href="javascript:void(0);" class="button-action minus" data-bind="click: minusQty" title="Minus"></a>
        <div class="qty-wrap">
            <input class="item_qty input-text update value" name="item_qty"  data-bind="value: $parent.qty, attr: {id: $parent.item_id}, event: {change: changeQty}" />
        </div>
        <a href="javascript:void(0);" class="button-action plus" data-bind="click: plusQty" title="Plus"></a>
    </div>
</td> -->
<td class="a-center subtotal">
    <!-- ko foreach: getRegion('after_details') -->
    <!-- ko template: getTemplate() --><!-- /ko -->
    <!-- /ko -->
</td>
<td class="a-center last button-remove">
    <div class="remove-wrapper">
        <a href="javascript:void(0);" class="button-action remove" data-bind="click:function(){removeItem($parent.item_id)}"></a>
    </div>
</td>
5
  • Can you guys please help me?
    – appy
    Nov 25, 2017 at 13:08
  • Post your code to check the problem. Nov 25, 2017 at 13:12
  • I have posted code in above Question...
    – appy
    Nov 25, 2017 at 13:35
  • Please check...
    – appy
    Nov 25, 2017 at 13:37
  • How did you solve this issue? I am also facing the same issue ..
    – aravind
    Feb 22, 2019 at 5:39

1 Answer 1

0

I am also facing the same issue, Am trying to get the product short description. It appears while loading and disappears after it fully loaded.

Below is my plugin function

public function afterGetConfig(\Magento\Checkout\Model\DefaultConfigProvider $subject, array $result){

    $items = $result['totalsData']['items'];

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

    for($i=0;$i<count($items);$i++){

        $quoteId = $items[$i]['item_id'];
        $quote = $objectManager->create('\Magento\Quote\Model\Quote\Item')->load($quoteId);
        $productId = $quote->getProductId();
        $product = $objectManager->create('\Magento\Catalog\Model\Product')->load($productId);
        $productShortDesc = $product->getShortDescription();        

        $items[$i]['product_shortdesc'] = $productShortDesc;

    }
    $result['totalsData']['items'] = $items;
        return $result;
}

In details.html Am calling using data-bind

 <span class="product-desc" data-bind="html: $parent.product_shortdesc"></span>

Did anyone find the solution for this?

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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