Post by gluleci » Wed Apr 22, 2020 2:35 pm

hello,

i want to show popular posts in cart page. i try but i can't.

i add this code, controller > checkout > cart.php

Code: Select all

$this->load->model('catalog/product');

			$data['products'] = array();

			if (!$setting['limit']) {
				$setting['limit'] = 4;
			}

			$filter_data = array(
				'sort'  => 'p.date_added',
				'order' => 'DESC',
				'start' => 0,
				'limit' => $setting['limit']
			);
	
			$oresults = $this->model_catalog_product->getPopularProducts($filter_data);
	
			if ($oresults) {
				foreach ($oresults as $oresult) {
					if ($oresult['image']) {
						$image = $this->model_tool_image->resize($oresult['image'], $setting['width'], $setting['height']);
					} else {
						$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
					}
	
					if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
						$price = $this->currency->format($this->tax->calculate($oresult['price'], $oresult['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
					} else {
						$price = false;
					}
	
					if ((float)$oresult['special']) {
						$special = $this->currency->format($this->tax->calculate($oresult['special'], $oresult['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
					} else {
						$special = false;
					}
	
					if ($this->config->get('config_tax')) {
						$tax = $this->currency->format((float)$oresult['special'] ? $oresult['special'] : $oresult['price'], $this->session->data['currency']);
					} else {
						$tax = false;
					}
	
					if ($this->config->get('config_review_status')) {
						$rating = $oresult['rating'];
					} else {
						$rating = false;
					}
	
					$data['products'][] = array(
						'product_id'  => $oresult['product_id'],
						'thumb'       => $image,
						'name'        => $oresult['name'],
						'description' => utf8_substr(trim(strip_tags(html_entity_decode($oresult['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
						'price'       => $price,
						'special'     => $special,
						'tax'         => $tax,
						'rating'      => $rating,
						'href'        => $this->url->link('product/product', 'product_id=' . $oresult['product_id'])
					);
				}
	
				return $this->load->view('extension/module/latest', $data);
			} else {
				return '-';
			}
and add this code , view>theme>default>checkout>cart.twig

Code: Select all

      {% for oresult in oresults %}
        <div class="product-layout product-list col-xs-12 col-md-4">
          <div class="product-thumb">
            <div class="image"><a href="{{ oresult.href }}"><img src="{{ oresult.thumb }}" alt="{{ oresult.name }}" title="{{ oresult.name }}" class="img-responsive" /></a></div>
            <div>
              <div class="caption">
                <h4><a href="{{ oresult.href }}">{{ oresult.name }}</a></h4>             
                <p>{{ oresult.description }}</p>
                {% if oresult.price %}
                <p class="price">
                {% if not oresult.special %}
                  {{ oresult.price }}
                  {% else %} <span class="price-new">{{ oresult.special }}</span> <span class="price-old">{{ oresult.price }}</span>
                {% endif %}
                  </p>
                {% endif %}
              </div>
            </div>
          </div>
        </div>
                {% endfor %}
but nothing happens. its not see my code.

Newbie

Posts

Joined
Wed Apr 22, 2020 2:27 pm

Post by OSWorX » Wed Apr 22, 2020 5:08 pm

Code: Select all

..	
$oresults = $this->model_catalog_product->getPopularProducts($filter_data);
And later:

Code: Select all

	$data['products'][] = array(
	'product_id'  => $oresult['product_id'],
	'thumb'       => $image,
	'name'        => $oresult['name'],
	'description' => utf8_substr(trim(strip_tags(html_entity_decode($oresult['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
	'price'       => $price,
	'special'     => $special,
	'tax'         => $tax,
	'rating'      => $rating,
	'href'        => $this->url->link('product/product', 'product_id=' . $oresult['product_id'])				
And inside the template

Code: Select all

      {% for oresult in oresults %}
and so on ..
gluleci wrote:
Wed Apr 22, 2020 2:35 pm
but nothing happens. its not see my code.
No wonder, you are assigning the data to products but call oresults ..

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


User avatar
Guru Member
Online

Posts

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

Post by straightlight » Wed Apr 22, 2020 6:52 pm

This method above is rather recommended than the use of customers activities with notification knowing which products have been added to the cart. Great work! :)

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 OSWorX » Wed Apr 22, 2020 7:21 pm

straightlight wrote:
Wed Apr 22, 2020 6:52 pm
This method above is rather recommended than the use of customers activities with notification knowing which products have been added to the cart. Great work! :)
? ? ?

Basically I realyl do not know what about you both guys are talking ..
OP is saying
.. show popular posts in cart page ..
while I really do not know what he means with "posts".
While I read this for the frontend.
And now you are talking about "customer activities" which is only for the backend.

Apples and Pears ..

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


User avatar
Guru Member
Online

Posts

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

Post by straightlight » Wed Apr 22, 2020 7:23 pm

OSWorX wrote:
Wed Apr 22, 2020 7:21 pm
straightlight wrote:
Wed Apr 22, 2020 6:52 pm
This method above is rather recommended than the use of customers activities with notification knowing which products have been added to the cart. Great work! :)
? ? ?

Basically I realyl do not know what about you both guys are talking ..
OP is saying
.. show popular posts in cart page ..
while I really do not know what he means with "posts".
While I read this for the frontend.
And now you are talking about "customer activities" which is only for the backend.

Apples and Pears ..
Right. I should of pointed out the topic but I figured it would of been a bit redundant. Here is the topic I was referring to specifically: viewtopic.php?f=202&t=217275#p784445 .

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 Gobbo » Wed Apr 22, 2020 8:38 pm

Hi,

Great idea, up-selling is always a great thing.

But can you add related products along with popular products? To the cart page.

Using opencart 3.0.3.2 - PHP 7.4 - Standard Template - Add to Cart Enable Disable Out of Stock Product 3.x - Export/Import Tool (V3.22) for OpenCart 3.x - Footer Social Media Link( 3.x ) v1.0


Active Member

Posts

Joined
Tue Jun 22, 2010 12:38 am

Post by straightlight » Wed Apr 22, 2020 8:47 pm

The only downside with the getPopularProducts() method is the pulling of the updated view while even search engines could increase the counters of those viewed products and may not be the best statistics based on the popular products in the cart page that way ... :ponder:

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 letxobnav » Wed Apr 22, 2020 10:13 pm

Correct, that is why OC should identify bots and exclude them from such updates.
Unfortunately OC does not while it does have a bots pattern setting in admin, such a shame.

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
Expert Member

Posts

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

Post by straightlight » Wed Apr 22, 2020 10:20 pm

To exclude them may not be the best way to handle. Rather to filter by classification when pulling the updated results back as opposed to add the updated value on the database.

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 letxobnav » Wed Apr 22, 2020 10:34 pm

Classification of what?
Why allow bots to increase product viewed count in the first place (those are not views) and then try to filter them back out?

If you can filter them out then you need a means to identify the number added by the bots which means you need to identify the bots and that means you can prevent them from adding to the count in the first place and then you don't have to filter them out.

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
Expert Member

Posts

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

Post by straightlight » Wed Apr 22, 2020 10:49 pm

letxobnav wrote:
Wed Apr 22, 2020 10:34 pm
Classification of what?
Why allow bots to increase product viewed count in the first place (those are not views) and then try to filter them back out?

If you can filter them out then you need a means to identify the number added by the bots which means you need to identify the bots and that means you can prevent them from adding to the count in the first place and then you don't have to filter them out.
Because there's a little bit more to the story when it comes to bots tracking on the products on a store but I do understand the point above. By blocking the bots dynamically, however, it may still affect specific services where OC users might be relying to as we may not know which bots are really useful excluding those already added in the config bots list especially since the config bot lists are configured by stores which might also be the reason why the updated viewed products may not be handled with bot filtering right now. If not by classification, then we'd have to assume that only the config robots array may contain those lists as we know, due to the mount of extensions already published out there, that it may not be the case.

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: OSWorX, pprmkr and 476 guests