Post by CostasL » Tue Jun 26, 2018 4:35 am

Hi all,

I would like to ask for your help because this thing is driving me crazy.
I have opencart 2.1.0.2 with journal2 theme installed and I have modified product.php and product.tpl in order to show the percentage of the discounted price of a special product in product page (see attachment).
The code I have used in product.php is the following:

Code: Select all

if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
					$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
					//my code
					$data['priceInt'] = $this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'));
					//------------my code
				} else {
					$price = false;
				}

				if ((float)$result['special']) {
					$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
					//------------my code
				$data['specialInt'] = $this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax'));
                $data['specialSavings'] = round((($data['priceInt']-$data['specialInt'])/$data['priceInt'])*100, 0);
				if ( $data['specialSavings']  >= 23 && $data['specialSavings'] <= 27 )
				
                      {
                        $data['specialSavings'] = 25;
                      }
					  else {
						$data['specialSavings'] = 20;  
}
//my code
The last part of the code is rounding the discount percentage to either 20% or 25% (my customer wants that so any discount that is 19% or 21% shows as 20% and any 24% or 26% shows as 25% respectively.
In product.tpl I have this code in order to show the percentage:

Code: Select all

 <li class="product-price"><?php echo $price; ?></li>
            <?php } else { ?>
			 
            <li class="price-old"><?php echo $price; ?></li>
            <li class="price-new"><?php echo $special; ?></li>
            <!---------my code starts -------------->
			<li><h1 style="color:red;">&nbsp;&nbsp;-<?php echo $specialSavings; ?>%</h1></li>
And it works fine!

Now, when I try to implement the same code in category.php, I face 2 problems:
1) In homepage where I have set all products to be shown, in first page afte the total 2 pages of pagination, works fine! When I click on the second page, the percentage is dissapeared!
2) I f I click on a subcategory, the percentage is shown wrong e.g. it may be 26% and it shows 20% as if the part of the following code doesn't work:

Code: Select all

if ( $data['specialSavings']  >= 23 && $data['specialSavings'] <= 27 )
				
                      {
                        $data['specialSavings'] = 25;
                      }
					  else {
						$data['specialSavings'] = 20;  
						  
					  }
Any ideas from the more experienced ones?
Thanks in advance!

Attachments

productpage.jpg

productpage.jpg (44.77 KiB) Viewed 19000 times


Newbie

Posts

Joined
Sat Oct 01, 2016 6:51 am

Post by straightlight » Tue Jun 26, 2018 8:25 pm

Take note that when adding codes into the category controller file (either the product/category or from extension/module/category which was not indicated on your first post), the variable names may need to be changed in the mean time before outputting the results into your theme file. However, since only partial solutions were provided, you may have to provide the category.php file as an attachment so to understand the changes that you did more accurately.

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 CostasL » Wed Jun 27, 2018 12:09 am

Hi straightlight and thanks for your interest,

I managed to fix my No2 issue with the wrong percentage. You were right about the variables names!
I still need to find the way to make the code show when you click on the second page of pagination or when using filters.
Here is my code in attachment.
The mod part is the following:

Code: Select all

//sale % mod
				$specialSavings 	 = round((($result['price'] - $result['special'])/$result['price'])*100, 0);
				if ( $specialSavings  >= 23 && $specialSavings <= 27 )
					
				
                      {
                        $specialSavings = 25;
                      }
				elseif ( $specialSavings  > 27)

					  {
						$specialSavings = 30;  
						  
					  }
					  elseif ( $specialSavings  < 23)
					  {
						$specialSavings = 20;  
					  }
					   else {
					$specialSavings = false;
					
				}
				//sale % mod

				
            
				$data['products'][] = array(
					'product_id'  => $result['product_id'],
					'thumb'       => $image,

                'thumb2'       => $image2,
            

                'labels'        => $this->model_journal2_product->getLabels($result['product_id']),
            
					'name'        => $result['name'],
					'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
					'price'       => $price,
					'specialSavings' 	 => $specialSavings, //sale % mod
					'special'     => $special,

                'date_end'       => $date_end,
            
					'tax'         => $tax,
					'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,
					'rating'      => $result['rating'],
					'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
				);
			}

