/**
  * Adds a new Shopper Group
  *
  * @param array $d
  * @return boolean
  */
 function add(&$d)
 {
     global $perm, $vmLogger, $VM_LANG;
     $hash_secret = "virtuemart";
     if ($perm->check("admin")) {
         $vendor_id = $d["vendor_id"];
     } else {
         $vendor_id = $_SESSION["ps_vendor_id"];
     }
     $db = new ps_DB();
     $timestamp = time();
     $default = @$d["default"] == "1" ? "1" : "0";
     if (!$this->validate_add($d)) {
         return False;
     }
     $user_id = md5(uniqid($hash_secret));
     $fields = array('vendor_id' => $vendor_id, 'shopper_group_name' => $d["shopper_group_name"], 'shopper_group_desc' => $d["shopper_group_desc"], 'shopper_group_discount' => $d["shopper_group_discount"], 'show_price_including_tax' => $d["show_price_including_tax"], 'default' => $default);
     $db->buildQuery('INSERT', '#__{vm}_shopper_group', $fields);
     if ($db->query() !== false) {
         $shopper_group_id = $db->last_insert_id();
         vmRequest::setVar('shopper_group_id', $shopper_group_id);
         $vmLogger->info($VM_LANG->_('SHOPPER_GROUP_ADDED'));
         // Set all other shopper groups to be non-default, if this new shopper group shall be "default"
         if ($default == "1") {
             $q = "UPDATE #__{vm}_shopper_group ";
             $q .= "SET `default`=0 ";
             $q .= "WHERE shopper_group_id !=" . $shopper_group_id;
             $q .= " AND vendor_id ={$vendor_id}";
             $db->query($q);
             $db->next_record();
         }
         return $_REQUEST['shopper_group_id'];
     }
     $vmLogger->err($VM_LANG->_('SHOPPER_GROUP_ADD_FAILED'));
     return false;
 }
