I need help with php i tried differnet ways but does no work.

2 attributes

Paper

<select id="edit-attributes-2" class="form-select ajax-processed" name="attributes[2]">
<option selected="selected" value="3">14pt C2S (Gloss Cover)</option>
<option value="4">16pt C2S (Gloss Cover)</option>
<option value="41">100# White Linen Cover</option>
<option value="42">16pt C1S (Gloss Cover)</option>
<option value="43">14pt Uncoated Cover</option>
</select>

Quantity

<select id="edit-attributes-3" class="form-select required ajax-processed" name="attributes[3]">
<option selected="selected" value="">Please select</option>
<option value="5">250</option>
<option value="6">500</option>
<option value="53">1000</option>
<option value="54">2500</option>
<option value="55">5000</option>
<option value="56">10000</option>
</select>

This is what I want to accomplish

If (paper == 16pt C2S (Gloss Cover) && Quantity == 2500){
$item->price = $item->price + 120;
}

CommentFileSizeAuthor
1.jpg386.69 KBbenitezv1ang

Comments

smd_ksu’s picture

Would live to know this as well. Subscribing

muhammad.tanweer’s picture

I am also trying to update the price of an item when added to cart or updated. I want to apply different price depending on quantity. I tried a custom module using hook_uc_cart_item_update and hook_uc_cart_item_insert but none of those helped. Can someone tell me what am I doing wrong please?

muhammad.tanweer’s picture

Issue summary: View changes

code

muhammad.tanweer’s picture

I had a requirement to alter the price per product on the basis of the quantity of the product added to cart. Here is how I achieved my goal.

/**
* Implements hook_uc_cart_item().
*
* Price calculation takes place here.
*/
function uc_custom_price_uc_cart_item($op, $item) {
switch ($op) {
case 'load':
$product = node_load($item->nid);
$qty_1 = $product->field_qty_1['und'][0]['value'] ? $product->field_qty_1['und'][0]['value'] : 0;
$price_1 = $product->field_price_1['und'][0]['value'] ? $product->field_price_1['und'][0]['value'] : 0;
$qty_2 = $product->field_qty_2['und'][0]['value'] ? $product->field_qty_2['und'][0]['value'] : 0;
$price_2 = $product->field_price_2['und'][0]['value'] ? $product->field_price_2['und'][0]['value'] : 0;
$qty_3 = $product->field_qty_3['und'][0]['value'] ? $product->field_qty_3['und'][0]['value'] : 0;
$price_3 = $product->field_price_3['und'][0]['value'] ? $product->field_price_3['und'][0]['value'] : 0;
$qty_4 = $product->field_qty_4['und'][0]['value'] ? $product->field_qty_4['und'][0]['value'] : 0;
$price_4 = $product->field_price_4['und'][0]['value'] ? $product->field_price_4['und'][0]['value'] : 0;

//if qty_1 and price_1 are input, these values will be included as a pricing tier
if ($qty_1 && $price_1) {
//if there is a minimum qauntity, the order quantity will automatically be set to this amount if user inputs a lesser number
if ($qty_1 > 1) {
$code = "if(\$" . "item->qty < {$qty_1}) {\$" . "item->qty = {$qty_1};} ";
}
$code .= "if(\$" . "item->qty >= {$qty_1}) {\$" . "item->price = {$price_1};} ";
}

//if qty_2 and price_2 are input, these values will be included as a pricing tier
if ($qty_2 && $price_2) {
$code .= "if(\$" . "item->qty >= {$qty_2}) {\$" . "item->price = {$price_2};} ";
}

//if qty_3 and price_3 are input, these values will be included as a pricing tier
if ($qty_3 && $price_3) {
$code .= "if(\$" . "item->qty >= {$qty_3}) {\$" . "item->price = {$price_3};} ";
}

//if qty_4 and price_4 are input, these values will be included as a pricing tier
if ($qty_4 && $price_4) {
$code .= "if(\$" . "item->qty >= {$qty_4}) {\$" . "item->price = {$price_4};} ";
}

// should really initialize this on load so we don't have to check later
// $code = isset($product->custom_code) ? $product->custom_code : '';
if (!empty($code)) {
$eval_code = token_replace($code, array('product' => $product, 'uc_cart_item' => $item));
eval($eval_code);
}
break;
}
}

/**
* Implements hook_uc_cart_alter().
*
* Fix module behavior for Ubercart version > 3.2.
*/
function uc_custom_price_uc_cart_alter(&$items) {
// manually call function for each cart item
foreach ($items as &$item) {
uc_custom_price_uc_cart_item('load', $item);
}
}

As you will see, I have 4 different quantities to alter the price for. May be this will help someone with a similar problem.

Muhammad Tanweer,
http://www.app-desk.com