Post by elliotjohn » Fri Jan 17, 2020 1:09 am

Hi there,

I'm currently using OC Version 3.0.2.0

I would like to know how to show a specific (image) BEFORE THE PRODUCT NAME in each product page if the product weight = 0 ?

Like : If product.weight = 0 then show ("https://www.xyz.com/image/image.png")

I am not very good in PHP so I ask some help.
I would like a MOD so the original file will be intact if possible.

Thanks for taking the time reading me.

Regards
Last edited by elliotjohn on Fri Jan 17, 2020 4:18 pm, edited 1 time in total.

Newbie

Posts

Joined
Sun Jan 05, 2020 5:10 am

Post by straightlight » Fri Jan 17, 2020 4:52 am

I am not very good in PHP so I ask some help.
Since you're only looking to show a generic PNG image before the image name, no PHP skill is needed. You could simply edit your catalog/view/theme/<your_custom_theme>/template/product/product.twig file by adding your image src link to your PNG file whenever the quantity is 0. Then, to follow this FAQ: viewtopic.php?f=176&t=200804#p718325

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member

Posts

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

Post by elliotjohn » Fri Jan 17, 2020 5:08 am

straightlight wrote:
Fri Jan 17, 2020 4:52 am
Since you're only looking to show a generic PNG image before the image name, no PHP skill is needed. You could simply edit your catalog/view/theme/<your_custom_theme>/template/product/product.twig file by adding your image src link to your PNG file whenever the quantity is 0. Then, to follow this FAQ: viewtopic.php?f=176&t=200804#p718325
1) I'm not looking to show a PNG before the image name but before the product name.
2) I would like to show a "free delivery png" when the product weight is = 0 or if the weight is not defined.

So if the product weight = 0 show FreeShipping.png

The FAQ you send me is irrelevant to my problem because this post is dedicated to :
- Show to the customer the weight & size of the product ( I don't need to)
- For OpenCart 2

Regards

Newbie

Posts

Joined
Sun Jan 05, 2020 5:10 am

Post by letxobnav » Fri Jan 17, 2020 11:49 am

Default the product weight is not mapped from the controller to the view so you would have to add that mapping first.

Code: Select all

$data['weight'] = $product_info['weight'];
Then you can add the conditional display of your image to the view

Code: Select all

{% if weight == 0 %}{{ <img src="path/FreeShipping.png"> }}{% endif %}
or (I always like to keep business logic out of the view and in the controller) in the controller

Code: Select all

$data['free_shipping'] = false;
if ($product_info['weight'] == 0) {
   $data['free_shipping'] = true;
   $data['free_shipping_indicator'] = '<img src="path/FreeShipping.png">';
}
and in the view

Code: Select all

{% if free_shipping %}{{ free_shipping_indicator }}{% endif %}
before

Code: Select all

<h1>{{ heading_title }}</h1>
just wondering, you have products requiring shipping with zero weight or are you just using that as a trick to facilitate free shipping?

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Active Member
Online

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by elliotjohn » Fri Jan 17, 2020 12:07 pm

letxobnav wrote:
Fri Jan 17, 2020 11:49 am
Default the product weight is not mapped from the controller to the view so you would have to add that mapping first.

Code: Select all

$data['weight'] = $product_info['weight'];
Then you can add the conditional display of your image to the view

Code: Select all

{% if weight == 0 %}{{ <img src="path/FreeShipping.png"> }}{% endif %}
or (I always like to keep business logic out of the view and in the controller) in the controller

Code: Select all

$data['free_shipping'] = false;
if ($product_info['weight'] == 0) {
   $data['free_shipping'] = true;
   $data['free_shipping_indicator'] = '<img src="path/FreeShipping.png">';
}
and in the view

Code: Select all

{% if free_shipping %}{{ free_shipping_indicator }}{% endif %}
before

Code: Select all

<h1>{{ heading_title }}</h1>
just wondering, you have products requiring shipping with zero weight or are you just using that as a trick to facilitate free shipping?
Hi letxobnav,

Thanks for the reply and the help with your code, but may I ask you what file must be modified with your code and where inside the file?
The answer to your question: it's a trick to facilitate free shipping ;o)

UPDATE 20 Minutes After:

I managed to place the code in catalog\view\theme\default\template\product\product.twig like this:

Code: Select all

          </div>
		  {% if weight == 0 %}
		  { <img src="image/shipping_logo_chronopost.png"> }
		  {% endif %}
		  {% if free_shipping %}
		  { free_shipping_indicator }
		  {% endif %}
          <h1>{{ heading_title }}</h1>

Concerning \catalog\controller\product\product.php
Where must I place the code?

Thanks

Newbie

Posts

Joined
Sun Jan 05, 2020 5:10 am

Post by elliotjohn » Fri Jan 17, 2020 12:59 pm

elliotjohn wrote:
Fri Jan 17, 2020 12:07 pm
letxobnav wrote:
Fri Jan 17, 2020 11:49 am
Default the product weight is not mapped from the controller to the view so you would have to add that mapping first.

Code: Select all

$data['weight'] = $product_info['weight'];
Then you can add the conditional display of your image to the view

Code: Select all

{% if weight == 0 %}{{ <img src="path/FreeShipping.png"> }}{% endif %}
or (I always like to keep business logic out of the view and in the controller) in the controller

Code: Select all

$data['free_shipping'] = false;
if ($product_info['weight'] == 0) {
   $data['free_shipping'] = true;
   $data['free_shipping_indicator'] = '<img src="path/FreeShipping.png">';
}
and in the view

Code: Select all

{% if free_shipping %}{{ free_shipping_indicator }}{% endif %}
before

Code: Select all

<h1>{{ heading_title }}</h1>
just wondering, you have products requiring shipping with zero weight or are you just using that as a trick to facilitate free shipping?
Hi letxobnav,

Thanks for the reply and the help with your code, but may I ask you what file must be modified with your code and where inside the file?
The answer to your question: it's a trick to facilitate free shipping ;o)

UPDATE 20 Minutes After:

I managed to place the code in catalog\view\theme\default\template\product\product.twig like this:

Code: Select all

          </div>
		  {% if weight == 0 %}
		  { <img src="image/shipping_logo_chronopost.png"> }
		  {% endif %}
		  {% if free_shipping %}
		  { free_shipping_indicator }
		  {% endif %}
          <h1>{{ heading_title }}</h1>

Concerning \catalog\controller\product\product.php
Where must I place the code?

Thanks
After a long battle (LOL) I managed to make it half work.

In product.php I added this code :

Code: Select all


				$data['minimum'] = 1;
			}
			
