Place discount in column in cart

  • Posts: 45
  • Thank you received: 0
9 years 10 months ago #219520

-- HikaShop version -- : 2.6.0. Business

Hi,

In the cart I want to place the discount percentage in a separate column (td) after the price. I know how to edit the column header (th), but how can I add the discount in the rows per product?

Thanks!

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
9 years 10 months ago #219541

Hi,

You can use this code to display the discount percentage:

</td>
<?php
if(isset($row->discount->discount_percent_amount))
	echo (int)$row->discount->discount_percent_amount.'%';
?>
</td>

You just have to place that code in the php foreach listing all the products.

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 0
9 years 10 months ago #219659

Okay, can you give me a hint where to add it if I wish to add it to the product listing?

Listing_price.php? And where would you put it? Around what line?

Thanks!

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
9 years 10 months ago #219664

Hi,

To add the discount percentage in the cart module, the view to edit is "product / cart" and add the code near the line: 482
In the cart of the checkout the view is "checkout / cart", line: 211
In the cart display menu "cart / showcart" line: 438 (in this case use $cart->...)

The following user(s) said Thank You: Squashtoppertje

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 0
9 years 10 months ago #220093

Thanks. And how can I get rid of the percentage next to the price?

Because now I still have, for instance:
Price | Discount
€ 25 -50% | 50%

So the first column is the original display with price and discount.

Thanks again.

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 0
9 years 10 months ago #220132

I solved this by commenting out the complete part related to discounts in listing_price.php. I don't know if it is the best solution, but it does work.

However this does trigger a new question: how to add the price before discount in a separate column in table listing?

EDIT: Solved this to! Using MSRP-field:

<td>
	<span class="hikashop_product_msrp_price hikashop_product_price_full">		
		<?php
			$mainCurr = $this->currencyHelper->mainCurrency();
			$app = JFactory::getApplication();
			$currCurrency = $app->getUserState( HIKASHOP_COMPONENT.'.currency_id', $mainCurr );
			$msrpCurrencied = $this->currencyHelper->convertUniquePrice($this->row->product_msrp,$mainCurr,$currCurrency);
			if($msrpCurrencied == $this->row->product_msrp)
				echo $this->currencyHelper->format($this->row->product_msrp,$mainCurr);
			else
				echo $this->currencyHelper->format($msrpCurrencied,$currCurrency).' ('.$this->currencyHelper->format($this->row->product_msrp,$mainCurr).')';
		?>
		
	</span>
<?php // } ?>
                  </td>

Last edit: 9 years 10 months ago by Squashtoppertje. Reason: Solved

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
9 years 10 months ago #220136

Hi,

You have to edit the view "product / listing_table" and do the same thing than in the "product / cart" view.

The following user(s) said Thank You: Squashtoppertje

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 0
9 years 10 months ago #220227

Hi Xavier,

Something strange happens: I added separate columns for the product code and the MSRP-price and in both cases in the first row the code and price are empty. If I select another product the same happens, only with the first code or MSRP price. See image.

This is the added code for the product code in the showcart.php:

<tr class="hikashop_show_cart row<?php echo $k; if((int)$cart->cart_product_quantity == 0) echo " hika_wishlist_green";?>">
			<td data-title="<?php echo JText::_('HIKA_NUM'); ?>" align="center"><?php echo $i; ?></td>
          
         <!-- ADDED -->
 						<td class="hikashop_product_code_row">
						<?php echo $this->row->product_code; ?>
						</td>         
          <!-- END ADDED -->

And this code for the MSRP price:
			</td>
<!-- ADDED -->
                  <td>
                  <?php
                 // if(isset($this->element->main->product_msrp) && !(@$this->row->product_msrp > 0.0) )
	// $this->row->product_msrp = $this->element->main->product_msrp;
// if(isset($this->row->product_msrp) && @$this->row->product_msrp > 0.0 && JRequest::getCmd('layout') == 'show' && $this->params->get('from_module','') == ''){ ?>
	<span class="hikashop_product_msrp_price hikashop_product_price_full">
		<span class="hikashop_product_msrp_price_title">
		<?php
			// echo JText::_('PRODUCT_MSRP_BEFORE');
		?>
		</span>
		
		<?php
			$mainCurr = $this->currencyHelper->mainCurrency();
			$app = JFactory::getApplication();
			$currCurrency = $app->getUserState( HIKASHOP_COMPONENT.'.currency_id', $mainCurr );
			$msrpCurrencied = $this->currencyHelper->convertUniquePrice($this->row->product_msrp,$mainCurr,$currCurrency);
			if($msrpCurrencied == $this->row->product_msrp)
				echo $this->currencyHelper->format($this->row->product_msrp,$mainCurr);
			else
				echo $this->currencyHelper->format($msrpCurrencied,$currCurrency); //.' ('.$this->currencyHelper->format($this->row->product_msrp,$mainCurr).')';
		?>
		
	</span>
<?php // } ?>
                  </td>

<!-- END ADDITION -->

			<td data-title="<?php echo JText::_('CART_PRODUCT_UNIT_PRICE'); ?>" align="right">

How can I solve this?

Thanks again!

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 84328
  • Thank you received: 13718
  • MODERATOR
9 years 10 months ago #220289

Hi,

The problem is that $this->row doesn't exist when you try to use it.
You should use instead $cart in your code and it will work.

The following user(s) said Thank You: Squashtoppertje

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 0
9 years 10 months ago #220316

YES! Thanks, this works!

You know, you offer great support, but there's one thing I miss (or maybe just haven't found yet): a list with all possible calls/data per view. That would be really handy.

Please Log in or Create an account to join the conversation.

  • Posts: 84328
  • Thank you received: 13718
  • MODERATOR
9 years 10 months ago #220338

Hi,

Our documentation is focused towards users not developers. For developers we have a somewhat scarce documentation for the most important things but developers are capable of finding additional information themselves and they can always ask us if necessary.
For the variables available in a view, you can look at the code there and do var_dumps of them. And for the functions available in HikaShop, you basically want to use the hikashop_get function to load classes/helpers and you can look in the administrator/components/com_hikashop/classes and administrator/components/com_hikashop/helpers for all the functions available through that, which basically covers all the necessary functions you would need.

The following user(s) said Thank You: Squashtoppertje

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 0
9 years 10 months ago #220355

Thanks. In this case I'm stuck somewhere in the middle between a user and a developer, but I'm learning... ;)

Please Log in or Create an account to join the conversation.

Time to create page: 0.076 seconds
Powered by Kunena Forum