Hello Zahid,
Here's what I've got for the mod so far... kind of a beta version, but hopefully it will help solve your situation.
I had this working on a live site, but as I'm trying to make the code scalable for use on any website, I'm running into trouble getting it to work just right. I'll keep at it. If there are any other Zen Cart pros on here that would like to have a look and let me know why this would or wouldn't work, or if there may be vulnerabilities in editing this code, then please feel free to give some feedback ;)
Anyhow, you want to edit this file: includes/classes/shopping_cart.php
Find the following code (should be around line 1180):
PHP Code:
$products_array[] = array('id' => $products_id,
'category' => $products->fields['master_categories_id'],
'name' => $products->fields['products_name'],
'model' => $products->fields['products_model'],
'image' => $products->fields['products_image'],
'price' => ($products->fields['product_is_free'] =='1' ? 0 : $products_price),
// 'quantity' => $this->contents[$products_id]['qty'],
'quantity' => $new_qty,
'weight' => $products->fields['products_weight'] + $this->attributes_weight($products_id),
// fix here
'final_price' => ($products_price + $this->attributes_price($products_id)),
'onetime_charges' => ($this->attributes_price_onetime_charges($products_id, $new_qty)),
'tax_class_id' => $products->fields['products_tax_class_id'],
'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''),
'attributes_values' => (isset($this->contents[$products_id]['attributes_values']) ? $this->contents[$products_id]['attributes_values'] : ''),
'products_priced_by_attribute' => $products->fields['products_priced_by_attribute'],
'product_is_free' => $products->fields['product_is_free'],
'products_discount_type' => $products->fields['products_discount_type'],
'products_discount_type_from' => $products->fields['products_discount_type_from']);
}
}
$this->notify('NOTIFIER_CART_GET_PRODUCTS_END');
return $products_array;
}
And REPLACE with this:
PHP Code:
//begin Attribute Calculator 1.0
//Zen Cart contribution by JT Website Design http://www.jtwebsitedesign.com
$description_sql = 'SELECT products_name FROM ' . TABLE_PRODUCTS_DESCRIPTION . ' where products_id = "' . (int) $products_id . '"';
$pdescription = $db->Execute($description_sql);
$products_name = $pdescription->fields['products_name'];
switch($products->fields['products_name'])
{
case 'Product A':
$priceFactor = 1.00;
break;
case 'Product B':
$priceFactor = 0.50;
break;
case 'Product C':
$priceFactor = 1.25;
break;
default:
$priceFactor = 0;
}
if($priceFactor != 0)
{
$Length_ID_Query = "select products_options_id from " . TABLE_PRODUCTS_OPTIONS . " where products_options_name = 'Length'";
$Length_ID = $db->Execute($Length_ID_Query);
$LengthID = (int)$Length_ID->fields['products_options_id'];
$Width_ID_Query = "select products_options_id from " . TABLE_PRODUCTS_OPTIONS . " where products_options_name = 'Width'";
$Width_ID = $db->Execute($Width_ID_Query);
$WidthID = (int)$Width_ID->fields['products_options_id'];
if ($this->contents[$products_id]['attributes_values'][$WidthID] && $this->contents[$products_id]['attributes_values'][$LengthID])
$areaFactor = $this->contents[$products_id]['attributes_values'][$WidthID]*$this->contents[$products_id]['attributes_values'][$LengthID];
else
$areaFactor = 0;
$extraCharge = $areaFactor * $priceFactor;
}
else
$extraCharge = 0;
//end Attribute Calculator 1.0
$products_array[] = array('id' => $products_id,
'category' => $products->fields['master_categories_id'],
'name' => $products->fields['products_name'],
'model' => $products->fields['products_model'],
'image' => $products->fields['products_image'],
'price' => ($products->fields['product_is_free'] =='1' ? 0 : $products_price+$extraCharge),
// 'quantity' => $this->contents[$products_id]['qty'],
'quantity' => $new_qty,
'weight' => $products->fields['products_weight'] + $this->attributes_weight($products_id),
// fix here
'final_price' => ($products_price + $this->attributes_price($products_id) + $extraCharge),
'onetime_charges' => ($this->attributes_price_onetime_charges($products_id, $new_qty)),
'tax_class_id' => $products->fields['products_tax_class_id'],
'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''),
'attributes_values' => (isset($this->contents[$products_id]['attributes_values']) ? $this->contents[$products_id]['attributes_values'] : ''),
'products_priced_by_attribute' => $products->fields['products_priced_by_attribute'],
'product_is_free' => $products->fields['product_is_free'],
'products_discount_type' => $products->fields['products_discount_type'],
'products_discount_type_from' => $products->fields['products_discount_type_from']);
}
}
$this->notify('NOTIFIER_CART_GET_PRODUCTS_END');
return $products_array;
}
So, what you'll want to do is change "Product A", "Product B", etc to match the names of your product. Then you can put a price per square foot (the variable for this is $PriceFactor), which can be specified for each individual product.
If you want the same price per square foot for all products, the above code can be modified a bit, and you can hard code the PriceFactor to be a specific number, removing the cases per product.
Hope it makes sense and helps out a bit! Let me know if it works for you