Post by sergius79 » Wed Feb 07, 2018 2:23 pm

Hello!

Where in ОС 2.0.3 creates the array $discounts (elements of this array)?

It is used in catalog/view/theme/default/template/product/product.tpl Sample:
<?php if ($discounts) { ?><?php foreach ($discounts as $discount) { ?><li><?php echo $discount['quantity']; ?><?php echo $text_discount; ?><?php echo $discount['price']; ?></li><?php } ?><?php } ?>

Newbie

Posts

Joined
Thu Nov 24, 2016 6:01 am

Post by OSWorX » Wed Feb 07, 2018 4:53 pm

Code: Select all

catalog/controller/product/product.php line 323

Image


User avatar
Expert Member

Posts

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

Post by sergius79 » Thu Feb 08, 2018 4:10 am

Thank you, OSWorX, very much!

Please, be so kind help me understand where price with/without tax comes from for $discounts?

Code: Select all

/catalog/controller/product/product.php
has:

Code: Select all

$discounts = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']);

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

foreach ($discounts as $discount) {
	$data['discounts'][] = array(
		'quantity' => $discount['quantity'],
		'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')))
		);
}
I have print_r($discounts) and see price comes with/without tax depending of setting from opencart admin "Display Prices With Tax: Yes/No"

I have change:

Code: Select all

'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')))
to
'price'    => $discount['price'],
again price comes with/without tax depending of setting from opencart admin.

I checked the discount function - there is no tax at all

Code: Select all

	public function getProductDiscounts($product_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND quantity > 1 AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity ASC, priority ASC, price ASC");

		return $query->rows;
	}
I need switch setting from opencart admin "Display Prices With Tax: Yes" but to have price without tax in $discounts.

Newbie

Posts

Joined
Thu Nov 24, 2016 6:01 am

Post by OSWorX » Thu Feb 08, 2018 4:47 am

Calculating prices with or without tax comes from the setting:

Code: Select all

$this->config->get('config_tax')
So if you change

Code: Select all

'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')))
to

Code: Select all

'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], 0))
you should have your net discount price.
(While I do not understand your change, because if you display prices to end customers EACH prices have to be WITH tax).

Image


User avatar
Expert Member

Posts

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

Post by sergius79 » Fri Feb 09, 2018 2:28 am

OSWorX, thank you very much!!!!!!!

I did it! http://prntscr.com/ic03zy

You have asked why I need it - it is for UK web site. There is popular to show prices without tax. I don't know why it is so. It is like local feature. For me as client it is not handy way because I prefer to see price with tax cause I will pay it anyway.

If somebody use information from this topic I would draw attention to Refresh Modifications in OC 2.3. if you correct $discounts array in controller to have 2 prices with/wthout tax.
;)

Newbie

Posts

Joined
Thu Nov 24, 2016 6:01 am
Who is online

Users browsing this forum: No registered users and 12 guests