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.
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.
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 ?
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
unfortunately no matter how hard I try this code does not work with oc 3.0.4.0 and php 8.3:by mona wrote: ↑Sun Apr 13, 2025 9:43 pmYou 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 ?
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>
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
The module below includes options and a cup of coffee
https://www.opencart.com/index.php?rout ... n_id=47289
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
Who is online
Users browsing this forum: Bing [Bot] and 44 guests