Post by Majnoon » Sun Jul 11, 2021 7:39 pm

straightlight wrote:
Sun Jul 11, 2021 6:58 pm
What did you use in cart.twig file call it?
This

Code: Select all

<script>
  gtag('event', 'add_to_cart', {
    'send_to': 'AW-xxxxxxxxxx',
    'value': '{{price}}',
    'items': [{
      'id': '{{ product.product_id }}',
      'google_business_vertical': 'retail'
    }]
  });
</script>

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by by mona » Sun Jul 11, 2021 9:00 pm

straightlight wrote:
Fri Jul 09, 2021 11:25 pm
Then, to use: {{ product.quantity }} and {{ product.product_id }} in cart.twig file.
Majnoon wrote:
Sat Jul 10, 2021 1:30 am
So how we will pull the price then?
straightlight wrote:
Sat Jul 10, 2021 1:46 am
Same way as the product ID and the quantity.
Majnoon wrote:
Sun Jul 11, 2021 7:39 pm

Code: Select all

<script>
 gtag('event', 'add_to_cart', {
 'send_to': 'AW-xxxxxxxxxx',
 'value': '{{price}}',
 'items': [{
 'id': '{{ product.product_id }}',
 'google_business_vertical': 'retail'
 }]
 });
</script>
straightlight wrote:
Sat Jul 10, 2021 1:26 am
Instructions unfollowed with TWIG file. Read the above again.
does

Code: Select all

{{price}}
look the same as

Code: Select all

{{product.product_id}}

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by Majnoon » Sun Jul 11, 2021 11:40 pm

by mona wrote:
Sun Jul 11, 2021 9:00 pm
does

Code: Select all

{{price}}
look the same as

Code: Select all

{{product.product_id}}
I don't think so it can be the same as

Code: Select all

{{product.product_id}}
Since earlier @striaghtlight added extra line into common/controller/cart.php

Code: Select all

'product_id'=> $product['product_id'],
and then used in twig

Code: Select all

{{product.product_id}}
But as for price
there is already

Code: Select all

'price'     => $price,
So that's why the question was to him why price is not populating into twig?

Also there is one more question even the

Code: Select all

{{product.product_id}}
unless refresh the page twice.

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by straightlight » Mon Jul 12, 2021 5:31 pm

The array is product. It's no different than product ID and quantity. {{ product.price }}.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Majnoon » Mon Jul 12, 2021 7:52 pm

straightlight wrote:
Mon Jul 12, 2021 5:31 pm
The array is product. It's no different than product ID and quantity. {{ product.price }}.
Thanks @straightlight.
Will the same code work on category.twig

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by straightlight » Mon Jul 12, 2021 7:56 pm

Majnoon wrote:
Mon Jul 12, 2021 7:52 pm
straightlight wrote:
Mon Jul 12, 2021 5:31 pm
The array is product. It's no different than product ID and quantity. {{ product.price }}.
Thanks @straightlight.
Will the same code work on category.twig
Including the changes in category.php controller file, yes.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Majnoon » Mon Jul 12, 2021 9:05 pm

straightlight wrote:
Mon Jul 12, 2021 7:56 pm
Including the changes in category.php controller file, yes.
I have made the changes as suggested.
will there be files (cart.php & cart.twig) in the storage/modification?

As i am seeing only modification file for cart.php but not for theme. ???

I have refresh the cache and modifications though.

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by straightlight » Mon Jul 12, 2021 9:07 pm

Majnoon wrote:
Mon Jul 12, 2021 9:05 pm
straightlight wrote:
Mon Jul 12, 2021 7:56 pm
Including the changes in category.php controller file, yes.
I have made the changes as suggested.
will there be files (cart.php & cart.twig) in the storage/modification?

As i am seeing only modification file for cart.php but not for theme. ???

I have refresh the cache and modifications though.
Which is why, it is best to keep things simple by creating an extension for this rather than playing with core files.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Majnoon » Mon Jul 12, 2021 9:15 pm

straightlight wrote:
Mon Jul 12, 2021 9:07 pm
Which is why, it is best to keep things simple by creating an extension for this rather than playing with core files.
Alright will convert it to XML and upload and report back.

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by Majnoon » Tue Jul 13, 2021 9:31 am

straightlight wrote:
Mon Jul 12, 2021 9:07 pm
Which is why, it is best to keep things simple by creating an extension for this rather than playing with core files.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<modification>
    <name>Google ads event</name>
    <version>1.0.0</version>
    <author>straightlight</author>
    <link>https://forum.opencart.com/</link>
    <code>GAE</code>
    <file path="catalog/controller/common/cart.php">
        <operation>
            <search><![CDATA['cart_id'   => $product['cart_id'],]]></search>
            <add position="after"><![CDATA['product_id'=> $product['product_id'],]]></add>
        </operation>
    </file>
    <file path="catalog/view/theme/default/template/common/cart.twig">
    	<operation>
    		<search><![CDATA[<div id="cart" class="btn-group btn-block">]]></search>
    		<add position="before"><![CDATA[<script>
  gtag('event', 'add_to_cart', {
    'send_to': 'AW-xxxxxxxxx,
    'value': '{{product.price}}',
    'items': [{
      'id': '{{ product.product_id }}',
      'google_business_vertical': 'retail'
    }]
  });
</script>
    		]]></add>
    	</operation>
    </file>
</modification>
I have added the code via modification.

@straightlight just a question will this code works for journal user as well?

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by straightlight » Tue Jul 13, 2021 5:38 pm

@straightlight just a question will this code works for journal user as well?
Not supported on the forum

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Majnoon » Thu Jul 15, 2021 9:44 pm

straightlight wrote:
Tue Jul 13, 2021 5:38 pm
Not supported on the forum
Noted with thanks!

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm
Who is online

Users browsing this forum: Bing [Bot], shanghua and 463 guests