$data['weight'] = $product_info['weight'];
$data['free_shipping'] = false;
if ($product_info['weight'] == 0) {
   $data['free_shipping'] = true;
   $data['free_shipping_indicator'] = '<img src="image/shipping_logo_chronopost.png">';
}

			$data['review_status'] = $this->config->get('config_review_status');
			
In the product.twig file I added this code:

Code: Select all

          
          </div>
		  
{% if weight == 0 %}
<img src="image/shipping_logo_chronopost.png"> 
{% endif %}

		  
          <h1>{{ heading_title }}</h1>

If I add the same code (above) on one line it caused a fatal error

Code: Select all

{% if weight == 0 %}{{ <img src="image/shipping_logo_chronopost.png"> }}{% endif %}
It seems that this line of code is OK to replace the last one.
I take a pictures so you can have a look

https://imgur.com/a/nGvBJY9


I think it's working right now, need some sleeping and testing time.
I will comeback in a few hours to tell you if everything is Okay.

Thanks and regards

Newbie

Posts

Joined
Sun Jan 05, 2020 5:10 am

Post by letxobnav » Fri Jan 17, 2020 4:17 pm

code in your images looks fine.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Active Member
Online

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by straightlight » Fri Jan 17, 2020 11:06 pm

elliotjohn wrote:
Fri Jan 17, 2020 5:08 am
straightlight wrote:
Fri Jan 17, 2020 4:52 am
Since you're only looking to show a generic PNG image before the image name, no PHP skill is needed. You could simply edit your catalog/view/theme/<your_custom_theme>/template/product/product.twig file by adding your image src link to your PNG file whenever the quantity is 0. Then, to follow this FAQ: viewtopic.php?f=176&t=200804#p718325
1) I'm not looking to show a PNG before the image name but before the product name.
2) I would like to show a "free delivery png" when the product weight is = 0 or if the weight is not defined.

So if the product weight = 0 show FreeShipping.png

The FAQ you send me is irrelevant to my problem because this post is dedicated to :
- Show to the customer the weight & size of the product ( I don't need to)
- For OpenCart 2

Regards
1 - For the image name, that is correct. I meant to say product name
2 - Static HTML do not require to be surrounded by { and } . { and } are usable to call a specific variable
3 - You are posting in the v3.x releases section of the forum and you are claiming to use Opencart 2 and also the reason why you might still be getting errors while trying to implement the provided codes on this topic. The FAQ has been provided for OC v3.x releases since you created a topic in v3.x releases and has been posted for the right purpose. Please post in the right forum section by referring to the breadcrumbs on the top of the forum. Forum rules.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member

Posts

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

Post by elliotjohn » Sat Jan 18, 2020 12:17 am

straightlight wrote:
Fri Jan 17, 2020 11:06 pm
elliotjohn wrote:
Fri Jan 17, 2020 5:08 am
straightlight wrote:
Fri Jan 17, 2020 4:52 am
Since you're only looking to show a generic PNG image before the image name, no PHP skill is needed. You could simply edit your catalog/view/theme/<your_custom_theme>/template/product/product.twig file by adding your image src link to your PNG file whenever the quantity is 0. Then, to follow this FAQ: viewtopic.php?f=176&t=200804#p718325
1) I'm not looking to show a PNG before the image name but before the product name.
2) I would like to show a "free delivery png" when the product weight is = 0 or if the weight is not defined.

