hairydog:
Oops! It isn't working quite as well as I thought.
What it is doing is to add the product's weigh to the attribute's weight for each attribute
For example, a product with a weight of 3, and attributes weighing 0.3 and 0.4 should come out weighing 3.7 (which is 4.275 after packing allowance) but it actually comes out at 3.3 + 3.4 = 6.7 (7.725).
If it has three attributes, weighing 0, 0.3, 0.4 the same item comes out weighing 3 + 3.3 + 3.4 = 9.7 (which is 11.175 after packing allowance)
If the three attributes weigh 0, it comes out at 9 (10.37)
This is the code I'm using:
$proid_query="SELECT t1.products_id, t1.orders_products_id, t1.products_quantity, t2.products_weight, t3.products_attributes_weight FROM " . TABLE_ORDERS_PRODUCTS . " as t1
LEFT JOIN " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " t3 ON t1.orders_products_id = t3.orders_products_id
LEFT JOIN " . TABLE_PRODUCTS." t2 ON t1.products_id = t2.products_id
WHERE t1.orders_id = " . (int)$orderid;
// not using comments 1 of 2
// next line grabs the comments to output on the interlink labels
// $comments_query ="SELECT comments FROM orders_status_history WHERE orders_id = $orderid ORDER BY orders_status_history_id LIMIT 1";
// Now start per product within an order
$Orderedproduct = $db->Execute($proid_query);
$prevProdID = 0;
// sum total weight of each item in this order
while (!$Orderedproduct->EOF)
{
$sumprod = 0.0; // Added in case a product has more than one attribute so that the previous value is not carried forward.
$sumattrib = 0.0; // Added in case a product does not have an attribute that the previous value is not carried forward.
$prodid = $Orderedproduct->fields['orders_products_id'];
$prodnum = $Orderedproduct->fields['products_quantity'];
if ($prodid != $prevProdID) {
$sumprod = $Orderedproduct->fields['products_weight'];
$prevProdId = $prodid;
}
if (zen_not_null($Orderedproduct->fields['products_attributes_weight'])) {
$sumattrib = $Orderedproduct->fields['products_attributes_weight'];
}
$sum = $sumprod+$sumattrib;
$sum=$sum * $prodnum;
$totalweight = $totalweight+$sum;
$Orderedproduct->MoveNext();
}
// that finishes the per product bit
// The rest is per order
// allow for packaging (per order)
$totalweight=(1.15*$totalweight)+0.02;
>
> Can anyone help me out with getting it to only add the product weight once per product, not once per attribute?
Seemed like something was wrong with that, but hadn't quite realized what it would be.
The below is modified from above and might accomplish the requested action.
$proid_query="SELECT t1.products_id, t1.orders_products_id, t1.products_quantity, t1.products_prid, t2.products_weight, t3.products_attributes_weight FROM " . TABLE_ORDERS_PRODUCTS . " as t1
LEFT JOIN " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " t3 ON t1.orders_products_id = t3.orders_products_id
LEFT JOIN " . TABLE_PRODUCTS." t2 ON t1.products_id = t2.products_id
WHERE t1.orders_id = " . (int)$orderid . " ORDER BY t1.products_prid";
// not using comments 1 of 2
// next line grabs the comments to output on the interlink labels
// $comments_query ="SELECT comments FROM orders_status_history WHERE orders_id = $orderid ORDER BY orders_status_history_id LIMIT 1";
// Now start per product within an order
$Orderedproduct = $db->Execute($proid_query);
$prevProdID = 0;
// sum total weight of each item in this order
while (!$Orderedproduct->EOF)
{
$sumprod = 0.0; // Added in case a product has more than one attribute so that the previous value is not carried forward.
$sumattrib = 0.0; // Added in case a product does not have an attribute that the previous value is not carried forward.
$prodid = $Orderedproduct->fields['products_prid'];
$prodnum = $Orderedproduct->fields['products_quantity'];
if ($prodid != $prevProdID) {
$sumprod = $Orderedproduct->fields['products_weight'];
$prevProdId = $prodid;
}
if (zen_not_null($Orderedproduct->fields['products_attributes_weight'])) {
$sumattrib = $Orderedproduct->fields['products_attributes_weight'];
}
$sum = $sumprod+$sumattrib;
$sum=$sum * $prodnum;
$totalweight = $totalweight+$sum;
$Orderedproduct->MoveNext();
}
// that finishes the per product bit
// The rest is per order
// allow for packaging (per order)
$totalweight=(1.15*$totalweight)+0.02;