//we search for this particular product in the shopping cart
					$q = "SELECT * FROM Collection_134 WHERE Collection_134_1='".$cartID."' AND Collection_134_2='".$productID."' AND Collection_134_4='".$priceID."' AND Collection_134_5 > 0";
					$res = $db->query($q);
					$productDetails = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
					
					if ($productDetails['Collection_134_3'] >= 25)
					{
							// first we check if there is a free product of this type already added
							$q = "SELECT * FROM Collection_134 WHERE Collection_134_1='".$cartID."' AND Collection_134_13 = " . $productDetails['Collection_134_ID'];
							$res = $db->query($q);
							
							$freeQuantity = floor($productDetails['Collection_134_3'] / 25);
							
							if ($res ->numRows() == 0)
							{
												$addToCartData = array();
												$addToCartData['Collection_134_1'] = $cartID;
												$addToCartData['Collection_134_2'] = $productID;
												$addToCartData['Collection_134_3'] = $freeQuantity;
												$addToCartData['Collection_134_4'] = $priceID;
												$addToCartData['Collection_134_5'] = 0;
												$addToCartData['Collection_134_6'] = "Free Product";
												$addToCartData['Collection_134_7'] = $productDetails['Collection_134_7'];
												$addToCartData['Collection_134_8'] = NULL;
												$addToCartData['Collection_134_9'] = $productDetails['Collection_134_9'];
												$addToCartData['Collection_134_10'] = 0;
												$addToCartData['Collection_134_11'] = 'Free Product for more than 25 products purchased';
												$addToCartData['Collection_134_12'] = $productDetails['Collection_134_12'];
												$addToCartData['Collection_134_13'] = $productDetails['Collection_134_ID'];
												
												$id = $db->extended->getBeforeID('Collection_134');
												$result = $db->extended->autoExecute('Collection_134', $addToCartData, MDB2_AUTOQUERY_INSERT);
												$id = $db->extended->getAfterID($id, 'Collection_134');
							
							}
							else
							{
											$addToCartData = array();
											$addToCartData['Collection_134_3'] = $freeQuantity;
											$row = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
											
											$db->extended->autoExecute('Collection_134', $addToCartData , MDB2_AUTOQUERY_UPDATE, ' Collection_134_ID = ' . $row['Collection_134_ID']);
											
											
							}//if there is free product
							
							
							
					}
					
					
					