0

My goal is to switch out the .phtml files: magento_module-wee::item/price/unit.phtml as well as magento_module-wee::item/price/row.phtml with my own custom ones and change how the prices are displayed in the cart.

My approach so far was to use: app\code\Vendor\Module\view\frontend\layout\checkout_item_price_renderers.xml

<?xml version="1.0" encoding="UTF-8"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceBlock name="checkout.item.price.unit">
        <arguments>
            <argument name="template" xsi:type="string">Vendor_Module::item/price/unit.phtml</argument>
        </arguments>
    </referenceBlock>
    <referenceBlock name="checkout.item.price.row"> 
        <arguments>
            <argument name="template" xsi:type="string">Vendor_Module::item/price/row.phtml</argument>
        </arguments>
    </referenceBlock>
</page>

Edit2: NOTE! The code above should work but does NOT (as I just found out). <action method="setTemplate"> (which is deprecated) has to be used (until the above code works as advertised) aparently.

And have the custom row.phtml as well as unit.phtml located at: app\code\Vendor\Module\view\frontend\templates\item\price\

I also tried to change <arguments> to <action method="setTemplate">, but whatever I tried so far - the "vanilla" module (module-weee) and its phtml file versions are used.

Any ideas how to get my phtml files rendered instead?

Edit1: Reading Hit's answer, I realized that I should probably post my entire module, not only the part, where I believe the fault lies. Sorry for my posting inexperience!

app\code\Vendor\Module\etc\module.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Module" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Checkout"/>
            <module name="Magento_Weee"/>
        </sequence>
    </module>
</config>

app\code\Vendor\Module\registration.php:

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE, 
    'Vendor_Module',
    __DIR__
);

app\code\Vendor\Module\composer.json:

{
    "name": "vendor/module",
    "description": "Description",
    "type": "magento2-module",
    "version": "1.0.0",
    "require": {
        "php": ">=7.0.13|>=7.1.1",
        "magento/framework": "101.0.*"
    },
    "repository": {
        "type": "composer",
        "url": "https://repo.magento.com/"
    },
    "minimum-stability": "stable",
    "autoload": {
        "files": [
          "registration.php"
        ],
        "psr-4": {
            "Vendor\\Module\\": ""
        }
    }
}
0

follow below steps.

step 1) create a custom module if not create like Vendor/Frontendsample

2) create registration.php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor_Frontendsample',
    __DIR__
);

3) create module.xml under etc folder

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Vendor_Frontendsample" setup_version="1.0.0"></module>
        <sequence>
            <module name="Magento_Checkout"/>
        </sequence>
</config>

4) create checkout_item_price_renderers.xml under Vendor/Frontendsample/view/frontend/layout/

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="checkout.item.price.unit">
            <arguments>
                <argument name="template" xsi:type="string">Vendor_Frontendsample::item/price/unit.phtml</argument>
            </arguments>
    </referenceBlock>
    <referenceBlock name="checkout.item.price.row">
            <arguments>
                <argument name="template" xsi:type="string">Vendor_Frontendsample::item/price/row.phtml</argument>
            </arguments>
    </referenceBlock>
    </body>
</page>

5) paste row.phtml and unit.phtml files under Vendor/Frontendsample/view/frontend/templates/item/price/ from core folder vendor/magento/module-weee/view/frontend/templates/item/price

6) run this command php bin/magento setup:upgrade && php bin/magento setup:static-content:deploy -f

you can take reference code from here

  • Thank you for your suggestion! Your version uses <action> instead of argument and forces a Magento_Checkout in sequence (I tried to sequence Magento_weee). But apart from that they are indentical - and do not work. – Tamashii Oct 3 '18 at 12:24
  • you can also use <arguments> instead of <action> see my updated answer – Hitesh Oct 3 '18 at 12:36
  • The phtml rendered is still: vendor/magento/module-weee/view/frontend/templates/item/price/unit.phtml - our modules are basically the same, but do not seem to work. – Tamashii Oct 3 '18 at 12:43
  • which Magento version are you using? did you run basic commands of Magento like php bin/magento setup:upgrade && php bin/magento setup:static-content:deploy -f is your module listed in etc/config.xml? did you got any error in log/exception.log or system.log? might be you missed something small, As I have tested in magento 2.2.6 – Hitesh Oct 3 '18 at 12:46
  • You are right! I did not run the "php bin/magento setup:static-content:deploy -f" as my magento cli told me that it (php bin/magento setup:static-content:deploy) is unnecessary in developer mode - BUT - now it works! Thank you! – Tamashii Oct 3 '18 at 12:52

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.