Price = quantity x length x price per meter?

  • Posts: 22
  • Thank you received: 0
7 years 11 months ago #258387

-- url of the page with the problem -- : localhost
-- HikaShop version -- : 2.6.4
-- Joomla version -- : 3.6.5
-- PHP version -- : 5.3.28
-- Browser(s) name and version -- : Chrome Версия 55.0.2883.87 m

We need to sell a certain length profiles. Specify a price per meter, and the choice of the length that the price remained the same (per square meter), and the factor has changed and applied to the final price.
For example, on the product page: the price per square meter € 1, option: The length of 2.5 meters.
In order: 1 Profile of length 2.5 meters of 2.5 €.
price = quantity x length x price per meter
Is that possible?

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

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
7 years 10 months ago #258437

Hi,

Yes, it's possible with a custom field of the table "item" and a price override plugin to take into account the value in the custom item field where the customer can enter the length.
In our FAQ, we provide a plugin to handle the same thing but to have the customer enter both the width and the length:
www.hikashop.com/support/documentation/106-faq.html#cart
Adpting the plugin to handle only the length is really easy.
You just need to change :

		if(!empty($product->length) && !empty($product->width)){
			$quantity = $quantity*$product->length*$product->width;
		}
to:
		if(!empty($product->length)){
			$quantity = $quantity*$product->length;
		}
in its code.

Last edit: 7 years 10 months ago by Jerome. Reason: [code] is nice

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

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
7 years 10 months ago #258438

Also, please note that this requires the Business edition as custom item fields are only available with that edition.

The following user(s) said Thank You: adm_memphis

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

  • Posts: 22
  • Thank you received: 0
7 years 10 months ago #258450

Thank You

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

  • Posts: 22
  • Thank you received: 0
7 years 10 months ago #258575

Can't find price override plugin. It is not the same as HikaShop Custom Quantity plugin, right?
The problem is that the price does not change depending on the length value.

Last edit: 7 years 10 months ago by adm_memphis.

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
7 years 10 months ago #258578

Hi,

Please provide more details about your issue.
As written in the FAQ, the plugin requires item custom fields to let the customer enter the dimensions when he add the product in the cart.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 22
  • Thank you received: 0
7 years 10 months ago #258621

Hi, Jerome!

custom_quantity_width_length.php :

<?php
jimport('joomla.plugin.plugin');
class plgSystemCustom_quantity_width_length extends JPlugin{
}

