winstanley_john Posted July 20, 2004 Posted July 20, 2004 Hello All at oscommerce! I needed to change the way products where treated in the shopping cart and had to play with the contents array that acts as data storage for the shopping cart. See this line $this->contents[] = array($products_id); in catalog\includes\classes\shopping_cart.php (about line 90) if ($this->in_cart($products_id)) { $this->update_quantity($products_id, $qty, $attributes); } else { $this->contents[] = array($products_id); $this->contents[$products_id] = array('qty' => $qty); The line indicated adds a new element to the array at the end of the contents array. The line after it adds the product to the correct position in the array. Why does the first line exist? Running this test script and observing the outcome shows that this mechanism adds too much data to the cart. $products_id = array(10,12,14,16); $qty = array(10,12,14,16); $contents = array(); $contents[] = array($products_id[0]); $contents[$products_id[0]] = array('qty' => $qty[0]); $contents[] = array($products_id[1]); $contents[$products_id[1]] = array('qty' => $qty[1]); $contents[] = array($products_id[2]); $contents[$products_id[2]] = array('qty' => $qty[2]); $contents[] = array($products_id[3]); $contents[$products_id[3]] = array('qty' => $qty[3]); echo "<pre>"; print_r($contents); echo "</pre>"; The outcome is Array ( [0] => Array ( [0] => 10 ) [10] => Array ( [qty] => 10 ) [11] => Array ( [0] => 12 ) [12] => Array ( [qty] => 12 ) [13] => Array ( [0] => 14 ) [14] => Array ( [qty] => 14 ) [15] => Array ( [0] => 16 ) [16] => Array ( [qty] => 16 ) ) At the end of the method the content array is cleaned to "remove the extra value". Should this value be there atall? http://spaces.msn.com/members/JohnWinstanley/ http://www.angelsolutions.co.uk
winstanley_john Posted July 20, 2004 Author Posted July 20, 2004 Shouldn't foreach be used here? list each is a bit complecated // Take value from contents array assign its key to products_id while (list($products_id, ) = each($this->contents)) { http://spaces.msn.com/members/JohnWinstanley/ http://www.angelsolutions.co.uk
Recommended Posts
Archived
This topic is now archived and is closed to further replies.