Example #2
0
 /**
  * Validates product fields and uploaded image files.
  *
  * @param array $d The input vars
  * @return boolean True when validation successful, false when not
  */
 function validate(&$d)
 {
     global $vmLogger, $database, $perm, $VM_LANG;
     require_once CLASSPATH . 'imageTools.class.php';
     $valid = true;
     $db = new ps_DB();
     $q = "SELECT product_id,product_thumb_image,product_full_image FROM #__{vm}_product WHERE product_sku='";
     $q .= $d["product_sku"] . "'";
     $db->setQuery($q);
     $db->query();
     if ($db->next_record() && $db->f("product_id") != $d["product_id"]) {
         $vmLogger->err("A Product with the SKU " . $d['product_sku'] . " already exists.");
         $valid = false;
     }
     if (!empty($d['product_discount_id'])) {
         if ($d['product_discount_id'] == "override") {
             $d['is_percent'] = "0";
             // If discount are applied before tax then base the discount on the untaxed price
             if (PAYMENT_DISCOUNT_BEFORE == '1') {
                 $d['amount'] = (double) $d['product_price'] - (double) $d['discounted_price_override'];
             } else {
                 $d['amount'] = (double) $d['product_price_incl_tax'] - (double) $d['discounted_price_override'];
             }
             // Set the discount start date as today
             $d['start_date'] = date('Y-m-d');
             require_once CLASSPATH . 'ps_product_discount.php';
             $ps_product_discount = new ps_product_discount();
             $ps_product_discount->add($d);
             $d['product_discount_id'] = $database->insertid();
             vmRequest::setVar('product_discount_id', $d['product_discount_id']);
         }
     }
     if (empty($d['manufacturer_id'])) {
         $d['manufacturer_id'] = "1";
     }
     if (empty($d["product_sku"])) {
         $vmLogger->err($VM_LANG->_('VM_PRODUCT_MISSING_SKU', false));
         $valid = false;
     }
     if (!$d["product_name"]) {
         $vmLogger->err($VM_LANG->_('VM_PRODUCT_MISSING_NAME', false));
         $valid = false;
     }
     if (empty($d["product_available_date"])) {
         $vmLogger->err($VM_LANG->_('VM_PRODUCT_MISSING_AVAILDATE', false));
         $valid = false;
     } else {
         $day = (int) substr($d["product_available_date"], 8, 2);
         $month = (int) substr($d["product_available_date"], 5, 2);
         $year = (int) substr($d["product_available_date"], 0, 4);
         $d["product_available_date_timestamp"] = mktime(0, 0, 0, $month, $day, $year);
     }
     /** Validate Product Specific Fields **/
     if (!$d["product_parent_id"]) {
         if (empty($d['product_categories']) || !is_array(@$d['product_categories'])) {
             $d['product_categories'] = explode('|', $d['category_ids']);
         }
         if (sizeof(@$d["product_categories"]) < 1) {
             $vmLogger->err($VM_LANG->_('VM_PRODUCT_MISSING_CATEGORY'));
             $valid = false;
         }
     }
     /** Image Upload Validation **/
     // do we have an image URL or an image File Upload?
     if (!empty($d['product_thumb_image_url'])) {
         // Image URL
         if (substr($d['product_thumb_image_url'], 0, 4) != "http") {
             $vmLogger->err($VM_LANG->_('VM_PRODUCT_IMAGEURL_MUSTBEGIN', false));
             $valid = false;
         }
         // if we have an uploaded image file, prepare this one for deleting.
         if ($db->f("product_thumb_image") && substr($db->f("product_thumb_image"), 0, 4) != "http") {
             $_REQUEST["product_thumb_image_curr"] = $db->f("product_thumb_image");
             $d["product_thumb_image_action"] = "delete";
             if (!vmImageTools::validate_image($d, "product_thumb_image", "product")) {
                 return false;
             }
         }
         $d["product_thumb_image"] = $d['product_thumb_image_url'];
     } else {
         // File Upload
         if (!vmImageTools::validate_image($d, "product_thumb_image", "product")) {
             $valid = false;
         }
     }
     if (!empty($d['product_full_image_url'])) {
         // Image URL
         if (substr($d['product_full_image_url'], 0, 4) != "http") {
             $vmLogger->err($VM_LANG->_('VM_PRODUCT_IMAGEURL_MUSTBEGIN', false));
             return false;
         }
         // if we have an uploaded image file, prepare this one for deleting.
         if ($db->f("product_full_image") && substr($db->f("product_full_image"), 0, 4) != "http") {
             $_REQUEST["product_full_image_curr"] = $db->f("product_full_image");
             $d["product_full_image_action"] = "delete";
             if (!vmImageTools::validate_image($d, "product_full_image", "product")) {
                 return false;
             }
         }
         $d["product_full_image"] = $d['product_full_image_url'];
     } else {
         // File Upload
         if (!vmImageTools::validate_image($d, "product_full_image", "product")) {
             $valid = false;
         }
     }
     // validate attribute names
     foreach ($d["attributeX"] as $attributeX) {
         // if we only have one attribute it can be left empty
         if ($attributeX["name"] == "" and count($d["attributeX"]) > 1) {
             $vmLogger->err($VM_LANG->_('VM_PRODUCT_MISSING_ATTRIBUTE_NAME', false));
             $valid = false;
         }
         if (strpos($attributeX["name"], ":") or strpos($attributeX["name"], ".") or strpos($attributeX["name"], "&") or strpos($attributeX["name"], "'")) {
             $vmLogger->err($VM_LANG->_('VM_PRODUCT_INVALID_ATTRIBUTE_NAME', false));
             $valid = false;
         }
     }
     // added for advanced attribute modification
     // strips the trailing semi-colon from an attribute
     if (isset($d["product_advanced_attribute"])) {
         if (';' == substr($d["product_advanced_attribute"], strlen($d["product_advanced_attribute"]) - 1, 1)) {
             $d["product_advanced_attribute"] = substr($d["product_advanced_attribute"], 0, strlen($d["product_advanced_attribute"]) - 1);
         }
     }
     // added for custom attribute modification
     // strips the trailing semi-colon from an attribute
     if (isset($d["product_custom_attribute"])) {
         if (';' == substr($d["product_custom_attribute"], strlen($d["product_custom_attribute"]) - 1, 1)) {
             $d["product_custom_attribute"] = substr($d["product_custom_attribute"], 0, strlen($d["product_custom_attribute"]) - 1);
         }
     }
     $d["clone_product"] = empty($d["clone_product"]) ? "N" : "Y";
     $d["product_publish"] = empty($d["product_publish"]) ? "N" : "Y";
     $d["product_special"] = empty($d["product_special"]) ? "N" : "Y";
     //parse quantity and child options
     $d['display_headers'] = vmGet($d, 'display_headers', 'Y') == 'Y' ? 'Y' : 'N';
     $d['product_list_child'] = vmGet($d, 'product_list_child', 'Y') == 'Y' ? 'Y' : 'N';
     $d['display_use_parent'] = vmGet($d, 'display_use_parent', 'Y') == 'Y' ? 'Y' : 'N';
     $d['product_list_type'] = vmGet($d, 'product_list_type', 'Y') == 'Y' ? 'Y' : 'N';
     $d['display_desc'] = vmGet($d, 'display_desc', 'Y') == 'Y' ? 'Y' : 'N';
     if (@$d['product_list'] == "Y") {
         if ($d['list_style'] == "one") {
             $d['product_list'] = "Y";
         } else {
             $d['product_list'] = "YM";
         }
     } else {
         $d['product_list'] = "N";
     }
     $d['quantity_options'] = ps_product::set_quantity_options($d);
     $d['child_options'] = ps_product::set_child_options($d);
     $d['order_levels'] = vmRequest::getInt('min_order_level') . "," . vmRequest::getInt('max_order_level');
     return $valid;
 }
