Use product custom field in price calculation

  • Posts: 10
  • Thank you received: 0
12 years 4 months ago #55303

I'm trying to modify the price of a product based on a custom field.

I have a custom field named "marcaje", whose value is a character ("A", "B", "C", etc)

In the function hikashop_product_price_for_quantity_in_cart i try to refer to that value and modify the price based on that:

if(($product->marcaje)=="A"){

}

It can be done? How?

Thank you!

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

  • Posts: 82821
  • Thank you received: 13368
  • MODERATOR
12 years 4 months ago #55371

Sure it can be done like that.

What kind of custom field are you using ?
A custom product field or a custom item field ?

You should look at the custom price plugin:
plugins/system/custom_price/custom_price.php

You will have an example of what to do.

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

  • Posts: 10
  • Thank you received: 0
12 years 4 months ago #55409

I have a field of item kind (tecnica) and can access it with the "arrow" operator

if(!empty($product->tecnica)){...}

but with product kind don't know how to.

I have added a product custom field named "test" of type text to a product, and modified hikashop_product_price_for_quantity_in_cart in custom_price.php
function hikashop_product_price_for_quantity_in_cart(&$product){
	$currencyClass = hikashop_get('class.currency');
	$quantity = @$product->cart_product_quantity;
	if(empty($product->prices)){
		$price= null;
		$price->price_currency_id = hikashop_getCurrency();
		$price->price_min_quantity = 1;
		$product->prices = array($price);
	}
	if(!empty($product->test)) {
		foreach($product->prices as $k => $price){
			$product->prices[$k]->price_value == 100;
			$product->prices[$k]->price_value_with_tax == 118;
		}
	}
	$currencyClass->quantityPrices($product->prices,$quantity,$product->cart_product_total_quantity);

but it's not working.

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

  • Posts: 82821
  • Thank you received: 13368
  • MODERATOR
12 years 4 months ago #55412

You first need to load the product data:

$productClass = hikashop_get('class.product');
$productData = $productClass->get($product->product_id);
if(!empty($productData->test)) {

....etc...

The following user(s) said Thank You: Verneda

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

  • Posts: 10
  • Thank you received: 0
12 years 4 months ago #55428

Worked like a charm, thank you!

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

Time to create page: 0.061 seconds
Powered by Kunena Forum