if(!function_exists('hikashop_product_price_for_quantity_in_cart') && !function_exists('hikashop_product_price_for_quantity_in_order')) {
function hikashop_product_price_for_quantity_in_cart(&$product){
$currencyClass = hikashop_get('class.currency');
$quantity = @$product->cart_product_quantity;
if(!empty($product->length)){
$quantity = $quantity*$product->length;
}
$currencyClass->quantityPrices($product->prices,$quantity,$product->cart_product_total_quantity);
}

function hikashop_product_price_for_quantity_in_order(&$product){
$quantity = $product->order_product_quantity;
if(!empty($product->length)){
$quantity = $quantity*$product->length;
}
$product->order_product_total_price_no_vat = $product->order_product_price*$quantity;
$product->order_product_total_price = ($product->order_product_price+$product->order_product_tax)*$quantity;
}

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

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
7 years 10 months ago #258633

Hi,

In the code you copy pasted, coming from the plugin, you can see that the variable is called "length", but in your screenshots, you can see that the custom field column name is "lenght".
Because of that difference, the plugin won't use the value entered in the custom field.

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

  • Posts: 22
  • Thank you received: 0
7 years 10 months ago #258686

Thank you very much for your time, and I went to learn English

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

  • Posts: 22
  • Thank you received: 0
7 years 10 months ago #259937

Is it possible to output full lenght in checkout cart?

Attachments:

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
7 years 10 months ago #259938

Hi,

Sure it is possible.
You will need to perform a view override of the checkout cart view, add a column in the table and display the product length in the corresponding cell.
In the cart products you will find all information coming from the product table ; so you will have the product dimensions.
www.hikashop.com/support/documentation/1...-display.html#layout

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 22
  • Thank you received: 0
7 years 10 months ago #260097

I tried to change the code in checkout / cart.php, but nothing good came of it.
I have successfully created a new column but still could not change value to quantity*length.
Do I need to create new class "hikashop_cart_product_full_length"?
I take the length from custom_quantity_width_length.php (HikaShopCustom Quantity plugin).

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

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
7 years 10 months ago #260100

Hi,

In checkout/cart.php the quantity is available in $this->row->cart_product_quantity and the length is available in $this->row->length
The HTML class of the element is not important.

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

  • Posts: 22
  • Thank you received: 0
7 years 10 months ago #260230

Hi again.
I'm sorry that wasting your time, but I did not reach any success with this problem.
I can't find $this->row->cart_product_quantity and $this->row->length In checkout/cart.php (txt in the attachment).
Still need to output length*quantity value before CART_PRODUCT_UNIT_PRICE.
I not quite understand the code, but understand that I need copy-paste and customize these fragments:

<td data-title="<?php echo JText::_('CART_PRODUCT_UNIT_PRICE'); ?>" class="hikashop_cart_product_price_value">
								<?php
									$this->row =& $row;
									$this->unit = true;
									echo $this->loadTemplate();
								?>
								<?php if(HIKASHOP_RESPONSIVE){ ?><span class="visible-phone"><?php echo JText::_('PER_UNIT'); ?></span><?php } ?>
							</td>
<th id="hikashop_cart_product_price_title" class="hikashop_cart_product_price_title hikashop_cart_title">
						<?php echo JText::_('CART_PRODUCT_UNIT_PRICE'); ?>
Can you tell me how to do it correctly?
Maybe I can give even some information?

Attachments:

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

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
7 years 10 months ago #260265

You can do like that for example:

<td data-title="<?php echo JText::_('CART_PRODUCT_UNIT_PRICE'); ?>" class="hikashop_cart_product_price_value">
								<?php
									$this->row =& $row;
									$this->unit = true;

echo 'calculation: ' .($this->row->cart_product_quantity * $this->row->length);

									echo $this->loadTemplate();
								?>
								<?php if(HIKASHOP_RESPONSIVE){ ?><span class="visible-phone"><?php echo JText::_('PER_UNIT'); ?></span><?php } ?>
							</td>

The following user(s) said Thank You: adm_memphis

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

  • Posts: 22
  • Thank you received: 0
7 years 10 months ago #260345

Thank you very much!
I used this modification:

<th id="hikashop_cart_product_price_title" class="hikashop_cart_product_price_title hikashop_cart_title">
						<?php echo JText::_('CART_PRODUCT_FULL_LENGTH'); ?>
                    </th>
<td data-title="<?php echo JText::_('CART_PRODUCT_UNIT_PRICE'); ?>" class="hikashop_cart_product_price_value">
								<?php
									$this->row =& $row;
									$this->unit = true;
if(empty($this->row->length))
if(empty($this->row->length100))
if(empty($this->row->length25))
echo "<div style='text-align:right'>".'';
else
echo "<div style='text-align:right'>" .$this->row->cart_product_quantity * $this->row->length25,'m';
else 
echo "<div style='text-align:right'>" .$this->row->cart_product_quantity * $this->row->length100,'m';
else
echo "<div style='text-align:right'>" .$this->row->cart_product_quantity * $this->row->length,'m';
								?>
								<?php if(HIKASHOP_RESPONSIVE){ ?><span class="visible-phone"><?php echo JText::_('PER_UNIT'); ?></span><?php } ?>
							</td>
It's almost perfect! I am very grateful to you for it, but there was formed an empty space to the right of tax calculation.

I also try to display "Length: 2m" instead
"Length
:2m"
for now I do not know how to do it.

Attachments:
Last edit: 7 years 10 months ago by adm_memphis.

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

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
7 years 10 months ago #260354

Hi,

You just need to increase the colspan in this code by the number of columns you add :

if($this->params->get('show_cart_image'))
			$td = '<td colspan="3" class="hikashop_cart_empty_footer"></td>';
		else
			$td = '<td colspan="2" class="hikashop_cart_empty_footer"></td>';

The following user(s) said Thank You: adm_memphis

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

Time to create page: 0.108 seconds
Powered by Kunena Forum