Example #3
0
 /**
  * Returns a link tag
  *
  * @param string $href
  * @param string $type
  * @param string $rel
  * @return string
  */
 function linkTag($href, $type = 'text/css', $rel = 'stylesheet', $media = "screen, projection")
 {
     global $mosConfig_gzip, $mosConfig_live_site;
     if (isset($_REQUEST['usefetchscript'])) {
         $use_fetchscript = vmRequest::getBool('usefetchscript', 1);
         vmRequest::setVar('usefetchscript', $use_fetchscript, 'session');
     } else {
         $use_fetchscript = vmRequest::getBool('usefetchscript', 1, 'session');
     }
     if (stristr($href, 'com_virtuemart') && $use_fetchscript) {
         $base_href = str_replace(URL, '', $href);
         $base_href = str_replace(SECUREURL, '', $base_href);
         $base_href = str_replace('components/com_virtuemart/', '', $base_href);
         $href = $mosConfig_live_site . '/components/com_virtuemart/fetchscript.php?gzip=' . $mosConfig_gzip . '&amp;subdir[0]=' . dirname($base_href) . '&amp;file[0]=' . basename($href);
     }
     return '<link type="' . $type . '" href="' . $href . '" rel="' . $rel . '"' . (empty($media) ? '' : ' media="' . $media . '"') . ' />' . "\n";
 }
