Page 1 of 1
bestseller sort on category
Posted: Sun Apr 13, 2025 8:17 pm
by zigi00x
Hello,
How to add a new field 'Bestseller' to the sort options on the category page and other sort pages, so that products can be sorted by the best-selling ones?
Why doesn't OpenCart have this essential feature in the core already?
Thank you.
Re: bestseller sort on category
Posted: Sun Apr 13, 2025 9:43 pm
by by mona
zigi00x wrote: ↑Sun Apr 13, 2025 8:17 pm
Why doesn't OpenCart have this essential feature in the core already?
You answered your own question. Search the Opencart Marketplace.
1. What is essential to you is not essential to others.
2. There is a best sellers module provided for free.
3. Unpaid search done on your behalf - One for free
https://www.opencart.com/index.php?rout ... n_id=28354
If that is not good enough for you and you can not find an extension in the marketplace there is a commercial section on the forum.
Opencart is a free commercial platform. Offering up a complaint about what you dont get for free does not incentivise anyone to give more for free.
Note for a free module - 650 downloads with 3 of them saying thank you - what about the other 647 ?
Re: bestseller sort on category
Posted: Wed Apr 16, 2025 3:33 am
by zigi00x
by mona wrote: ↑Sun Apr 13, 2025 9:43 pm
zigi00x wrote: ↑Sun Apr 13, 2025 8:17 pm
Why doesn't OpenCart have this essential feature in the core already?
You answered your own question. Search the Opencart Marketplace.
1. What is essential to you is not essential to others.
2. There is a best sellers module provided for free.
3. Unpaid search done on your behalf - One for free
https://www.opencart.com/index.php?rout ... n_id=28354
If that is not good enough for you and you can not find an extension in the marketplace there is a commercial section on the forum.
Opencart is a free commercial platform. Offering up a complaint about what you dont get for free does not incentivise anyone to give more for free.
Note for a free module - 650 downloads with 3 of them saying thank you - what about the other 647 ?
unfortunately no matter how hard I try this code does not work with oc 3.0.4.0 and php 8.3:
Code: Select all
<modification>
<name>Sort by Bestselling (All Orders)</name>
<code>cdsortbybestseller</code>
<version>1.3</version>
<author>Cyber Fox</author>
<link>https://cyberfoxdigital.co.uk</link>
<!-- 1. MODEL: Počítá všechny objednávky (bez filtru statusu) -->
<file path="catalog/model/catalog/product.php">
<operation>
<search>
<![CDATA[$sql .= " LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN "]]>
</search>
<add position="before" index="1">
<![CDATA[
if (!empty($data['sort']) && $data['sort'] == 'sold_count') {
$sql = str_replace(
'AS special',
'AS special,
(SELECT COUNT(DISTINCT op.order_id)
FROM ' . DB_PREFIX . 'order_product op
WHERE op.product_id = p.product_id
) AS sold_count',
$sql
);
}
]]>
</add>
</operation>
<operation>
<search><![CDATA['p.date_added']]></search>
<add position="replace">
<![CDATA['p.date_added',
'sold_count']]>
</add>
</operation>
</file>
<!-- 2. LANGUAGE: Text pro řazení -->
<file path="catalog/language/en-gb/product/category.php">
<operation>
<search><![CDATA[$_['text_rating_desc'] = 'Rating (Highest)';]]></search>
<add position="after">
<![CDATA[$_['text_sold_count_desc'] = 'Bestselling (All Orders)';]]>
</add>
</operation>
</file>
<!-- 3. CONTROLLERS: Aktualizováno na sold_count -->
<file path="catalog/controller/product/category.php">
<operation>
<search><![CDATA['text' => $this->language->get('text_price_asc'),]]></search>
<add position="before" offset="1">
<![CDATA[
$data['sorts'][] = array(
'text' => $this->language->get('text_sold_count_desc'),
'value' => 'sold_count-DESC',
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=sold_count&order=DESC' . $url)
);
]]>
</add>
</operation>
</file>
<file path="catalog/controller/product/manufacturer.php">
<operation>
<search><![CDATA['text' => $this->language->get('text_price_asc'),]]></search>
<add position="before" offset="1">
<![CDATA[
$data['sorts'][] = array(
'text' => $this->language->get('text_total_desc'),
'value' => 'op.total-DESC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=op.total&order=DESC' . $url)
);
]]>
</add>
</operation>
</file>
<file path="catalog/controller/product/search.php">
<operation>
<search><![CDATA['text' => $this->language->get('text_price_asc'),]]></search>
<add position="before" offset="1">
<![CDATA[
$data['sorts'][] = array(
'text' => $this->language->get('text_total_desc'),
'value' => 'op.total-DESC',
'href' => $this->url->link('product/search', 'search=' . $this->request->get['search'] . '&sort=op.total&order=DESC' . $url)
);
]]>
</add>
</operation>
</file>
<file path="catalog/controller/product/special.php">
<operation>
<search><![CDATA['text' => $this->language->get('text_price_asc'),]]></search>
<add position="before" offset="1">
<![CDATA[
$data['sorts'][] = array(
'text' => $this->language->get('text_total_desc'),
'value' => 'op.total-DESC',
'href' => $this->url->link('product/special', 'sort=op.total&order=DESC' . $url)
);
]]>
</add>
</operation>
</file>
</modification>
I would be grateful for any help, thanks in advance
Re: bestseller sort on category
Posted: Wed Apr 16, 2025 9:26 am
by by mona
The code works but without options.
The module below includes options and a cup of coffee
https://www.opencart.com/index.php?rout ... n_id=47289