So if the product weight = 0 show FreeShipping.png

The FAQ you send me is irrelevant to my problem because this post is dedicated to :
- Show to the customer the weight & size of the product ( I don't need to)
- For OpenCart 2

Regards
1 - For the image name, that is correct. I meant to say product name
2 - Static HTML do not require to be surrounded by { and } . { and } are usable to call a specific variable
3 - You are posting in the v3.x releases section of the forum and you are claiming to use Opencart 2 and also the reason why you might still be getting errors while trying to implement the provided codes on this topic. The FAQ has been provided for OC v3.x releases since you created a topic in v3.x releases and has been posted for the right purpose. Please post in the right forum section by referring to the breadcrumbs on the top of the forum. Forum rules.
Dear,

I never claim to use Opencart 2...
You make some mistake while reading me...

My first post...
I'm currently using OC Version 3.0.2.0
Concerning my post that you quoted I say "The FAQ you send me is irrelevant to my problem because this post (the one he sended me) is dedicated to :
1) Show to the customer the weight & size of the product
2)OpenCart 2"
So the post he send me is is dedicated to Opencart 2 and for showing the weight/size to the customer.

So I never claim to be using OC 2 and I in my first post I clearly say that i'm using OC 3


Thanks and regards

Newbie

Posts

Joined
Sun Jan 05, 2020 5:10 am

Post by straightlight » Sat Jan 18, 2020 12:51 am

So I never claim to be using OC 2 and I in my first post I clearly say that i'm using OC 3
While you may or may not be using OC 2, it is still mentioned: For Opencart 2 as it does not provide the info whether you are relating the fact you are using OC 2 or OC 3 as compared to your first post which is considered a lack of information.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member

Posts

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

Post by elliotjohn » Sat Jan 18, 2020 2:04 am

Je vais me permettre de parler français peut-être que ça passera mieux.

Anglais:
The FAQ you send me is irrelevant to my problem because this post (the one he sended me) is dedicated to :
1) Show to the customer the weight & size of the product
2)OpenCart 2"

Français:
Il m'a envoyer un lien d'une FAQ qui concernait :
1) L'affichage du poids et de la taille du produits pour le client
2) Opencart 2

Tu me dit que "it is still mentioned: For Opencart 2" tout en oubliant le contexte et la phrase juste avant....

Tu comprends mieux en Français là ?
Opencart 2 concernait SON LIEN moi j'ai jamais dit nulle-part que je l'utilisais ou que je cherchais une aide là-dessus.

Il y a clairement un problème de compréhension là.

Mes salutations les plus cordiales


straightlight wrote:
Sat Jan 18, 2020 12:51 am
So I never claim to be using OC 2 and I in my first post I clearly say that i'm using OC 3
While you may or may not be using OC 2, it is still mentioned: For Opencart 2 as it does not provide the info whether you are relating the fact you are using OC 2 or OC 3 as compared to your first post which is considered a lack of information.

Newbie

Posts

Joined
Sun Jan 05, 2020 5:10 am

Post by straightlight » Sat Jan 18, 2020 2:58 am

Puisque cette section du forum sont pour les anglophones, il n'y a aucune raison de postuler vos réponses dans les deux langues. Le forum implique spécifiquement des réponses françaises dans la section française du forum. Comme j'ai expliqué dans ma réponse précédente, la mention d'OC v2 a été postulée brievement sans aucun détail accordé avec votre réponse même si la 1e postule fait en sorte que vous utilisiez la version 3 d'OC.

While the forum rules are being explained in English, followed is the official section: viewforum.php?f=176

Thank you.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member

Posts

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

Post by straightlight » Sat Jan 18, 2020 3:02 am

In addition to the above, this new topic: viewtopic.php?f=202&t=215688#p774376 indicates on your screenshot that you are using OC in a localhost environment.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member

Posts

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

Post by elliotjohn » Sat Jan 18, 2020 3:04 am

straightlight wrote:
Sat Jan 18, 2020 3:02 am
In addition to the above, this new topic: viewtopic.php?f=202&t=215688#p774376 indicates on your screenshot that you are using OC in a localhost environment.
Yes i'm using it in a localhost environment for testing purpose and when everything is okay i make the modification online after.
I'm experiencing the same problem in localhost and online.

Newbie

Posts

Joined
Sun Jan 05, 2020 5:10 am

Post by straightlight » Sat Jan 18, 2020 3:06 am

I'm experiencing the same problem in localhost and online.
Is there a URL you could provide for the support team to take a look at?

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member

Posts

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

Post by elliotjohn » Sat Jan 18, 2020 3:17 am

straightlight wrote:
Sat Jan 18, 2020 3:06 am
I'm experiencing the same problem in localhost and online.
Is there a URL you could provide for the support team to take a look at?
Just send it In your P.Message box

Newbie

Posts

Joined
Sun Jan 05, 2020 5:10 am
Who is online

Users browsing this forum: myy_84@hotmail.com and 15 guests