Example #4
0
 /**
  * Updates a Shipping Adress for the specified user info ID
  *
  * @param array $d
  * @return boolean
  */
 function update(&$d)
 {
     global $perm, $VM_LANG;
     require_once CLASSPATH . 'ps_userfield.php';
     $db = new ps_DB();
     $timestamp = time();
     if (!$this->validate_update($d)) {
         return false;
     }
     // Get all fields which where shown to the user
     $shippingFields = ps_userfield::getUserFields('shipping', false, '', true);
     $skip_fields = ps_userfield::getSkipFields();
     foreach ($shippingFields as $userField) {
         if (!in_array($userField->name, $skip_fields)) {
             $fields[$userField->name] = ps_userfield::prepareFieldDataSave($userField->type, $userField->name, vmGet($d, $userField->name, strtoupper($userField->name)));
         }
     }
     // These are pre-defined fields.
     $fields['user_id'] = !$perm->check("admin,storeadmin") ? $_SESSION['auth']['user_id'] : (int) $d["user_id"];
     $fields['address_type'] = 'ST';
     $fields['mdate'] = time();
     $db->buildQuery('UPDATE', '#__{vm}_user_info', $fields, "WHERE user_info_id='" . $db->getEscaped($d["user_info_id"]) . "'" . (!$perm->check("admin,storeadmin") ? " AND user_id=" . $_SESSION['auth']['user_id'] : ''));
     if ($db->query() === false) {
         $GLOBALS['vmLogger']->err($VM_LANG->_('VM_USERADDRESS_UPDATED_FAILED'));
         return false;
     }
     $GLOBALS['vmLogger']->info($VM_LANG->_('VM_USERADDRESS_UPDATED'));
     vmRequest::setVar('ship_to_info_id', $d['user_info_id']);
     return true;
 }
