Skip to main content

Use product custom field in price calculation

More
14 years 3 months ago #55303 by Verneda
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:
Code:
if(($product->marcaje)=="A"){ }

It can be done? How?

Thank you!

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

More
14 years 3 months ago #55371 by nicolas
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.

More
14 years 3 months ago #55409 by Verneda
I have a field of item kind (tecnica) and can access it with the "arrow" operator
Code:
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
Code:
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.

More
14 years 3 months ago #55412 by nicolas
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.

More
14 years 3 months ago #55428 by Verneda
Worked like a charm, thank you!

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

Time to create page: 0.205 seconds
Powered by Kunena Forum