Forums / Setting Up Categories, Products, Attributes / How to get products attributes from cart?

How to get products attributes from cart?

Locked

Views: 2,525

Results 1 to 3 of 3
This thread is locked. New replies are disabled.
19 Aug 2006, 12:58 PM
#1
jarsa avatar

jarsa

New Zenner

Join Date:
May 2006
Posts:
45
Plugin Contributions:
0

How to get products attributes from cart?

I need to walk through all the products in the cart to see if defined products exist. Function below works just fine with ID´s, no matter if products come with attributes or without them. It just returns products clear ID from the cart without :43fds45.... ending.

function get_products_id() {

 if (!is_array ($products_id_array)) $products_id_array = array();
 
 $products = $_SESSION['cart']->get_products();
 	    for ($i=0; $i<sizeof($products); $i++) {
	  $products_id_array[] = zen_get_prid($products[$i]['id']);
	}
  return $products_id_array;     
}

BUT!!! How do I get options_value_id´s with products ID´s if them exist in the cart?? So I need to have output with products_id and products_options_value_id (or at least products final_price) just something with to recognize products attributes.

I hope there is an easy answer for this...or actually any kind of answer! :sleepy:

-Jarsa-.

21 Aug 2006, 7:17 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: How to get products attributes from cart?

Kinda depends on the use. What are you planning to do with this information?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

21 Aug 2006, 10:17 AM
#3
jarsa avatar

jarsa

New Zenner

Join Date:
May 2006
Posts:
45
Plugin Contributions:
0

Re: How to get products attributes from cart?

Ciao!

I allready solved my problem. It may not be very stylish solution, but it works fine for me. Function returns products_options_values_id to calling class when products_id and its options_id are given.

This function returns only one option_values_id because there can be only one of these products in my customers cart. If cart contains several same product_id´s, returned value will be the last added options value_id.

function get_products_options_values_id($products_id, $option_id) {

  $products = $_SESSION['cart']->get_products();
  	  for ($i=0; $i<sizeof($products); $i++) {
		  $products_id_array[] = zen_get_prid($products[$i]['id']);
	  		  $products_attributes_array[] = products[$i]['attributes'][$option_id];
	 		}
	 			    
	$products_options_array = array_combine($products_id_array, $products_attributes_array);
	   foreach ($products_options_array as $products_id => $products_options_values_id) {
 
  return $products_options_values_id;     
 }
}

I´ll be asking more questions soon :wink2: ,
Jarsa