Example #5
0
   <input type="hidden" name="Itemid" value="' . $sess->getShopItemid() . '" />
   <input type="hidden" name="description" value="' . stripslashes($cart[$i]["description"]) . '" />
   <input type="image" name="update" title="' . $VM_LANG->_('PHPSHOP_CART_UPDATE') . '" src="' . VM_THEMEURL . 'images/update_quantity_cart.png" alt="' . $VM_LANG->_('PHPSHOP_UPDATE') . '" align="middle" />
 </form>';
       $product_rows[$i]['delete_form'] = '<form action="' . $action_url . '" method="post" name="delete" style="display: inline;">
   <input type="hidden" name="option" value="com_virtuemart" />
   <input type="hidden" name="page" value="' . $page . '" />
   <input type="hidden" name="Itemid" value="' . $sess->getShopItemid() . '" />
   <input type="hidden" name="func" value="cartDelete" />
   <input type="hidden" name="product_id" value="' . $_SESSION['cart'][$i]["product_id"] . '" />
   <input type="hidden" name="description" value="' . $cart[$i]["description"] . '" />
 	<input type="image" name="delete" title="' . $VM_LANG->_('PHPSHOP_CART_DELETE') . '" src="' . VM_THEMEURL . 'images/remove_from_cart.png" alt="' . $VM_LANG->_('PHPSHOP_CART_DELETE') . '" align="middle" />
 </form>';
   }
   // End of for loop through the Cart
   vmRequest::setVar('zone_qty', $vars['zone_qty']);
   $total = $total_undiscounted = round($total, 5);
   $vars["total"] = $total;
   $subtotal_display = $GLOBALS['CURRENCY_DISPLAY']->getFullValue($grandSubtotal);
   if (!empty($_POST["do_coupon"]) || in_array(strtolower($func), array('cartadd', 'cartupdate', 'cartdelete')) && !empty($_SESSION['coupon_redeemed'])) {
       /* process the coupon */
       require_once CLASSPATH . "ps_coupon.php";
       $vars["total"] = $total;
       ps_coupon::process_coupon_code($vars);
   }
   /* HANDLE SHIPPING COSTS */
   if (!empty($shipping_rate_id) && !ps_checkout::noShippingMethodNecessary()) {
       $shipping = true;
       $vars["weight"] = $weight_total;
       $shipping_total = round($ps_checkout->_SHIPPING->get_rate($vars), 5);
       $shipping_taxrate = $ps_checkout->_SHIPPING->get_tax_rate();
Example #6
0
 function set($array, $hash = 'default', $overwrite = true)
 {
     foreach ($array as $key => $value) {
         vmRequest::setVar($key, $value, $hash, $overwrite);
     }
 }
Example #7
0
     $tmp_product_id = $menuparams->get('product_id');
     $tmp_category_id = $menuparams->get('category_id');
     $tmp_flypage = $menuparams->get('flypage');
     $tmp_page = $menuparams->get('page');
     if (!empty($tmp_product_id)) {
         vmRequest::setVar('product_id', $tmp_product_id);
         vmRequest::setVar('page', 'shop.product_details');
     } elseif (!empty($tmp_category_id)) {
         vmRequest::setVar('category_id', $tmp_category_id);
         vmRequest::setVar('page', 'shop.browse');
     }
     if ((!empty($tmp_product_id) || !empty($tmp_category_id)) && !empty($tmp_flypage)) {
         vmRequest::setVar('flypage', $tmp_flypage);
     }
     if (!empty($tmp_page)) {
         vmRequest::setVar('page', $tmp_page);
     }
     // Set the default page
     $defaultpage = HOMEPAGE;
 } else {
     $defaultpage = vmget($_SESSION, 'last_page');
 }
 $page = vmRequest::getVar('page', $defaultpage);
 $func = vmRequest::getVar('func');
 $ajax_request = strtolower(vmGet($_SERVER, 'HTTP_X_REQUESTED_WITH')) == 'xmlhttprequest' || vmGet($_REQUEST, 'ajax_request') == '1';
 $option = vmRequest::getVar('option');
 // This makes it possible to use Shared SSL
 $sess->prepare_SSL_Session();
 if ($option == "com_virtuemart") {
     // Get sure that we have float values with a decimal point!
     @setlocale(LC_NUMERIC, 'en_US', 'en');
Example #8
0
 function render($print = false)
 {
     global $mainframe, $mosConfig_gzip, $mosConfig_live_site;
     foreach ($this->_style as $style) {
         $tag = '<style type="' . key($style) . '">' . current($style) . '</style>';
         if ($print) {
             echo $tag;
         } else {
             $mainframe->addCustomHeadTag($tag);
         }
     }
     if (isset($_REQUEST['usefetchscript'])) {
         $use_fetchscript = vmRequest::getBool('usefetchscript', true);
         vmRequest::setVar('usefetchscript', $use_fetchscript, 'session');
     } else {
         $use_fetchscript = vmRequest::getBool('usefetchscript', true, 'session');
     }
     // Gather all the linked Scripts into ONE link
     $i = 0;
     $appendix = '';
     $loadorder = array();
     foreach ($this->_scripts as $script) {
         $src = $script['url'];
         $type = $script['type'];
         $content = $script['content'];
         $position = $script['position'];
         $urlpos = strpos($src, '?');
         $url_params = '';
         $js_file = false;
         $js_statement = false;
         if ($urlpos && (stristr($src, VM_COMPONENT_NAME) && !stristr($src, '.php') && $use_fetchscript)) {
             $url_params = '&amp;' . substr($src, $urlpos);
             $src = substr($src, 0, $urlpos);
         }
         /* Group the JS files together */
         if (stristr($src, VM_COMPONENT_NAME) && !stristr($src, '.php') && $use_fetchscript) {
             $base_source = str_replace($GLOBALS['real_mosConfig_live_site'], '', $src);
             $base_source = str_replace($GLOBALS['mosConfig_live_site'], '', $base_source);
             $base_source = str_replace('/components/' . VM_COMPONENT_NAME, '', $base_source);
             $base_source = str_replace('components/' . VM_COMPONENT_NAME, '', $base_source);
             $js_file = '&amp;subdir[' . $i . ']=' . dirname($base_source) . '&amp;file[' . $i . ']=' . basename($src);
             $i++;
         } else {
             $js_statement = array('type' => $type, 'src' => $src, 'content' => $content);
         }
         /* Group the statements according to their position */
         /* JS files */
         if ($js_file) {
             if (!isset($loadorder[$position]['js_file']['appendix'])) {
                 $loadorder[$position]['js_file']['appendix'] = '';
             }
             $loadorder[$position]['js_file']['appendix'] .= $js_file;
         }
         $js_file = false;
         /* JS statements */
         if ($js_statement) {
             $loadorder[$position]['js_statement'][] = $js_statement;
         }
         $js_statement = false;
     }
     /* Add the JS to the output */
     $processorder = array('top', 'middle', 'bottom');
     foreach ($processorder as $key => $pos) {
         if (isset($loadorder[$pos])) {
             if (isset($loadorder[$pos]['js_file'])) {
                 /* JS files */
                 $src = $mosConfig_live_site . '/components/' . VM_COMPONENT_NAME . '/fetchscript.php?gzip=' . $mosConfig_gzip;
                 $src .= $loadorder[$pos]['js_file']['appendix'];
                 $tag = '<script src="' . $src . @$url_params . '" type="text/javascript"></script>';
                 if ($print) {
                     echo $tag;
                 } else {
                     $mainframe->addCustomHeadTag($tag);
                 }
             }
             if (isset($loadorder[$pos]['js_statement'])) {
                 /* JS statements */
                 foreach ($loadorder[$pos]['js_statement'] as $statement_key => $otherscript) {
                     if (!empty($otherscript['src'])) {
                         $tag = '<script type="' . $otherscript['type'] . '" src="' . $otherscript['src'] . '"></script>';
                     } else {
                         $tag = '<script type="' . $otherscript['type'] . '">' . $otherscript['content'] . '</script>';
                     }
                     if ($print) {
                         echo $tag;
                     } else {
                         $mainframe->addCustomHeadTag($tag);
                     }
                 }
             }
         }
     }
     // Gather all the linked Stylesheets into ONE link
     $i = 0;
     $appendix = '';
     $url_params = '';
     foreach ($this->_styleSheets as $stylesheet) {
         $urlpos = strpos($stylesheet['url'], '?');
         if ($urlpos) {
             $url_params .= '&amp;' . substr($stylesheet['url'], $urlpos);
             $stylesheet['url'] = substr($stylesheet['url'], 0, $urlpos);
         }
         if (stristr($stylesheet['url'], VM_COMPONENT_NAME) && !stristr($stylesheet['url'], '.php') && $stylesheet['media'] == null && $use_fetchscript) {
             $base_source = str_replace($GLOBALS['real_mosConfig_live_site'], '', $stylesheet['url']);
             $base_source = str_replace($GLOBALS['mosConfig_live_site'], '', $base_source);
             $base_source = str_replace('/components/' . VM_COMPONENT_NAME, '', $base_source);
             $base_source = str_replace('components/' . VM_COMPONENT_NAME, '', $base_source);
             $appendix .= '&amp;subdir[' . $i . ']=' . dirname($base_source) . '&amp;file[' . $i . ']=' . basename($stylesheet['url']);
             $i++;
         } else {
             $tag = '<link type="' . $stylesheet['mime'] . '" href="' . $stylesheet['url'] . '" rel="stylesheet"' . (!empty($stylesheet['media']) ? ' media="' . $stylesheet['media'] . '"' : '') . ' />';
             if ($print) {
                 echo $tag;
             } else {
                 $mainframe->addCustomHeadTag($tag);
             }
         }
     }
     if ($i > 0) {
         $src = $mosConfig_live_site . '/components/com_virtuemart/fetchscript.php?gzip=' . $mosConfig_gzip;
         $src .= $appendix;
         $tag = '<link href="' . $src . @$url_params . '" type="text/css" rel="stylesheet" />';
         if ($print) {
             echo $tag;
         } else {
             $mainframe->addCustomHeadTag($tag);
         }
     }
 }
Example #9
0
 /**
  * adds an item to the shopping cart
  * @author pablo
  * @param array $d
  */
 function add(&$d)
 {
     global $sess, $VM_LANG, $cart, $vmLogger, $func;
     $d = $GLOBALS['vmInputFilter']->process($d);
     include_class("product");
     $db = new ps_DB();
     $ci = 0;
     $request_stock = "";
     $total_quantity = 0;
     $total_updated = 0;
     $total_deleted = 0;
     $_SESSION['last_page'] = "shop.product_details";
     if (!empty($d['product_id']) && !isset($d["prod_id"])) {
         if (empty($d['prod_id'])) {
             $d['prod_id'] = array();
         }
         if (is_array($d['product_id'])) {
             $d['prod_id'] = array_merge($d['prod_id'], $d['product_id']);
         } else {
             $d['prod_id'] = array_merge($d['prod_id'], array($d['product_id']));
         }
     }
     //Check to see if a prod_id has been set
     if (!isset($d["prod_id"])) {
         return true;
     }
     $multiple_products = sizeof($d["prod_id"]);
     //Iterate through the prod_id's and perform an add to cart for each one
     for ($ikey = 0; $ikey < $multiple_products; $ikey++) {
         // Create single array from multi array
         $key_fields = array_keys($d);
         foreach ($key_fields as $key) {
             if (is_array($d[$key])) {
                 $e[$key] = @$d[$key][$ikey];
             } else {
                 $e[$key] = $d[$key];
             }
         }
         if ($multiple_products > 1) {
             $func = "cartUpdate";
         }
         $e['product_id'] = $d['product_id'];
         $e['Itemid'] = $d['Itemid'];
         if (is_array($d["prod_id"])) {
             $product_id = $d["prod_id"][$ikey];
         } else {
             $product_id = $e["prod_id"];
         }
         if (is_array($d["quantity"])) {
             $quantity = @$d['quantity'][$ikey];
         } else {
             $quantity = @$e['quantity'];
         }
         // Check for negative quantity
         if ($quantity < 0) {
             vmRequest::setVar('product_id', $product_id);
             $vmLogger->warning($VM_LANG->_('PHPSHOP_CART_ERROR_NO_NEGATIVE', false));
             return False;
         }
         if (!is_numeric($quantity)) {
             vmRequest::setVar('product_id', $product_id);
             $vmLogger->warning($VM_LANG->_('PHPSHOP_CART_ERROR_NO_VALID_QUANTITY', false));
             return False;
         }
         $quantity = intval($quantity);
         // Check to see if checking stock quantity
         if (CHECK_STOCK) {
             $product_in_stock = ps_product::get_field($product_id, 'product_in_stock');
             if (empty($product_in_stock)) {
                 $product_in_stock = 0;
             }
             if ($quantity > $product_in_stock) {
                 //Create an array for out of stock items and continue to next item
                 $request_stock[$ci]['product_id'] = $product_id;
                 $request_stock[$ci]['quantity'] = $quantity;
                 $ci++;
                 continue;
             }
         }
         // Check if product exists and is published
         if (!ps_product::product_exists($product_id)) {
             $vmLogger->tip($VM_LANG->_('VM_CART_PRODUCT_NOTEXIST', false));
             return false;
         }
         // Quick add of item
         $q = "SELECT product_id FROM #__{vm}_product WHERE ";
         $q .= "product_parent_id = " . (int) $product_id;
         $db->query($q);
         if ($db->num_rows()) {
             vmRequest::setVar('product_id', $e["product_id"]);
             $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_SELECT_ITEM', false));
             $_REQUEST['flypage'] = ps_product::get_flypage($e["product_id"]);
             $GLOBALS['page'] = 'shop.product_details';
             return true;
         }
         // Check to see if we already have it
         $updated = 0;
         $result = ps_product_attribute::cartGetAttributes($e);
         if ($result["attribute_given"] == false && !empty($result["advanced_attribute_list"]) || $multiple_products == 1 && ($result["custom_attribute_given"] == false && !empty($result["custom_attribute_list"]))) {
             $_REQUEST['flypage'] = ps_product::get_flypage($product_id);
             $GLOBALS['page'] = 'shop.product_details';
             $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_SELECT_ITEM', false));
             return true;
         }
         //Check for empty custom field and quantity>0 for multiple addto
         //Normally means no info added to a custom field, but once added to a cart the quantity is automatically placed
         //If another item is added and the custom field is left blank for another product already added this will just ignore that item
         if ($multiple_products != 1 && $quantity != 0 && ($result["custom_attribute_given"] == false && !empty($result["custom_attribute_list"]))) {
             $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_SELECT_ITEM', false));
             continue;
         }
         // Check for duplicate and do not add to current quantity
         for ($i = 0; $i < $_SESSION["cart"]["idx"]; $i++) {
             // modified for advanced attributes
             if ($_SESSION['cart'][$i]["product_id"] == $product_id && $_SESSION['cart'][$i]["description"] == $e["description"]) {
                 $updated = 1;
             }
         }
         list($min, $max) = ps_product::product_order_levels($product_id);
         if ($min != 0 && $quantity != 0 && $quantity < $min) {
             eval("\$msg = \"" . $VM_LANG->_('VM_CART_MIN_ORDER', false) . "\";");
             $vmLogger->warning($msg);
             continue;
         }
         if ($max != 0 && $quantity != 0 && $quantity > $max) {
             eval("\$msg = \"" . $VM_LANG->_('VM_CART_MAX_ORDER', false) . "\";");
             $vmLogger->warning($msg);
             continue;
         }
         // If we did not update then add the item
         if (!$updated && $quantity) {
             $k = $_SESSION['cart']["idx"];
             $_SESSION['cart'][$k]["quantity"] = $quantity;
             $_SESSION['cart'][$k]["product_id"] = $product_id;
             $_SESSION['cart'][$k]["parent_id"] = $e["product_id"];
             $_SESSION['cart'][$k]["category_id"] = vmGet($e, 'category_id', 0);
             // added for the advanced attribute modification
             $_SESSION['cart'][$k]["description"] = $e["description"];
             $_SESSION['cart']["idx"]++;
             $total_quantity += $quantity;
         } else {
             list($updated_prod, $deleted_prod) = $this->update($e);
             $total_updated += $updated_prod;
             $total_deleted += $deleted_prod;
         }
         /* next 3 lines added by Erich for coupon code */
         /* if the cart was updated we gotta update any coupon discounts to avoid ppl getting free stuff */
         if (!empty($_SESSION['coupon_discount'])) {
             // Update the Coupon Discount !!
             require_once CLASSPATH . 'ps_coupon.php';
             ps_coupon::process_coupon_code($d);
         }
     }
     // End Iteration through Prod id's
     $cart = $_SESSION['cart'];
     ps_cart::saveCart();
     // Ouput info message with cart update details /*
     if ($total_quantity != 0 || $total_updated != 0 || $total_deleted != 0) {
         if ($total_quantity > 0 && $total_updated == 0) {
             $msg = $VM_LANG->_('VM_CART_PRODUCT_ADDED', false);
         } else {
             $msg = $VM_LANG->_('VM_CART_PRODUCT_UPDATED', false);
         }
         // Comment out the following line to turn off msg i.e. //$vmLogger->tip( $msg );
         $vmLogger->info($msg);
     } else {
         if (@$request_stock) {
             $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_GOTO_WAITING_LIST', false));
         } elseif ($total_quantity == 0) {
             vmRequest::setVar('product_id', $product_id);
             $GLOBALS['last_page'] = 'shop.product_details';
             $vmLogger->warning($VM_LANG->_('PHPSHOP_CART_ERROR_NO_VALID_QUANTITY', false));
             return false;
         } else {
             $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_QUANTITY_EXCEEDED', false));
         }
     }
     // end cart update message */
     // Perform notification of out of stock items
     if (@$request_stock) {
         global $notify;
         $_SESSION['notify'] = array();
         $_SESSION['notify']['idx'] = 0;
         $k = 0;
         $notify = $_SESSION['notify'];
         foreach ($request_stock as $request) {
             $_SESSION['notify'][$k]["prod_id"] = $request['product_id'];
             $_SESSION['notify'][$k]["quantity"] = $request['quantity'];
             $_SESSION['notify']['idx']++;
             $k++;
         }
         if (vmIsXHR()) {
             $GLOBALS['vm_mainframe']->scriptRedirect($sess->url('index.php?page=shop.waiting_list&product_id=' . $product_id, true, false));
         } else {
             vmRedirect($sess->url('index.php?page=shop.waiting_list&product_id=' . $product_id, true, false));
         }
     }
     return True;
 }