Forums / Addon Shipping Modules / How to make inactive one shipping table if the order get more than 4 kg?

How to make inactive one shipping table if the order get more than 4 kg?

Views: 31,816

Results 1 to 20 of 21
4 May 2016, 1:00 PM
#1
bennito avatar

bennito

New Zenner

Join Date:
Jan 2016
Location:
Denmark, Copenhagen
Posts:
39
Plugin Contributions:
0

How to make inactive one shipping table if the order get more than 4 kg?

Hi guys,

I have tried to search the answer without success. So I hope somebody know the answer.

I need to make one of my table rate shipping method inactive if the order is bigger than 4 kg. The reason is because if the order is more than 5 kg. that would suppose to use bigger size box that it is allowed by the post. So that I want this shipping method to be inactive and let the user less options.

Thank you in advance!

4 May 2016, 2:14 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: How to make inactive one shipping table if the order get more than 4 kg?

What is the specific shipping module that you want to turn off when weight is greater than 4?

What version Zen Cart are you using?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

4 May 2016, 4:08 PM
#3
bennito avatar

bennito

New Zenner

Join Date:
Jan 2016
Location:
Denmark, Copenhagen
Posts:
39
Plugin Contributions:
0

Re: How to make inactive one shipping table if the order get more than 4 kg?

Hi,

The shipping module is Table shipping. Zen Cart version is 1.5.4.

4 May 2016, 4:25 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: How to make inactive one shipping table if the order get more than 4 kg?

You can customize the file:
/includes/modules/shipping/table.php

by adding the code in RED:

