Post by lockiedownunder » Sat Jul 19, 2025 9:37 am

I'm looking for a way to display the discounted price offered to certain customer groups as well as the original price, so it is quite clear how much of a discount they're getting.

OC 3.0.4.1
PHP 8.2
Keep Smiling ;D


New member

Posts

Joined
Sun Nov 01, 2015 3:00 pm


Post by khnaz35 » Sat Jul 19, 2025 3:30 pm

Not tested yet but you can give it shot, logically this will work

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<modification>
  <name>Customer Group Special + Discount Display</name>
  <code>customer_group_special_with_display</code>
  <version>1.0</version>
  <author>khnaz35</author>
  <link>mailto:khnaz35@gmail.com</link>

  <!-- Modify controller logic -->
  <file path="catalog/controller/product/product.php">
  
    <!-- Inject customer group price logic before special block -->
    <operation>
      <search><![CDATA[
if (!is_null($product_info['special']) && (float)$product_info['special'] >= 0) {
]]></search>
      <add position="before"><![CDATA[
$data['price_value'] = (float)$product_info['price'];

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

// Default special price
$customer_group_special = $product_info['special'];

$specials = $this->model_catalog_product->getProductSpecials([
  'filter_product_id' => $product_info['product_id']
]);

foreach ($specials as $s) {
  if ((int)$s['customer_group_id'] === (int)$this->customer->getGroupId()) {
    $customer_group_special = $s['price'];
    break;
  }
}
]]></add>
    </operation>

    <!-- Replace special price assignment with customer-group version -->
    <operation>
      <search><![CDATA[
$data['special'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
]]></search>
      <replace><![CDATA[
$data['special'] = $this->currency->format($this->tax->calculate($customer_group_special, $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
$data['special_value'] = (float)$customer_group_special;
]]></replace>
    </operation>

  </file>

  <!-- Inject 'You save %' into product.twig after special price -->
  <file path="catalog/view/theme/*/template/product/product.twig">
    <operation>
      <search><![CDATA[<h2>{{ special }}</h2>]]></search>
      <add position="after"><![CDATA[
{% if price_value and special_value and price_value > special_value %}
  <li><strong class="price-saving">You save {{ ((price_value - special_value) / price_value * 100)|round }}%</strong></li>
{% endif %}
]]></add>
    </operation>
  </file>
</modification>

Got an urgent question that’s keeping you up at night? There might just be a magical inbox ready to help: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by lockiedownunder » Sun Jul 20, 2025 1:06 pm

Pardon my ignorance but how do I apply this code?

OC 3.0.4.1
PHP 8.2
Keep Smiling ;D


New member

Posts

Joined
Sun Nov 01, 2015 3:00 pm


Post by khnaz35 » Sun Jul 20, 2025 1:21 pm

You have to options
1-copy the code and create new xml from your admin modification section you have extension installed for that on your store.

2- copy the code past into a file using text editor name the file and save it as .xml and place the file inside system directory

Got an urgent question that’s keeping you up at night? There might just be a magical inbox ready to help: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by lockiedownunder » Sun Jul 20, 2025 1:54 pm

khnaz35 wrote:
Sun Jul 20, 2025 1:21 pm
You have to options
1-copy the code and create new xml from your admin modification section you have extension installed for that on your store.

2- copy the code past into a file using text editor name the file and save it as .xml and place the file inside system directory
I figured out option 1 thank you
After saving it says error then if I click blue refresh button it crashes admin, I had to uninstall it.

OC 3.0.4.1
PHP 8.2
Keep Smiling ;D


New member

Posts

Joined
Sun Nov 01, 2015 3:00 pm


Post by khnaz35 » Sun Jul 20, 2025 2:02 pm

lockiedownunder wrote:
Sun Jul 20, 2025 1:54 pm
I figured out option 1 thank you
Awesome most welcome

So now on this part
lockiedownunder wrote:
Sun Jul 20, 2025 1:54 pm
After saving it says error then if I click blue refresh button it crashes admin, I had to uninstall it.
As i mentioned earlier i didn't test it on my test store , it was most logical that would be done.
So make things work i need to know the exact error what you got after installing it.
Do share the error logs

Got an urgent question that’s keeping you up at night? There might just be a magical inbox ready to help: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by lockiedownunder » Sun Jul 20, 2025 3:38 pm

I cleared the mod logs, Installed your code but there are no mod logs. It must crash before creating them

OC 3.0.4.1
PHP 8.2
Keep Smiling ;D


New member

Posts

Joined
Sun Nov 01, 2015 3:00 pm


Post by khnaz35 » Sun Jul 20, 2025 4:35 pm

Define crash

Got an urgent question that’s keeping you up at night? There might just be a magical inbox ready to help: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by lockiedownunder » Sun Jul 20, 2025 6:30 pm

khnaz35 wrote:
Sun Jul 20, 2025 4:35 pm
Define crash
After install I press blue refresh button and get the attached screen.

Attachments

???
clicked-refresh.jpg

OC 3.0.4.1
PHP 8.2
Keep Smiling ;D


New member

Posts

Joined
Sun Nov 01, 2015 3:00 pm


Post by lockiedownunder » Sun Jul 20, 2025 6:31 pm

It's okay don't waste any more time on this. I thank you for your assistance so far.

Tony

OC 3.0.4.1
PHP 8.2
Keep Smiling ;D


New member

Posts

Joined
Sun Nov 01, 2015 3:00 pm


Post by khnaz35 » Sun Jul 20, 2025 7:48 pm

lockiedownunder wrote:
Sun Jul 20, 2025 6:30 pm
khnaz35 wrote:
Sun Jul 20, 2025 4:35 pm
Define crash
After install I press blue refresh button and get the attached screen.
This error would be on server error logs not in your opencart logs

Got an urgent question that’s keeping you up at night? There might just be a magical inbox ready to help: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by khnaz35 » Sun Jul 20, 2025 7:50 pm

lockiedownunder wrote:
Sun Jul 20, 2025 6:31 pm
It's okay don't waste any more time on this. I thank you for your assistance so far.

Tony
Most welcome, if no need further solution I will mark the topic as closed

Got an urgent question that’s keeping you up at night? There might just be a magical inbox ready to help: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia
Who is online

Users browsing this forum: ianhaney50 and 14 guests