Post by zoe » Fri Nov 15, 2024 10:17 am

Hey there,
I am using 3.0.2.0
I have made an XML file to display an * sign after the price in product/category
and to show text below the price.
The text has to change to German when this language is selected. But it will not work.
I am not a pro, so well explained help would be much appreciated ;)

Here is my code:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Add Delivery Time Below Price</name>
    <code>add-delivery-time-below-price</code>
    <version>1.0</version>
    <author>me</author>
    <link></link>
    <file path="catalog/view/theme/*/template/product/category.twig">
        <operation>
            <search><![CDATA[{{ price }}]]></search>
            <add position="after"><![CDATA[ 
                <div style="font-size: 7pt; margin-top: 5px;">
                    {% if session.language == 'de' %}
                        Lieferzeit (DE): 14 Werktage**
                    {% else %}
                        Delivery Time (DE): 14 working days**
                    {% endif %}
                </div>
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[{{ price }}]]></search>
            <add position="after"><![CDATA[ * ]]></add>
        </operation>
    </file>
</modification>
Last edited by zoe on Sat Nov 16, 2024 6:56 pm, edited 1 time in total.

zoe
Newbie

Posts

Joined
Fri Nov 15, 2024 10:00 am

Post by OSWorX » Fri Nov 15, 2024 4:37 pm

Hello zoe,

welcome to the forum.

Question: where do you have defined this variable: session.language
As long as you have that not defined, the check will never work ..

Beside of this: do not use the 3.0.2.0 version, instead use 3.0.4.0 https://github.com/opencart/opencart/re ... ag/3.0.4.0 and use php 8.x

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by paulfeakins » Fri Nov 15, 2024 8:33 pm

zoe wrote:
Fri Nov 15, 2024 10:17 am
it will not work.
Yes I can tell you're not a pro because you haven't given us any information about what actually happens. Presumably nothing at all? Have you cleared all the caches? https://www.antropy.co.uk/blog/how-to-c ... t-3-0-2-0/

Anyway the second modification looks pretty strange, I'd remove that one.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by nonnedelectari » Fri Nov 15, 2024 8:38 pm

zoe wrote:
Fri Nov 15, 2024 10:17 am
Hey there,
I am using 3.0.2.0
I have made an XML file to display an * sign after the price in product/category
and to show text below the price.
The text has to change to German when this language is selected. But it will not work.
I am not a pro, so well explained help would be much appreciated ;)
Link to my website: https://www.bases-and-more.com/-Fantasy ... esin-Bases

Here is my code:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Add Delivery Time Below Price</name>
    <code>add-delivery-time-below-price</code>
    <version>1.0</version>
    <author>me</author>
    <link></link>
    <file path="catalog/view/theme/*/template/product/category.twig">
        <operation>
            <search><![CDATA[{{ price }}]]></search>
            <add position="after"><![CDATA[ 
                <div style="font-size: 7pt; margin-top: 5px;">
                    {% if session.language == 'de' %}
                        Lieferzeit (DE): 14 Werktage**
                    {% else %}
                        Delivery Time (DE): 14 working days**
                    {% endif %}
                </div>
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[{{ price }}]]></search>
            <add position="after"><![CDATA[ * ]]></add>
        </operation>
    </file>
</modification>
1) Not handy to put actual hardcoded language in twig files, or any files (except for the language files) for that matter.
2) is "session" an array variable you pass from the controller to the view?

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by OSWorX » Fri Nov 15, 2024 9:12 pm

General this could be achieved very easy with an event.
No need to use OCMod (or anything else).

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by zoe » Fri Nov 15, 2024 9:44 pm

Thanks for your answers.

Now I have separate XML for * after price in product/category:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Add Delivery Time Below Price</name>
    <code>add-delivery-time-below-price</code>
    <version>1.0</version>
    <author>me</author>
    <link></link>
    <file path="catalog/view/theme/*/template/product/category.twig">
        <operation>
         
            <search><![CDATA[{{ price }}]]></search>
            <add position="after"><![CDATA[ * ]]></add>
        </operation>
    </file>
</modification>
And one for the text below price with language function product/category:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Sprache wechseln und Lieferzeit anzeigen</name>
    <code>language-switch-delivery-time</code>
    <version>1.0</version>
    <author>Me</author>
    <link></link>
    
    <file path="catalog/controller/product/category.php">
        <operation>
            <search><![CDATA[$this->response->setOutput($this->load->view('product/category', $data));]]></search>
            <add position="before"><![CDATA[
                // Sprache auf Deutsch setzen, wenn der Nutzer es auswählt
                if (isset($this->session->data['language']) && $this->session->data['language'] == 'de-de') {
                    $data['delivery_time'] = 'Lieferzeit (DE): 14 Werktage**';
                } else {
                    $data['delivery_time'] = 'Delivery Time (DE): 14 working days**';
                }
            ]]></add>
        </operation>
    </file>
    
    <file path="catalog/view/theme/default/template/product/category.twig">
        <operation>
            <search><![CDATA[{{ price }}]]></search>
            <add position="after"><![CDATA[
                <div style="font-size: 7pt; margin-top: 5px;">
                    {{ delivery_time }}
                </div>
            ]]></add>
        </operation>
    </file>
</modification>
It works so far.

zoe
Newbie

Posts

Joined
Fri Nov 15, 2024 10:00 am

Post by nonnedelectari » Fri Nov 15, 2024 9:59 pm

Putting hardcoded language in the controller is also not handly, language files are there for a reason.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm
Who is online

Users browsing this forum: No registered users and 18 guests