Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

HELP how shopping-cart information stored?


nicklestud

Recommended Posts

Posted

Hello,

 

I am trying to write code that will check the customers shopping cart information every time a shipping module is called up. For instance, I can not use USPS to ship certain items, so if I can check the customers shopping cart for that item, I can cause the USPS options not to be displayed.

 

I do not know how it works.

 

How does OSC store each customers shopping cart information?

 

I know that this will print out the customers shopping-cart total weight:

 

global $shipping_weight;

echo "Your order is: " . $shipping_weight . " lbs."

 

BUT..

 

How can I write similar code that will print out the customer shopping-cart's items, or item "product_id"?

 

Your help is grealy appreciated.

Posted
Hello,

 

I am trying to write code that will check the customers shopping cart information every time a shipping module is called up. For instance, I can not use USPS to ship certain items, so if I can check the customers shopping cart for that item, I can cause the USPS options not to be displayed.

 

I do not know how it works.

 

How does OSC store each customers shopping cart information?

 

I know that this will print out the customers shopping-cart total weight:

 

global $shipping_weight;

echo "Your order is: " . $shipping_weight .  " lbs."

 

BUT..

 

How can I write similar code that will print out the customer shopping-cart's items, or item "product_id"?

 

Your help is grealy appreciated.

 

 

shopping cart is a session stored class instance.

 

so if you want to know if a certain product is in the cart you write :

 

if ($cart->in_cart($product_id)) {

echo 'it is in there';

} else {

echo 'it is not in there';

}

Treasurer MFC

Posted
shopping cart is a session stored class instance.

 

so if you want to know if a certain product is in the cart you write :

 

if ($cart->in_cart($product_id)) {

  echo 'it is in there';

} else {

  echo 'it is not in there';

}

 

 

by the way, you can have a look in class shopping_cart.php to see al the functions it supports and even add your own.

you always call the classes with:

 

class_instance_name->class_function

Treasurer MFC

Posted

There is something about your code examples that puts a smile on my face :) Always correct and easy to understand...

 

Bobby

Posted

I've done something similar, not showing the shipping methods when there is 0 weight.

 

For me to make this work, I added weight to the order products array; in includes/classes/order.php I know have this (changed the sql and added weight to the array)

      $index = 0;
     $orders_products_query = tep_db_query("select orders_products_id, op.products_id, products_name, products_model, p.products_weight, products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . "op, " . TABLE_PRODUCTS ."p where op.orders_products_id = p.products_id and orders_id = '" . (int)$order_id . "'");
     while ($orders_products = tep_db_fetch_array($orders_products_query)) {
       $this->products[$index] = array('qty' => $orders_products['products_quantity'],
                                'id' => $orders_products['products_id'],
                                       'name' => $orders_products['products_name'],
                                       'model' => $orders_products['products_model'],
                                       'weight' => $orders_products['products_weight'],
                                       'tax' => $orders_products['products_tax'],
                                       'price' => $orders_products['products_price'],
                                       'final_price' => $orders_products['final_price']);

 

And then each shipping method that shouldn't be available, I added in the followin g code:

        for ($i=1; $i <= sizeof($order->products); $i++ ){
         if ( $order->products[$i]['weight'] == '0' ) {
           $this->quotes['error'] = '';
           return $this->quotes;        
         }
       }

also sometimes, adding global $order was also still needed.

 

I decided to not show anything if the method is not available. This is because to really iron it out, I should have a single message for the 'no weight maintained' condition and show it only once, while right now, an error message shows for each shipping module.

 

Hope this gives you some inspiration

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Posted
shopping cart is a session stored class instance.

 

so if you want to know if a certain product is in the cart you write :

 

if ($cart->in_cart($product_id)) {

  echo 'it is in there';

} else {

  echo 'it is not in there';

}

 

actually, what I did was just change the $order object into an array. Then just looked for some words in the title of the product description. I put a sample below. I think your code is cleaner and might try to adjust this later:

 

          $order_array = (array)$order;
  $products_size = count($order_array['products']);
  $string_look = 'no USPS';  //search for string in item name
  
  for ($i=0; $i<$products_size; i++){	
   $products_name = $order_array['products'][$i]['name'];
 if ( strpos($products_name, $string_look) ){
	 return(false);  //return "false"  
 }

 

After this code, I was just able to put the words "no USPS" in each product I did not want shipped using USPS. if "no USPS" was in the item title description, the USPS module returned false and the error message popped up.

 

The error message is desireable since I explain in the error why USPS can not be used.

Posted
I've done something similar, not showing the shipping methods when there is 0 weight.

 

For me to make this work, I added weight to the order products array; in includes/classes/order.php I know have this (changed the sql and added weight to the array)

      $index = 0;
     $orders_products_query = tep_db_query("select orders_products_id, op.products_id, products_name, products_model, p.products_weight, products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . "op, " . TABLE_PRODUCTS ."p where op.orders_products_id = p.products_id and orders_id = '" . (int)$order_id . "'");
     while ($orders_products = tep_db_fetch_array($orders_products_query)) {
       $this->products[$index] = array('qty' => $orders_products['products_quantity'],
                                'id' => $orders_products['products_id'],
                                       'name' => $orders_products['products_name'],
                                       'model' => $orders_products['products_model'],
                                       'weight' => $orders_products['products_weight'],
                                       'tax' => $orders_products['products_tax'],
                                       'price' => $orders_products['products_price'],
                                       'final_price' => $orders_products['final_price']);

 

And then each shipping method that shouldn't be available, I added in the followin g code:

        for ($i=1; $i <= sizeof($order->products); $i++ ){
         if ( $order->products[$i]['weight'] == '0' ) {
           $this->quotes['error'] = '';
           return $this->quotes;        
         }
       }

also sometimes, adding global $order was also still needed.

 

I decided to not show anything if the method is not available. This is because to really iron it out, I should have a single message for the 'no weight maintained' condition and show it only once, while right now, an error message shows for each shipping module.

 

Hope this gives you some inspiration

 

 

in most modules you can simply set the enable flag to false in condition.

Treasurer MFC

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...