[B]// bof: skip if over 4
if ($shipping_weight > 4) {
  //skip
} else {
[/B]    $this->quotes = array('id' => $this->code,
    'module' => MODULE_SHIPPING_TABLE_TEXT_TITLE . $show_box_weight,
    'methods' => array(array('id' => $this->code,
    'title' => MODULE_SHIPPING_TABLE_TEXT_WAY,
    'cost' => $shipping + (MODULE_SHIPPING_TABLE_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_TABLE_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_TABLE_HANDLING) ) ));
[B]}
// eof: skip if over 4
[/B]
    if ($this->tax_class > 0) {

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

4 May 2016, 6:51 PM
#5
bennito avatar

bennito

New Zenner

Join Date:
Jan 2016
Location:
Denmark, Copenhagen
Posts:
39
Plugin Contributions:
0

Re: How to make inactive one shipping table if the order get more than 4 kg?

Ajeh,

Thank you!

It is amazing how people in this forum are helping!

So far is working perfect! Thank you again!

4 May 2016, 9:13 PM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: How to make inactive one shipping table if the order get more than 4 kg?

Thanks for the update that this is working for you ... :smile:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

8 May 2016, 12:21 PM
#7
sly_designs avatar

sly_designs

New Zenner

Join Date:
Feb 2013
Location:
Melbourne Australia
Posts:
33
Plugin Contributions:
0

Re: How to make inactive one shipping table if the order get more than 4 kg?

How cool, I've been trying to work how to do that for ages,

Very handy,

Cheers

8 May 2016, 1:45 PM
#8
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: How to make inactive one shipping table if the order get more than 4 kg?

Thanks for letting us know that this was able to help you as well ... :smile:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

2 Jun 2016, 9:16 PM
#9
hairydog avatar

hairydog

Zen Follower

Join Date:
Sep 2006
Posts:
165
Plugin Contributions:
0

Re: How to make inactive one shipping table if the order get more than 4 kg?

Is there a way to get the shipping weight of an order afterwards?

I'm trying to generate a feed file to make Interlink shipping labels. The problem is that I can't find a way to get it to include the correct weights.

There is a very old plugin that does this, but it takes the list of products in the order, works out the weight of each and uses that as the weight of the order. I'm able to add a calculation for packaging, but I'm not able to find a way to include additional weights of attributes.

It looks easy enough to do it for the contents of the basket (using the $shipping_weight), but less obvious (to me) how to do it for an order in the system. Am I missing something?

2 Jun 2016, 9:39 PM
#10
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to make inactive one shipping table if the order get more than 4 kg?

hairydog:

Is there a way to get the shipping weight of an order afterwards?

I'm trying to generate a feed file to make Interlink shipping labels. The problem is that I can't find a way to get it to include the correct weights.

There is a very old plugin that does this, but it takes the list of products in the order, works out the weight of each and uses that as the weight of the order. I'm able to add a calculation for packaging, but I'm not able to find a way to include additional weights of attributes.

It looks easy enough to do it for the contents of the basket (using the $shipping_weight), but less obvious (to me) how to do it for an order in the system. Am I missing something?
The order process includes a table for attributes (orders_products_attributes), the table on its own does not include the weight of the attributes, but does offer sufficient information to retrieve the associated attribute information that (still) exists in the store side.

There are three paths that I could see to address this. The first, would be to pull all of the order information together using a left join of the attributes order table and the data that might still exist in the store to obtain all of the weights. (risk is that at some point in the future the live store data may change, so "historical" information would be lost, but on a day-to-day basis would give up-to-date information.
The second is to modify the various orders tables to capture the weight information and during the purchase process to store that data in the applicable table. Then retrieval would be similar as above but not include the live store data, just the order info.
The third option (which I guess could be made to a fourth as well) would be to create a new table that contains all of the desired weight information and perhaps anything else seen as important to the shipping process that could be either pulled in like above or is a self standing table to obtain order weight information and then as necessary linked to other order data.

Whatever method is chosen, it could also make sense to use a combination of methods at the beginning if relatively recent historical information is needed for more than just "today's" shipment with the expectation that once the order history is "established" that only logged order info would be valued. At the same time, by having a live versus recorded comparison available, one could then compare the old with any new plans....

I know not direct code assistance, but does seem like there is some things to be considered before jumping in with code.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

3 Jun 2016, 12:53 PM
#11
hairydog avatar

hairydog

Zen Follower

Join Date:
Sep 2006
Posts:
165
Plugin Contributions:
0

Re: How to make inactive one shipping table if the order get more than 4 kg?

mc12345678:

The order process includes a table for attributes (orders_products_attributes), the table on its own does not include the weight of the attributes, but does offer sufficient information to retrieve the associated attribute information that (still) exists in the store side.There are three paths that I could see to address this. The first, would be to pull all of the order information together using a left join of the attributes order table and the data that might still exist in the store to obtain all of the weights. (risk is that at some point in the future the live store data may change, so "historical" information would be lost, but on a day-to-day basis would give up-to-date information.Thanks for confirming that the data isn't stored anywhere in the order record. Seems odd that it isn't, but there you are. It looks like the orders_products_attributes table has the attributes weight but the orders_products table lacks the products weights - need to go to the products table for that info.This is only needed for generating shipping labels, so it doesn't matter that there is no long term storage of attribute weights. So a left join is probably all that is needed. I just wish I was better at writing this sort of code!Right now I have$proids_query="SELECT * FROM " . TABLE_PRODUCTS." as t2 WHERE t2.products_id = $prodid "; $Orderedproductweight = $db->Execute($proids_query) ; $sum = $Orderedproductweight->fields['products_weight']; ```
$sum=$sum * $prodnum; $totalweight=1.15*($totalweight+$sum+0.02);

3 Jun 2016, 1:29 PM
#12
hairydog avatar

hairydog

Zen Follower

Join Date:
Sep 2006
Posts:
165
Plugin Contributions:
0

Re: How to make inactive one shipping table if the order get more than 4 kg?

This seems to work- but I can't persuade it to look readable in this message!```php
$proid_query="SELECT * FROM " . TABLE_ORDERS_PRODUCTS . " as t1 LEFT JOIN orders_products_attributes t3 ON t1.orders_products_id = t3.orders_products_id WHERE t1.orders_id = $orderid"; $Orderedproduct = $db->Execute($proid_query); // sum total weight while (!$Orderedproduct->EOF) { $prodid = $Orderedproduct->fields['products_id']; $prodnum = $Orderedproduct->fields['products_quantity']; $proids_query="SELECT * FROM " . TABLE_PRODUCTS." as t2 WHERE t2.products_id = $prodid "; $Orderedproductweight = $db->Execute($proids_query) ; $sumprod = $Orderedproductweight->fields['products_weight']; $sumattrib = $Orderedproduct->fields['products_attributes_weight']; $sum = $sumprod+$sumattrib;$sum=$sum * $prodnum; // allow for packaging $totalweight=$totalweight+(1.15 * $sum);

3 Jun 2016, 2:31 PM
#13
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to make inactive one shipping table if the order get more than 4 kg?

Here is a suggestion on the code updated to reduce the query load, to add a little data sanitization (which could be done in a few different ways), and to address the possibility that a product could have more than one attribute associated (which would have added the weight of the product for each attribute associated with the product.

I tried to highlight the changes.

$proid_query="SELECT t1.products_id, t1.products_quantity, 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 WHERE t1.orders_id = " . (int)$orderid; 
$Orderedproduct = $db->Execute($proid_query); 

$prevProdID = 0;

// sum total weight 
while (!$Orderedproduct->EOF) 
{ 
  $prodid = $Orderedproduct->fields['products_id']; 
  $prodnum = $Orderedproduct->fields['products_quantity']; 

  $proids_query="SELECT t2.products_weight FROM " . TABLE_PRODUCTS." as t2 WHERE t2.products_id = " . (int)$prodid; 
  $Orderedproductweight = $db->Execute($proids_query) ; 

  if ($prodid != $prevProdID) {
    $sumprod = $Orderedproductweight->fields['products_weight'];
    $prevProdId = $prodid;
  } else {
    $sumprod = 0;
  }

  $sumattrib = $Orderedproduct->fields['products_attributes_weight']; 
  $sum = $sumprod+$sumattrib;
  $sum=$sum * $prodnum; 
  // allow for packaging 
  $totalweight=$totalweight+(1.15 * $sum);
  $Orderedproduct->MoveNext();
}
 

The original query could also be made as:

$proid_query="SELECT t1.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; 

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

3 Jun 2016, 2:59 PM
#14
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to make inactive one shipping table if the order get more than 4 kg?

Sorry I ran out of time to revise my message... Bad habit, but I review the code after posting and then see things.. :/

Below is yet a further revised untested code. Seems to have what you are seeking. I also reformatted a few things including adding the reference to the orders_products_attributes table to be compatible with those using a DB_PREFIX.

$proid_query="SELECT t1.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; 
$Orderedproduct = $db->Execute($proid_query); 

$prevProdID = 0;

// sum total weight 
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_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; 
  // allow for packaging 
  $totalweight=$totalweight+(1.15 * $sum);
  $Orderedproduct->MoveNext();
}
 

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

3 Jun 2016, 5:24 PM
#15
hairydog avatar

hairydog

Zen Follower

Join Date:
Sep 2006
Posts:
165
Plugin Contributions:
0

Re: How to make inactive one shipping table if the order get more than 4 kg?

That's marvellous - works a treat! Thank you so much for that.

9 Jun 2016, 10:03 PM
#16
hairydog avatar

hairydog

Zen Follower

Join Date:
Sep 2006
Posts:
165
Plugin Contributions:
0

Re: How to make inactive one shipping table if the order get more than 4 kg?

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?

10 Jun 2016, 12:26 PM
#17
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to make inactive one shipping table if the order get more than 4 kg?

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;

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

10 Jun 2016, 4:02 PM
#18
hairydog avatar

hairydog

Zen Follower

Join Date:
Sep 2006
Posts:
165
Plugin Contributions:
0

Re: How to make inactive one shipping table if the order get more than 4 kg?

Unfortunately, that does exactly the same. It seems to be looping round the product weight once fer each attribute entry.

I've been trying to separate the queries so that it looks up the product weights first, then uses a separate query to look up the attribute weights, then adds the results together and multiplies the result by the quantity ordered, but without much success.

10 Jun 2016, 4:25 PM
#19
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to make inactive one shipping table if the order get more than 4 kg?

hairydog:

Unfortunately, that does exactly the same. It seems to be looping round the product weight once fer each attribute entry.

I've been trying to separate the queries so that it looks up the product weights first, then uses a separate query to look up the attribute weights, then adds the results together and multiplies the result by the quantity ordered, but without much success.

There's a typo. I may have introduced it, not sure, not going back to check:

 if ($prodid != $prevProdID) {
    $sumprod = $Orderedproduct->fields['products_weight'];
    $prevProdI[b]D[/b] = $prodid;
  }   

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

10 Jun 2016, 4:41 PM
#20
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to make inactive one shipping table if the order get more than 4 kg?

I believe either method of the previous code with that typo corrected would provide the desired result as there is one orders_products_id for each unique product added to the cart (two products each having a different set of attributes will each have a unique orders_products_id). As well, each product added to the cart is expected to have a unique products_prid for any two or more product having attributes. Any two or more product having the same attributes (or none) will be treated by the cart as an additional quantity of the first one added, therefore within an order, the products_prid is expected to be unique for each product or quantity of product added to the cart.

Seems to me though that the first one is lighter on the database engine/more efficient. Though a method like you are describing would likely be clearer code:
Obtain each product and related other table relationship.
Obtain the information from the order_products_attributes table for the order and the specific product. If there are attributes, add the weight, if not use the product's weight and then multiply by the quantity.

Involves a lot more code and frequent queries to the database, but later could offer expansion/modification to use that data in other ways not yet envisioned...

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...