Newbie

Posts

Joined
Sat Oct 01, 2016 6:51 am

Post by straightlight » Wed Jun 27, 2018 12:29 am

I still need to find the way to make the code show when you click on the second page of pagination or when using filters
In catalog/controller/product/category.php file, look for the $pagination object variables. As for the filters, look for prefixes beginning with: filter_ on the same controller file. Lots of examples can be used and reproduced into your own variable / key names.

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 CostasL » Wed Jun 27, 2018 1:07 am

ok I know where these are but how to implement my code in there?
Can you give me an example?

Newbie

Posts

Joined
Sat Oct 01, 2016 6:51 am

Post by straightlight » Wed Jun 27, 2018 1:08 am

If you'd like, you could submit a new request in the Commercial Support section of the forum to get this done as a custom job, if an extension is not already available on the Marketplace.

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 CostasL » Wed Jun 27, 2018 1:36 am

Thank you but I just asked for a hint.
If I can't do it and want to outsource the issue, I will do that.

Newbie

Posts

Joined
Sat Oct 01, 2016 6:51 am

Post by CostasL » Thu Jun 28, 2018 5:10 am

Found out that my modification works fine. It is a theme issue (journal2).
If i switch to default theme, everything works fine.
But in Journal2, the url is rewritten and this causes the problem.
For example, setting products to show in the dropdown menu (limit), from 12 to 25 gives the folowing:
with default theme: https://mydomain.com/eshop/All-Shoes?limit=25
with Journal2 theme: https://mydomain.com/eshop/All-Shoes#/s ... C/limit=25

Funny thing is that If I switch back to Journal2 theme when having the first url (from default theme) in the address bar, and refresh the page, my modification works and the url format remains the same.
If I then click on another sorting (e.g. price Low to High) ,
the url becomes https://mydomain.com/eshop/All-Shoes?li ... C/limit=25 and the mod doesn't work.
But If i remove the hash (#) from the url, everything is beautiful!!!

Should I use a url rewrite script or something else? I would love to hear some suggestions.

Newbie

Posts

Joined
Sat Oct 01, 2016 6:51 am

Post by straightlight » Thu Jun 28, 2018 5:25 am

Looks like the sorting list you are using may not be adapted to SEO links. Ensure from the related controller of your modifications that you are using the $this->url->link object in order to convert your URLs into SEO.

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 CostasL » Thu Jun 28, 2018 5:35 am

straightlight wrote:
Thu Jun 28, 2018 5:25 am
Looks like the sorting list you are using may not be adapted to SEO links. Ensure from the related controller of your modifications that you are using the $this->url->link object in order to convert your URLs into SEO.
I haven't changed anything like this. On the other hand, If i click on e.g. page 2 the problematic url format is shown. But If I right-click on page 2, then in the new window the url is like https://mydomain.com/eshop/Pumps?page=2 and my mod works!

Newbie

Posts

Joined
Sat Oct 01, 2016 6:51 am

Post by straightlight » Thu Jun 28, 2018 5:46 am

See if this solution fixes the issue: https://github.com/billynoah/opencart/b ... nation.php

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 CostasL » Thu Jun 28, 2018 6:10 am

straightlight wrote:
Thu Jun 28, 2018 5:46 am
See if this solution fixes the issue: https://github.com/billynoah/opencart/b ... nation.php
No, nothing! Thanks anyway.
The problem is that the theme has a function (somewhere that I cannot find) that treats any url by adding '#/sort=p.sort_order/order=ASC/limit=12/page=2' instead of '?'

Newbie

Posts

Joined
Sat Oct 01, 2016 6:51 am

Post by straightlight » Thu Jun 28, 2018 9:37 am

Contact the developer of that extension to resolved this issue.

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
Who is online

Users browsing this forum: No registered users and 19 guests