Domanda

I wanted to display store name with item name on checkout page.

I am beginner in knockoutJs, please help me to solve this.

È stato utile?

Soluzione

You need to create plugin for add store name with each product. Follow this below steps and add code in appropriate file :

app/code/RH/CustomCheckout/etc/frontend/di.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Model\DefaultConfigProvider">
        <plugin name="rh-checkout-summary-modify" type="RH\CustomCheckout\Plugin\CheckoutSummaryModify" sortOrder="10" />
    </type>
</config>

app/code/RH/CustomCheckout/Plugin/CheckoutSummaryModify.php

<?php

namespace RH\CustomCheckout\Plugin;

class CheckoutSummaryModify {

    /**
     * @var \Magento\Store\Model\StoreManagerInterface
     */
    protected $storeManager;

    /**
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
     */
    public function __construct(
        \Magento\Store\Model\StoreManagerInterface $storeManager
    ) {
        $this->storeManager = $storeManager;
    }
    public function afterGetConfig(\Magento\Checkout\Model\DefaultConfigProvider $subject, $result) {
        $items = $result['totalsData']['items'];
        foreach ($items as $key => $value) {
            $items[$key]['storeName'] = $this->storeManager->getStore()->getName();
        }
        $result['totalsData']['items'] = $items;
        return $result;
    }
}
?>

Now, copy file from

vendor/magento/module-checkout/view/frontend/web/template/summary/item/details.html

And add at this below path :

app/design/frontend/Vendor/YourTheme/Magento_Checkout/web/template/summary/item/details.html

Now, Add this below line :

<strong class="store-name" data-bind="text: $parent.storeName"></strong>

after this line :

<strong class="product-item-name" data-bind="text: $parent.name"></strong>

Deploy files and clean cache.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top