示例#1
0
 function execute()
 {
     global $osC_Session, $osC_ShoppingCart, $osC_Language, $messageStack, $toC_Customization_Fields;
     //get the product id or product id string including the variants
     $id = false;
     //used to fix bug [#209 - Compare / wishlist variant problem]
     if (isset($_GET['pid']) && (preg_match('/^[0-9]+(_?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$/', $_GET['pid']) || preg_match('/^[a-zA-Z0-9 -_]*$/', $_GET['pid']))) {
         $id = $_GET['pid'];
     } else {
         foreach ($_GET as $key => $value) {
             if ((preg_match('/^[0-9]+(_?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$/', $key) || preg_match('/^[a-zA-Z0-9 -_]*$/', $key)) && $key != $osC_Session->getName()) {
                 $id = $key;
             }
             break;
         }
     }
     //processing variants products
     $variants = null;
     if (strpos($id, '_') !== false) {
         $id = str_replace('_', '#', $id);
         $variants = osc_parse_variants_from_id_string($id);
     }
     if ($id !== false && osC_Product::checkEntry($id)) {
         $osC_Product = new osC_Product($id);
     }
     if (isset($osC_Product)) {
         //customization fields check
         if ($osC_Product->hasRequiredCustomizationFields()) {
             if (!$toC_Customization_Fields->exists($osC_Product->getID())) {
                 $osC_Language->load('products');
                 $messageStack->add_session('products', $osC_Language->get('error_customization_fields_missing'), 'error');
                 osc_redirect(osc_href_link(FILENAME_PRODUCTS, $osC_Product->getID()));
             }
         }
         $gift_certificate_data = null;
         if ($osC_Product->isGiftCertificate() && isset($_POST['senders_name']) && isset($_POST['recipients_name']) && isset($_POST['message'])) {
             if ($osC_Product->isEmailGiftCertificate()) {
                 $gift_certificate_data = array('senders_name' => $_POST['senders_name'], 'senders_email' => $_POST['senders_email'], 'recipients_name' => $_POST['recipients_name'], 'recipients_email' => $_POST['recipients_email'], 'message' => $_POST['message']);
             } else {
                 $gift_certificate_data = array('senders_name' => $_POST['senders_name'], 'recipients_name' => $_POST['recipients_name'], 'message' => $_POST['message']);
             }
             if ($osC_Product->isOpenAmountGiftCertificate()) {
                 $gift_certificate_data['price'] = $_POST['gift_certificate_amount'];
             }
             $gift_certificate_data['type'] = $osC_Product->getGiftCertificateType();
         }
         $quantity = null;
         if (isset($_POST['quantity']) && is_numeric($_POST['quantity'])) {
             $quantity = $_POST['quantity'];
         }
         if ($osC_Product->isGiftCertificate() && $gift_certificate_data == null) {
             osc_redirect(osc_href_link(FILENAME_PRODUCTS, $osC_Product->getID()));
             return false;
         } else {
             $osC_ShoppingCart->add($osC_Product->getID(), $variants, $quantity, $gift_certificate_data);
         }
     }
     osc_redirect(osc_href_link(FILENAME_CHECKOUT, 'cart'));
 }
 function getVariantsFormattedPrice()
 {
     global $toC_Json;
     $response = array();
     if (isset($_POST['products_id_string']) && preg_match('/^[0-9]+(#([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)$/', $_POST['products_id_string'])) {
         $response['success'] = true;
         $variants = osc_parse_variants_from_id_string($_POST['products_id_string']);
         $osC_Product = new osC_Product($_POST['products_id_string']);
         $formatted_price = $osC_Product->getPriceFormated(true, $variants);
         $response['formatted_price'] = $formatted_price;
     } else {
         $response['success'] = false;
         $response['feedback'] = 'The products id string is not valid';
     }
     echo $toC_Json->encode($response);
 }
 function execute()
 {
     global $osC_Session, $toC_Wishlist, $osC_Product;
     $id = false;
     foreach ($_GET as $key => $value) {
         if ((ereg('^[0-9]+(_?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$', $key) || ereg('^[a-zA-Z0-9 -_]*$', $key)) && $key != $osC_Session->getName()) {
             $id = $key;
         }
         break;
     }
     //change the variants in the product info page, then attach the wid param to represent the variant product
     if (isset($_GET['wid']) && preg_match('/^[0-9]+(_?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$/', $_GET['wid'])) {
         $id = $_GET['wid'];
     }
     if (strpos($id, '_') !== false) {
         $id = str_replace('_', '#', $id);
     }
     if ($id !== false && osC_Product::checkEntry($id)) {
         $osC_Product = new osC_Product($id);
     }
     if (isset($osC_Product)) {
         $variants = null;
         if (isset($_POST['variants']) && is_array($_POST['variants'])) {
             $variants = $_POST['variants'];
         } else {
             if (isset($_GET['variants']) && !empty($_GET['variants'])) {
                 $variants = osc_parse_variants_string($_GET['variants']);
             } else {
                 if (strpos($id, '#') !== false) {
                     $variants = osc_parse_variants_from_id_string($id);
                 }
             }
         }
         if (!osc_empty($variants)) {
             $toC_Wishlist->add($osC_Product->getID(), $variants);
         } else {
             $toC_Wishlist->add($osC_Product->getID());
         }
     }
     osc_redirect(osc_href_link(FILENAME_ACCOUNT, 'wishlist'));
 }
示例#4
0
 /**
  * Update the product information according to the variants
  * 
  * @access private
  * @param string product id string with variants
  * @param object product
  * @param string original product name
  * @param boolean flag to represent the new variant is adding into the wishlist
  * @return string the new product name
  */
 function _updateProduct($products_id_string, $osC_Product, $product_name, $add = true)
 {
     $variant_product = array();
     if (preg_match('/^[0-9]+(#?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$/', $products_id_string)) {
         $variants = osc_parse_variants_from_id_string($products_id_string);
     }
     $variants_groups = $osC_Product->getData('variants_groups');
     $products_variants = $osC_Product->getVariants();
     if (is_array($variants) && !osc_empty($variants)) {
         $products_variant = $products_variants[$products_id_string];
     } else {
         if ($add) {
             $products_variant = $osC_Product->getDefaultVariant();
             $default_variants_string = $products_variant['product_id_string'];
             $variants = osc_parse_variants_from_id_string($default_variants_string);
         }
     }
     $variants_groups_name = $products_variant['groups_name'];
     //process products name
     if (!osc_empty($variants_groups_name)) {
         $product_name .= '<br />';
         foreach ($variants_groups_name as $group_name => $value_name) {
             $product_name .= '<em class="label label-info">' . $group_name . ': ' . $value_name . '</em>' . '<br />';
         }
     }
     $variant_product['name'] = $product_name;
     // process product price and image according to the variants
     $variant_product['price'] = $osC_Product->getPrice($variants);
     $variant_product['image'] = $osC_Product->getImage($variants);
     return $variant_product;
 }
示例#5
0
 function listChooseProducts()
 {
     global $toC_Json, $osC_Database, $osC_Language, $osC_Currencies, $osC_Tax;
     $start = empty($_REQUEST['start']) ? 0 : $_REQUEST['start'];
     $limit = empty($_REQUEST['limit']) ? MAX_DISPLAY_SEARCH_RESULTS : $_REQUEST['limit'];
     $Qproducts = $osC_Database->query('select SQL_CALC_FOUND_ROWS * from :table_products p left join :table_products_description pd on p.products_id = pd.products_id where p.products_status = 1 and pd.language_id = :language_id and p.products_status = 1');
     if (!empty($_REQUEST['search'])) {
         $Qproducts->appendQuery('and pd.products_name  like :products_name');
         $Qproducts->bindValue(':products_name', '%' . $_REQUEST['search'] . '%');
     }
     $Qproducts->appendQuery('order by p.products_id ');
     $Qproducts->bindTable(':table_products', TABLE_PRODUCTS);
     $Qproducts->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
     $Qproducts->bindInt(':language_id', $osC_Language->getID());
     $Qproducts->setExtBatchLimit($start, $limit);
     $Qproducts->execute();
     $osC_Currencies = new osC_Currencies();
     $osC_Order = new osC_Order($_REQUEST['orders_id']);
     $osC_Tax = new osC_Tax_Admin();
     $_SESSION['currency'] = $osC_Order->getCurrency();
     $records = array();
     while ($Qproducts->next()) {
         $products_id = $Qproducts->valueInt('products_id');
         $osC_Product = new osC_Product($products_id, $osC_Order->getCustomer('customers_id'));
         if (!$osC_Product->hasVariants()) {
             $products_name = $osC_Product->getTitle();
             $products_price = $osC_Product->getPriceFormated();
             if ($osC_Product->isGiftCertificate()) {
                 $products_name .= '<table cellspacing="0" cellpadding="0" border="0">';
                 if ($osC_Product->isOpenAmountGiftCertificate()) {
                     $products_name .= '<tr><td><i>--&nbsp;&nbsp;' . $osC_Language->get('field_amount') . '</i></td><td><input id="' . $products_id . '_price' . '" type="text" class="x-form-text x-form-field x-form-empty-field" style="width: 140px" value="' . round($osC_Product->getOpenAmountMinValue() * $osC_Order->getCurrencyValue(), 2) . '"/></td></tr>';
                 }
                 if ($osC_Product->isEmailGiftCertificate()) {
                     $products_name .= '<tr><td><i>--&nbsp;&nbsp;' . $osC_Language->get('field_recipient_sender_name') . '</i></td><td><input id="' . $products_id . '_sender_name' . '" type="text" class="x-form-text x-form-field x-form-empty-field" style="width: 140px" /></td></tr>' . '<tr><td><i>--&nbsp;&nbsp;' . $osC_Language->get('field_recipient_sender_email') . '</i></td><td><input id="' . $products_id . '_sender_email' . '" type="text" class="x-form-text x-form-field x-form-empty-field" style="width: 140px" /></td></tr>' . '<tr><td><i>--&nbsp;&nbsp;' . $osC_Language->get('field_recipient_name') . '</i></td><td><input id="' . $products_id . '_recipient_name' . '" type="text" class="x-form-text x-form-field x-form-empty-field" style="width: 140px" /></td></tr>' . '<tr><td><i>--&nbsp;&nbsp;' . $osC_Language->get('field_recipient_email') . '</i></td><td><input id="' . $products_id . '_recipient_email' . '" type="text" class="x-form-text x-form-field x-form-empty-field" style="width: 140px" /></td></tr>' . '<tr><td><i>--&nbsp;&nbsp;' . $osC_Language->get('field_message') . '</i></td><td><textarea id="' . $products_id . '_message' . '" class=" x-form-textarea x-form-field" style="width: 140px" /></textarea></td></tr>';
                 } else {
                     if ($osC_Product->isPhysicalGiftCertificate()) {
                         $products_name .= '<tr><td><i>--&nbsp;&nbsp;' . $osC_Language->get('field_recipient_sender_name') . '</i></td><td><input id="' . $products_id . '_sender_name' . '" type="text" class="x-form-text x-form-field x-form-empty-field" style="width: 140px" /></td></tr>' . '<tr><td><i>--&nbsp;&nbsp;' . $osC_Language->get('field_recipient_name') . '</i></td><td><input id="' . $products_id . '_recipient_name' . '" type="text" class="x-form-text x-form-field x-form-empty-field" style="width: 140px" /></td></tr>' . '<tr><td><i>--&nbsp;&nbsp;' . $osC_Language->get('field_message') . '</i></td><td><textarea id="' . $products_id . '_message' . '" class=" x-form-textarea x-form-field" style="width: 140px" /></textarea></td></tr>';
                     }
                 }
                 $products_name .= '</table>';
             }
             $records[] = array('products_id' => $products_id, 'products_name' => $products_name, 'products_type' => $osC_Product->getProductType(), 'products_sku' => $osC_Product->getSKU(), 'products_price' => $products_price, 'products_quantity' => $osC_Product->getQuantity(), 'new_qty' => $Qproducts->valueInt('products_moq'), 'has_variants' => false);
         } else {
             $records[] = array('products_id' => $products_id, 'products_name' => $osC_Product->getTitle(), 'products_type' => $osC_Product->getProductType(), 'products_sku' => $osC_Product->getSKU(), 'products_price' => $osC_Product->getPriceFormated(), 'products_quantity' => $osC_Product->getQuantity(), 'new_qty' => $Qproducts->valueInt('products_moq'), 'has_variants' => true);
             foreach ($osC_Product->getVariants() as $product_id_string => $details) {
                 $variants = '';
                 foreach ($details['groups_name'] as $groups_name => $values_name) {
                     $variants .= '&nbsp;&nbsp;&nbsp;<i>' . $groups_name . ' : ' . $values_name . '</i><br />';
                 }
                 $records[] = array('products_id' => $product_id_string, 'products_name' => $variants, 'products_type' => $osC_Product->getProductType(), 'products_sku' => $osC_Product->getSKU(osc_parse_variants_from_id_string($product_id_string)), 'products_price' => $osC_Currencies->format($osC_Product->getPrice(osc_parse_variants_from_id_string($product_id_string)), $osC_Order->getCurrency()), 'products_quantity' => $details['quantity'], 'new_qty' => $Qproducts->valueInt('products_moq'), 'has_variants' => false);
             }
         }
     }
     unset($_SESSION['currency']);
     $response = array(EXT_JSON_READER_TOTAL => $Qproducts->getBatchSize(), EXT_JSON_READER_ROOT => $records);
     echo $toC_Json->encode($response);
 }
示例#6
0
 function osC_Product($id, $customers_id = null)
 {
     global $osC_Database, $osC_Services, $osC_Language, $osC_Image, $osC_Cache, $osC_Currencies;
     if (!empty($id)) {
         if ($osC_Cache->read('product-' . $id . '-' . $osC_Language->getCode())) {
             $this->_data = $osC_Cache->getCache();
         } else {
             $Qproduct = $osC_Database->query('select p.products_id as id, p.products_type as type, p.products_max_order_quantity as max_order_quantity, p.products_moq as products_moq, p.order_increment as order_increment, p.products_price as price, p.products_tax_class_id as tax_class_id, p.products_date_added as date_added, p.products_date_available as date_available, p.manufacturers_id, p.quantity_discount_groups_id, p.quantity_unit_class, pd.products_name as name, pd.products_short_description as products_short_description, pd.products_description as description, pd.products_page_title as page_title, pd.products_meta_keywords as meta_keywords, pd.products_meta_description as meta_description, p.products_model as model, p.products_sku as sku, pd.products_keyword as keyword, pd.products_tags as tags, pd.products_url as url, p.quantity_discount_groups_id as quantity_discount_groups_id, p.products_weight as products_weight, p.products_weight_class as products_weight_class, quc.quantity_unit_class_title as unit_class, m.manufacturers_name from :table_products p left join :table_manufacturers m on (p.manufacturers_id = m.manufacturers_id), :table_products_description pd, :table_quantity_unit_classes quc where');
             $Qproduct->bindTable(':table_products', TABLE_PRODUCTS);
             $Qproduct->bindTable(':table_manufacturers', TABLE_MANUFACTURERS);
             $Qproduct->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
             $Qproduct->bindTable(':table_quantity_unit_classes', TABLE_QUANTITY_UNIT_CLASSES);
             if (ereg('^[0-9]+(#?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$', $id)) {
                 $this->_current_variants = osc_parse_variants_from_id_string($id);
                 $Qproduct->appendQuery('p.products_id = :products_id');
                 $Qproduct->bindInt(':products_id', osc_get_product_id($id));
             } else {
                 $Qproduct->appendQuery('pd.products_keyword = :products_keyword');
                 $Qproduct->bindValue(':products_keyword', $id);
             }
             $Qproduct->appendQuery('and p.products_status = 1 and p.products_id = pd.products_id and pd.language_id = :language_id and p.quantity_unit_class = quc.quantity_unit_class_id and quc.language_id = pd.language_id ');
             $Qproduct->bindInt(':language_id', $osC_Language->getID());
             $Qproduct->execute();
             if ($Qproduct->numberOfRows() === 1) {
                 $this->_data = $Qproduct->toArray();
                 //images
                 $this->_data['images'] = array();
                 $Qimages = $osC_Database->query('select id, image, default_flag from :table_products_images where products_id = :products_id order by sort_order');
                 $Qimages->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
                 $Qimages->bindInt(':products_id', $this->_data['id']);
                 $Qimages->execute();
                 while ($Qimages->next()) {
                     $this->_data['images'][] = $Qimages->toArray();
                 }
                 //categories
                 $Qcategory = $osC_Database->query('select categories_id from :table_products_to_categories where products_id = :products_id limit 1');
                 $Qcategory->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
                 $Qcategory->bindInt(':products_id', $this->_data['id']);
                 $Qcategory->execute();
                 $this->_data['category_id'] = $Qcategory->valueInt('categories_id');
                 //attachments
                 $Qattachments = $osC_Database->query('select attachments_name, pa.attachments_id, filename, cache_filename, attachments_description from :table_products_attachments pa, :table_products_attachments_description pad, :table_products_attachments_to_products pa2p where pa.attachments_id = pad.attachments_id and pa2p.attachments_id = pa.attachments_id and pa2p.products_id = :products_id and pad.languages_id = :language_id');
                 $Qattachments->bindTable(':table_products_attachments', TABLE_PRODUCTS_ATTACHMENTS);
                 $Qattachments->bindTable(':table_products_attachments_description', TABLE_PRODUCTS_ATTACHMENTS_DESCRIPTION);
                 $Qattachments->bindTable(':table_products_attachments_to_products', TABLE_PRODUCTS_ATTACHMENTS_TO_PRODUCTS);
                 $Qattachments->bindInt(":products_id", $this->_data['id']);
                 $Qattachments->bindInt(":language_id", $osC_Language->getID());
                 $Qattachments->execute();
                 while ($Qattachments->next()) {
                     $this->_data['attachments'][] = array('attachment_name' => $Qattachments->value('attachments_name'), 'filename' => $Qattachments->value('filename'), 'attachments_id' => $Qattachments->valueInt('attachments_id'), 'attachment_file_name' => $Qattachments->value('cache_filename'), 'description' => $Qattachments->value('attachments_description'));
                 }
                 //accessories
                 $Qaccessories = $osC_Database->query('select accessories_id from :table_products_accessories pa where pa.products_id =  :products_id');
                 $Qaccessories->bindTable(':table_products_accessories', TABLE_PRODUCTS_ACCESSORIES);
                 $Qaccessories->bindInt(":products_id", $this->_data['id']);
                 $Qaccessories->execute();
                 while ($Qaccessories->next()) {
                     $this->_data['accessories'][] = $Qaccessories->value('accessories_id');
                 }
                 //variants
                 $this->iniProductVariants();
                 //attributes
                 $Qattributes = $osC_Database->query('select pav.name, pav.module, pav.value as selections, pa.value from :table_products_attributes pa, :table_products_attributes_values pav where pa.products_attributes_values_id = pav.products_attributes_values_id and pa.language_id = pav.language_id and pa.products_id = :products_id and pa.language_id = :language_id');
                 $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
                 $Qattributes->bindTable(':table_products_attributes_values', TABLE_PRODUCTS_ATTRIBUTES_VALUES);
                 $Qattributes->bindInt(':products_id', $this->_data['id']);
                 $Qattributes->bindInt(':language_id', $osC_Language->getID());
                 $Qattributes->execute();
                 $attributes = array();
                 while ($Qattributes->next()) {
                     $name = $Qattributes->value('name');
                     $value = $Qattributes->value('value');
                     if ($Qattributes->value('module') == 'pull_down_menu') {
                         $selections = $Qattributes->value('selections');
                         $selections = explode(',', $selections);
                         if (isset($selections[$value - 1])) {
                             $value = $selections[$value - 1];
                         }
                     }
                     $attributes[] = array('name' => $name, 'value' => $value);
                 }
                 $this->_data['attributes'] = $attributes;
                 //customizations
                 $Qcustomizations = $osC_Database->query('select cf.customization_fields_id, products_id, type, is_required, name from :table_customization_fields cf inner join :table_customization_fields_description cfd on cf.customization_fields_id = cfd.customization_fields_id where cf.products_id = :products_id and cfd.languages_id = :languages_id');
                 $Qcustomizations->bindTable(':table_customization_fields', TABLE_CUSTOMIZATION_FIELDS);
                 $Qcustomizations->bindTable(':table_customization_fields_description', TABLE_CUSTOMIZATION_FIELDS_DESCRIPTION);
                 $Qcustomizations->bindInt(':products_id', $this->_data['id']);
                 $Qcustomizations->bindInt(':languages_id', $osC_Language->getID());
                 $Qcustomizations->execute();
                 $customizations = array();
                 while ($Qcustomizations->next()) {
                     $customizations[] = array('customization_fields_id' => $Qcustomizations->valueInt('customization_fields_id'), 'products_id' => $Qcustomizations->valueInt('products_id'), 'type' => $Qcustomizations->valueInt('type'), 'is_required' => $Qcustomizations->valueInt('is_required'), 'name' => $Qcustomizations->value('name'));
                 }
                 $this->_data['customizations'] = $customizations;
                 if ($this->_data['type'] == PRODUCT_TYPE_DOWNLOADABLE) {
                     $Qdownloadables = $osC_Database->query('select * from :table_products_downloadables where products_id = :products_id');
                     $Qdownloadables->bindTable(':table_products_downloadables', TABLE_PRODUCTS_DOWNLOADABLES);
                     $Qdownloadables->bindInt(':products_id', $id);
                     $Qdownloadables->execute();
                     $downloadable = $Qdownloadables->toArray();
                     $this->_data = array_merge($this->_data, $downloadable);
                 } else {
                     if ($this->_data['type'] == PRODUCT_TYPE_GIFT_CERTIFICATE) {
                         $Qcertificates = $osC_Database->query('select * from :table_products_gift_certificates where products_id = :products_id');
                         $Qcertificates->bindTable(':table_products_gift_certificates', TABLE_PRODUCTS_GIFT_CERTIFICATES);
                         $Qcertificates->bindInt(':products_id', $id);
                         $Qcertificates->execute();
                         $certificate = $Qcertificates->toArray();
                         $this->_data = array_merge($this->_data, $certificate);
                     }
                 }
             }
             $osC_Cache->write('product-' . $id . '-' . $osC_Language->getCode(), $this->_data);
         }
         //format the variants display price
         if (isset($this->_data['variants']) && is_array($this->_data['variants'])) {
             $products_variants = $this->_data['variants'];
             foreach ($products_variants as $products_id_string => $data) {
                 $this->_data['variants'][$products_id_string]['display_price'] = $osC_Currencies->displayPrice($data['price'], $this->_data['tax_class_id']);
             }
         }
         //the customer group and discount group is not cached
         if ($customers_id == null) {
             global $osC_Customer;
             if (is_object($osC_Customer) && $osC_Customer->getID() !== false) {
                 $this->_customers_id = $osC_Customer->getID();
                 $this->_customers_groups_id = $osC_Customer->getCustomerGroupID();
                 $this->_customer_group_discount = $osC_Customer->getCustomerGroupDiscount();
             }
         } else {
             global $osC_Database;
             $QcustomerGroup = $osC_Database->query('select c.customers_groups_id, cg.customers_groups_discount from :table_customers c, :table_customers_groups cg where c.customers_groups_id = cg.customers_groups_id and c.customers_id = :customers_id ');
             $QcustomerGroup->bindTable(':table_customers', TABLE_CUSTOMERS);
             $QcustomerGroup->bindTable(':table_customers_groups', TABLE_CUSTOMERS_GROUPS);
             $QcustomerGroup->bindInt(':customers_id', $customers_id);
             $QcustomerGroup->execute();
             if ($QcustomerGroup->numberOfRows() == 1) {
                 $this->_customers_id = $customers_id;
                 $this->_customers_groups_id = $QcustomerGroup->valueInt('customers_groups_id');
                 $this->_customer_group_discount = $QcustomerGroup->value('customers_groups_discount');
             }
         }
         if ($this->_data['quantity_discount_groups_id'] > 0) {
             $this->_data['quantity_discount'] = $this->getDiscountGroup($this->_customers_groups_id);
         }
     }
 }
 function outputCompareProductsTable()
 {
     global $osC_Language, $osC_Image, $osC_Weight, $osC_Currencies;
     $content = '';
     $products_images = array();
     $products_titles = array();
     $products_price = array();
     $products_weight = array();
     $products_sku = array();
     $products_manufacturers = array();
     $products_desciptions = array();
     $products_attributes = array();
     $products_variants = array();
     $cols = array('<col width="20%">');
     $col_width = round(80 / count($this->getProducts()));
     if ($this->hasContents()) {
         foreach ($this->getProducts() as $products_id) {
             $cols[] = '<col width="' . $col_width . '%">';
             $osC_Product = new osC_Product($products_id);
             $image = $osC_Product->getImages();
             $product_title = $osC_Product->getTitle();
             $product_price = $osC_Product->getPriceFormated(true);
             $product_weight = $osC_Product->getWeight();
             $product_sku = $osC_Product->getSKU();
             //if the product have any variants, it means that the $products_id should be a product string such as 1#1:1;2:2
             $variants = array();
             if ($osC_Product->hasVariants()) {
                 $product_variants = $osC_Product->getVariants();
                 if (preg_match('/^[0-9]+(#?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)+$/', $products_id)) {
                     $products_variant = $product_variants[$products_id];
                     $variants = osc_parse_variants_from_id_string($products_id);
                 } else {
                     $products_variant = $osC_Product->getDefaultVariant();
                     $variants = $products_variant['groups_id'];
                 }
                 //if the product have any variants, get the group_name:value_name string
                 if (isset($products_variant) && isset($products_variant['groups_name']) && is_array($products_variant['groups_name']) && !empty($products_variant['groups_name'])) {
                     $products_variants[$products_id]['variants'] = array();
                     foreach ($products_variant['groups_name'] as $groups_name => $value_name) {
                         $products_variants[$products_id]['variants'][] = array('name' => $groups_name, 'value' => $value_name);
                     }
                 }
                 $product_price = $osC_Currencies->displayPrice($osC_Product->getPrice($variants), $osC_Product->getTaxClassID());
                 $product_weight = $products_variant['weight'];
                 $product_sku = $products_variant['sku'];
                 $image = $products_variant['image'];
             }
             $image = is_array($image) ? $image[0]['image'] : $image;
             $products_titles[] = $product_title;
             if (!osc_empty($product_price)) {
                 $products_price[] = $product_price;
             }
             if (!osc_empty($product_weight)) {
                 $products_weight[] = $osC_Weight->display($product_weight, $osC_Product->getWeightClass());
             }
             if (!osc_empty($product_sku)) {
                 $products_sku[] = $product_sku;
             }
             if (!osc_empty($osC_Product->getManufacturer())) {
                 $products_manufacturers[] = $osC_Product->getManufacturer();
             }
             if (!osc_empty($osC_Product->getDescription())) {
                 $products_desciptions[] = $osC_Product->getDescription();
             }
             if ($osC_Product->hasAttributes()) {
                 foreach ($osC_Product->getAttributes() as $attribute) {
                     $products_attributes[$products_id]['attributes'][] = array('name' => $attribute['name'], 'value' => $attribute['value']);
                 }
             }
             $products_id = str_replace('#', '_', $products_id);
             $products_images[] = '<div class="image">' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $products_id), $osC_Image->show($image, $osC_Product->getTitle())) . '</div>' . '<div class="button">' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $products_id . '&action=cart_add' . (osc_empty(osc_parse_variants_array($variants)) ? '' : '&variants=' . osc_parse_variants_array($variants))), osc_draw_image_button('button_in_cart.gif', $osC_Language->get('button_add_to_cart'))) . '</div>';
         }
         $content .= '<table id="compareProducts" cellspacing="0" cellpadding="2" border="0">';
         //add col groups
         $content .= '<colgroup>';
         foreach ($cols as $col) {
             $content .= $col;
         }
         $content .= '</colgroup>';
         //add product header
         $content .= '<tbody>';
         $content .= '<tr class="first">';
         $content .= '<th>&nbsp;</th>';
         if (!osc_empty($products_images)) {
             foreach ($products_images as $k => $product_image) {
                 $content .= '<td' . ($k == count($products_images) - 1 ? ' class="last"' : '') . '>' . $product_image . '</td>';
             }
         }
         $content .= '</tr>';
         $content .= '</tbody>';
         //add compare details
         $content .= '<tbody>';
         $row_class = 'even';
         //add product name
         if (!osc_empty($products_titles)) {
             $content .= '<tr class="' . $row_class . '">' . '<th>' . $osC_Language->get('field_products_name') . '</th>';
             foreach ($products_titles as $k => $product_title) {
                 $content .= '<td' . ($k == count($products_titles) - 1 ? ' class="last"' : '') . '>' . $product_title . '</td>';
             }
             $content .= '</tr>';
             $row_class = $row_class == 'even' ? 'odd' : 'even';
         }
         //add product price
         if (!osc_empty($products_price)) {
             $content .= '<tr class="' . $row_class . '">' . '<th>' . $osC_Language->get('field_products_price') . '</th>';
             foreach ($products_price as $k => $product_price) {
                 $content .= '<td' . ($k == count($products_price) - 1 ? ' class="last"' : '') . '>' . $product_price . '</td>';
             }
             $content .= '</tr>';
             $row_class = $row_class == 'even' ? 'odd' : 'even';
         }
         //add product weight
         if (!osc_empty($products_weight)) {
             $content .= '<tr class="' . $row_class . '">' . '<th>' . $osC_Language->get('field_products_weight') . '</th>';
             foreach ($products_weight as $k => $product_weight) {
                 $content .= '<td' . ($k == count($products_weight) - 1 ? ' class="last"' : '') . '>' . $product_weight . '</td>';
             }
             $content .= '</tr>';
             $row_class = $row_class == 'even' ? 'odd' : 'even';
         }
         //add product sku
         if (!osc_empty($products_sku)) {
             $content .= '<tr class="' . $row_class . '">' . '<th>' . $osC_Language->get('field_products_sku') . '</th>';
             foreach ($products_sku as $k => $product_sku) {
                 $content .= '<td' . ($k == count($products_sku) - 1 ? ' class="last"' : '') . '>' . $product_sku . '</td>';
             }
             $content .= '</tr>';
             $row_class = $row_class == 'even' ? 'odd' : 'even';
         }
         //add product manufacturers
         if (!osc_empty($products_manufacturers)) {
             $content .= '<tr class="' . $row_class . '">' . '<th>' . $osC_Language->get('field_products_manufacturer') . '</th>';
             foreach ($products_manufacturers as $k => $product_manufacturer) {
                 $content .= '<td' . ($k == count($products_manufacturers) - 1 ? ' class="last"' : '') . '>' . $product_manufacturer . '</td>';
             }
             $content .= '</tr>';
             $row_class = $row_class == 'even' ? 'odd' : 'even';
         }
         //add product variants
         if (!osc_empty($products_variants)) {
             $content .= '<tr class="' . $row_class . '">' . '<th>' . $osC_Language->get('field_products_variants') . '</th>';
             foreach ($this->getProducts() as $k => $products_id) {
                 if (isset($products_variants[$products_id]['variants']) && !osc_empty($products_variants[$products_id]['variants'])) {
                     $content .= '<td' . ($k == count($this->getProducts()) - 1 ? ' class="last"' : '') . '>';
                     foreach ($products_variants[$products_id]['variants'] as $variant) {
                         $content .= '<span class="variant">' . $variant['name'] . ': ' . $variant['value'] . '</span>';
                     }
                     $content .= '</td>';
                 }
             }
             $content .= '</tr>';
             $row_class = $row_class == 'even' ? 'odd' : 'even';
         }
         //add product attributes
         if (!osc_empty($products_attributes)) {
             $content .= '<tr class="' . $row_class . '">' . '<th>' . $osC_Language->get('field_products_attributes') . '</th>';
             foreach ($this->getProducts() as $k => $products_id) {
                 if (isset($products_attributes[$products_id]['attributes']) && !osc_empty($products_attributes[$products_id]['attributes'])) {
                     $content .= '<td' . ($k == count($this->getProducts()) - 1 ? ' class="last"' : '') . '>';
                     foreach ($products_attributes[$products_id]['attributes'] as $attribute) {
                         $content .= '<span class="attribute">' . $attribute['name'] . ': ' . $attribute['value'] . '</span>';
                     }
                     $content .= '</td>';
                 }
             }
             $content .= '</tr>';
             $row_class = $row_class == 'even' ? 'odd' : 'even';
         }
         //add product description
         if (!osc_empty($products_desciptions)) {
             $content .= '<tr class="' . $row_class . ' last">' . '<th>' . $osC_Language->get('field_products_description') . '</th>';
             foreach ($products_desciptions as $k => $product_description) {
                 $content .= '<td' . ($k == count($products_desciptions) - 1 ? ' class="last"' : '') . '>' . $product_description . '</td>';
             }
             $content .= '</tr>';
             $row_class = $row_class == 'even' ? 'odd' : 'even';
         }
         $content .= '</tbody>';
         $content .= '</table>';
     }
     return $content;
 }
 /**
  * Add the products to this order.
  */
 function addProduct($products_id_string, $quantity, $gift_certificate_data = null)
 {
     global $osC_Database, $osC_Language, $osC_Tax;
     $error = false;
     $osC_Database->startTransaction();
     $products_id = osc_get_product_id($products_id_string);
     $variants = osc_parse_variants_from_id_string($products_id_string);
     $osC_Product = new osC_Product($products_id, $this->getCustomer('customers_id'));
     //If the products with the variants exists in the order, then increase the order quantity
     //Each gift certificate added to order will be considered as a new product
     //
     if (isset($this->_contents[$products_id_string])) {
         $orders_products_id = $this->_contents[$products_id_string]['orders_products_id'];
         $new_quantity = $this->_contents[$products_id_string]['quantity'] + $quantity;
         $Qupdate = $osC_Database->query('update :table_orders_products set products_quantity = :products_quantity, products_price = :products_price, final_price = :final_price, products_type = :products_type where orders_products_id = :orders_products_id ');
         $Qupdate->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
         $Qupdate->bindInt(':products_quantity', $new_quantity);
         $Qupdate->bindValue(':products_price', $osC_Product->getPrice($variants, $new_quantity));
         $Qupdate->bindValue(':final_price', $osC_Product->getPrice($variants, $new_quantity));
         $Qupdate->bindInt(':orders_products_id', $orders_products_id);
         $Qupdate->bindInt(':products_type', $osC_Product->getProductType());
         $Qupdate->setLogging($_SESSION['module'], $this->_order_id);
         $Qupdate->execute();
         if ($osC_Database->isError()) {
             $error = true;
         } else {
             $this->_contents[$products_id_string]['quantity'] = $new_quantity;
             $this->_contents[$products_id_string]['price'] = $osC_Product->getPrice($variants, $new_quantity);
             $this->_contents[$products_id_string]['final_price'] = $osC_Product->getPrice($variants, $new_quantity);
         }
     } else {
         $products_price = $osC_Product->getPrice($variants, $quantity);
         if ($osC_Product->isEmailGiftCertificate() && $osC_Product->isOpenAmountGiftCertificate()) {
             $products_price = $gift_certificate_data['price'];
         }
         $Qinsert = $osC_Database->query('insert into :table_orders_products (orders_id, products_id, products_sku, products_name, products_price, final_price, products_tax, products_quantity, products_type) values (:orders_id, :products_id, :products_sku, :products_name, :products_price, :final_price, :products_tax, :products_quantity, :products_type) ');
         $Qinsert->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
         $Qinsert->bindInt(':orders_id', $this->_order_id);
         $Qinsert->bindInt(':products_id', $osC_Product->getID());
         $Qinsert->bindValue(':products_sku', $osC_Product->getSKU());
         $Qinsert->bindValue(':products_name', $osC_Product->getTitle());
         $Qinsert->bindValue(':products_price', $products_price);
         $Qinsert->bindValue(':final_price', $products_price);
         $Qinsert->bindValue(':products_tax', $osC_Tax->getTaxRate($osC_Product->getTaxClassID(), $this->_shipping_address['country_id'], $this->_shipping_address['zone_id']));
         $Qinsert->bindInt(':products_quantity', $quantity);
         $Qinsert->bindInt(':products_type', $osC_Product->getProductType());
         $Qinsert->execute();
         if ($osC_Database->isError()) {
             $error = true;
         } else {
             $orders_products_id = $osC_Database->nextID();
             if (is_array($variants) && !empty($variants)) {
                 foreach ($variants as $groups_id => $values_id) {
                     $Qvariants = $osC_Database->query('select pvg.products_variants_groups_name, pvv.products_variants_values_name from :table_products_variants pv, :table_products_variants_entries pve, :table_products_variants_groups pvg, :table_products_variants_values pvv where pv.products_id = :products_id and pv.products_variants_id = pve.products_variants_id and pve.products_variants_groups_id = :groups_id and pve.products_variants_values_id = :variants_values_id and pve.products_variants_groups_id = pvg.products_variants_groups_id and pve.products_variants_values_id = pvv.products_variants_values_id and pvg.language_id = :language_id and pvv.language_id = :language_id');
                     $Qvariants->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                     $Qvariants->bindTable(':table_products_variants_entries', TABLE_PRODUCTS_VARIANTS_ENTRIES);
                     $Qvariants->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
                     $Qvariants->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
                     $Qvariants->bindInt(':products_id', $osC_Product->getID());
                     $Qvariants->bindInt(':groups_id', $groups_id);
                     $Qvariants->bindInt(':variants_values_id', $values_id);
                     $Qvariants->bindInt(':language_id', $osC_Language->getID());
                     $Qvariants->bindInt(':language_id', $osC_Language->getID());
                     $Qvariants->execute();
                     $Qinsert = $osC_Database->query('insert into :table_orders_products_variants (orders_id, orders_products_id, products_variants_groups_id, products_variants_groups, products_variants_values_id, products_variants_values) values (:orders_id, :orders_products_id, :products_variants_groups_id, :products_variants_groups, :products_variants_values_id, :products_variants_values) ');
                     $Qinsert->bindTable(':table_orders_products_variants', TABLE_ORDERS_PRODUCTS_VARIANTS);
                     $Qinsert->bindInt(':orders_id', $this->_order_id);
                     $Qinsert->bindInt(':orders_products_id', $orders_products_id);
                     $Qinsert->bindInt(':products_variants_groups_id', $groups_id);
                     $Qinsert->bindValue(':products_variants_groups', $Qvariants->value('products_variants_groups_name'));
                     $Qinsert->bindInt(':products_variants_values_id', $values_id);
                     $Qinsert->bindValue(':products_variants_values', $Qvariants->value('products_variants_values_name'));
                     $Qinsert->setLogging($_SESSION['module'], $this->_order_id);
                     $Qinsert->execute();
                     if ($osC_Database->isError()) {
                         $error = true;
                         break;
                     }
                 }
             }
             if ($error === false) {
                 if ($osC_Product->getProductType() == PRODUCT_TYPE_DOWNLOADABLE) {
                     $Qdownloadable = $osC_Database->query('select * from :table_products_downloadables where products_id = :products_id');
                     $Qdownloadable->bindTable(':table_products_downloadables', TABLE_PRODUCTS_DOWNLOADABLES);
                     $Qdownloadable->bindInt(':products_id', $products_id);
                     $Qdownloadable->execute();
                     $Qopd = $osC_Database->query('insert into :table_orders_products_download (orders_id, orders_products_id, orders_products_filename, orders_products_cache_filename, download_maxdays, download_count) values (:orders_id, :orders_products_id, :orders_products_filename, :orders_products_cache_filename, :download_maxdays, :download_count)');
                     $Qopd->bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD);
                     $Qopd->bindInt(':orders_id', $_REQUEST['orders_id']);
                     $Qopd->bindInt(':orders_products_id', $orders_products_id);
                     $Qopd->bindValue(':orders_products_filename', $Qdownloadable->value('filename'));
                     $Qopd->bindValue(':orders_products_cache_filename', $Qdownloadable->value('cache_filename'));
                     $Qopd->bindValue(':download_maxdays', $Qdownloadable->valueInt('number_of_accessible_days'));
                     $Qopd->bindValue(':download_count', $Qdownloadable->valueInt('number_of_downloads'));
                     $Qopd->setLogging($_SESSION['module'], $this->_order_id);
                     $Qopd->execute();
                     if ($osC_Database->isError()) {
                         $error = true;
                     }
                 }
             }
             if ($error === false) {
                 if ($osC_Product->getProductType() == PRODUCT_TYPE_GIFT_CERTIFICATE) {
                     require_once '../includes/classes/gift_certificates.php';
                     $Qgc = $osC_Database->query('insert into :table_gift_certificates (orders_id, orders_products_id, gift_certificates_type, amount, gift_certificates_code, recipients_name, recipients_email, senders_name, senders_email, messages) values (:orders_id, :orders_products_id, :gift_certificates_type, :amount, :gift_certificates_code, :recipients_name, :recipients_email, :senders_name, :senders_email, :messages)');
                     $Qgc->bindTable(':table_gift_certificates', TABLE_GIFT_CERTIFICATES);
                     $Qgc->bindInt(':orders_id', $_REQUEST['orders_id']);
                     $Qgc->bindInt(':gift_certificates_type', $gift_certificate_data['type']);
                     $Qgc->bindInt(':orders_products_id', $orders_products_id);
                     $Qgc->bindValue(':amount', $gift_certificate_data['price']);
                     $Qgc->bindValue(':gift_certificates_code', toC_Gift_Certificates::createGiftCertificateCode());
                     $Qgc->bindValue(':recipients_name', $gift_certificate_data['recipients_name']);
                     $Qgc->bindValue(':recipients_email', $gift_certificate_data['recipients_email']);
                     $Qgc->bindValue(':senders_name', $gift_certificate_data['senders_name']);
                     $Qgc->bindValue(':senders_email', $gift_certificate_data['senders_email']);
                     $Qgc->bindValue(':messages', $gift_certificate_data['message']);
                     $Qgc->setLogging($_SESSION['module'], $this->_order_id);
                     $Qgc->execute();
                     if ($osC_Database->isError()) {
                         $error = true;
                     }
                 }
             }
         }
         if ($error === false) {
             $this->_contents[$products_id_string] = array('id' => $products_id, 'orders_products_id' => $orders_products_id, 'quantity' => $quantity, 'name' => $osC_Product->getTitle(), 'sku' => $osC_Product->getSKU($variants_array), 'tax' => $osC_Tax->getTaxRate($osC_Product->getTaxClassID(), $this->_shipping_address['country_id'], $this->_shipping_address['zone_id']), 'price' => $product_price, 'final_price' => $products_price, 'weight' => $osC_Product->getWeight($variants), 'tax_class_id' => $osC_Product->getTaxClassID(), 'weight_class_id' => $osC_Product->getWeightClass());
         }
     }
     osC_Product::updateStock($this->_order_id, $orders_products_id, $products_id, $quantity);
     if ($error === false) {
         $osC_Database->commitTransaction();
         $this->_calculate();
         $this->updateOrderTotal();
         return true;
     }
     $osC_Database->rollbackTransaction();
     return false;
 }
示例#9
0
 function listWishlists()
 {
     global $toC_Json, $osC_Language, $osC_Database;
     $customers_id = isset($_REQUEST['customers_id']) ? $_REQUEST['customers_id'] : null;
     if (is_numeric($customers_id)) {
         $Qwishlists = $osC_Database->query('select wp.wishlists_products_id, wp.products_id, wp.date_added, wp.comments from :table_wishlists w, :table_wishlists_products wp where w.wishlists_id = wp.wishlists_id and w.customers_id = :customers_id');
         $Qwishlists->bindTable(':table_wishlists', TABLE_WISHLISTS);
         $Qwishlists->bindTable(':table_wishlists_products', TABLE_WISHLISTS_PRODUCTS);
         $Qwishlists->bindInt(':customers_id', $customers_id);
         $Qwishlists->execute();
         $records = array();
         while ($Qwishlists->next()) {
             $products_id = osc_get_product_id($Qwishlists->value('products_id'));
             $variants = osc_parse_variants_from_id_string($Qwishlists->value('products_id'));
             $Qname = $osC_Database->query('select products_name from :table_products_description where products_id = :products_id and language_id = :language_id');
             $Qname->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
             $Qname->bindInt(':products_id', $products_id);
             $Qname->bindInt(':language_id', $osC_Language->getID());
             $Qname->execute();
             $products_name = $Qname->value('products_name');
             if (!empty($variants)) {
                 $variants_name = array();
                 foreach ($variants as $groups_id => $values_id) {
                     $Qvariants = $osC_Database->query('select pvg.products_variants_groups_name, pvv.products_variants_values_name from :table_products_variants pv, :table_products_variants_entries pve, :table_products_variants_groups pvg, :table_products_variants_values pvv where pv.products_id = :products_id and pv.products_variants_id = pve.products_variants_id and pve.products_variants_groups_id = :groups_id and pve.products_variants_values_id = :variants_values_id and pve.products_variants_groups_id = pvg.products_variants_groups_id and pve.products_variants_values_id = pvv.products_variants_values_id and pvg.language_id = :pvg_language_id and pvv.language_id = :pvv_language_id');
                     $Qvariants->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                     $Qvariants->bindTable(':table_products_variants_entries', TABLE_PRODUCTS_VARIANTS_ENTRIES);
                     $Qvariants->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
                     $Qvariants->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
                     $Qvariants->bindInt(':products_id', $products_id);
                     $Qvariants->bindInt(':groups_id', $groups_id);
                     $Qvariants->bindInt(':variants_values_id', $values_id);
                     $Qvariants->bindInt(':pvg_language_id', $osC_Language->getID());
                     $Qvariants->bindInt(':pvv_language_id', $osC_Language->getID());
                     $Qvariants->execute();
                     $variants_name[] = $Qvariants->value('products_variants_groups_name') . ' : ' . $Qvariants->value('products_variants_values_name');
                 }
                 $products_name .= '<br />' . implode('<br />', $variants_name);
             }
             $records[] = array('wishlists_products_id' => $Qwishlists->value('wishlists_products_id'), 'products_name' => $products_name, 'date_added' => osC_DateTime::getShort($Qwishlists->value('date_added')), 'comments' => $Qwishlists->value('comments'));
         }
         $Qwishlists->freeResult();
         $response = array(EXT_JSON_READER_ROOT => $records);
         echo $toC_Json->encode($response);
     }
 }
示例#10
0
 function add($products_id_string, $variants = null, $quantity = null, $gift_certificates_data = null, $customization_qty = null, $action = 'add')
 {
     global $osC_Database, $osC_Services, $osC_Language, $osC_Customer, $osC_Image, $toC_Wishlist, $toC_Customization_Fields;
     $products_id = osc_get_product_id($products_id_string);
     $osC_Product = new osC_Product($products_id);
     if ($osC_Product->isGiftCertificate()) {
         if ($variants == null || empty($variants)) {
             $products_id_string = $products_id . '#' . time();
         } else {
             $products_id_string = $products_id . '#' . $variants;
             //set variants to null
             $variants = null;
         }
     } else {
         $products_id_string = osc_get_product_id_string($products_id_string, $variants);
     }
     if ($osC_Product->getID() > 0) {
         if ($toC_Wishlist->hasProduct($products_id)) {
             $toC_Wishlist->deleteProduct($products_id);
         }
         if ($this->exists($products_id_string)) {
             $old_quantity = $this->getQuantity($products_id_string);
             if (!is_numeric($quantity)) {
                 $quantity = $this->getQuantity($products_id_string) + 1;
             } else {
                 if (is_numeric($quantity) && $quantity == 0) {
                     $this->remove($products_id_string);
                     return;
                 } else {
                     if ($action == 'add') {
                         $quantity = $this->getQuantity($products_id_string) + $quantity;
                     } else {
                         if ($action == 'update') {
                             $quantity = $quantity;
                             if (isset($customization_qty) && !empty($customization_qty)) {
                                 foreach ($customization_qty as $key => $value) {
                                     $this->_contents[$products_id_string]['customizations'][$key]['qty'] = $value;
                                 }
                             }
                         }
                     }
                 }
             }
             if ($osC_Product->isGiftCertificate()) {
                 if ($quantity > 1) {
                     $quantity = 1;
                     $error = $osC_Language->get('error_gift_certificate_quantity_must_be_one');
                 }
             }
             //check minimum order quantity
             $products_moq = $osC_Product->getMOQ();
             if ($quantity < $products_moq) {
                 $quantity = $products_moq;
                 $error = sprintf($osC_Language->get('error_minimum_order_quantity'), $osC_Product->getTitle(), $products_moq);
             }
             //check maximum order quantity
             $products_max_order_quantity = $osC_Product->getMaxOrderQuantity();
             if ($products_max_order_quantity > 0) {
                 if ($quantity > $products_max_order_quantity) {
                     $quantity = $products_max_order_quantity;
                     $error = sprintf($osC_Language->get('error_maximum_order_quantity'), $osC_Product->getTitle(), $products_max_order_quantity);
                 }
             }
             //check order increment
             $increment = $osC_Product->getOrderIncrement();
             if (($quantity - $products_moq) % $increment != 0) {
                 $quantity = $products_moq + (floor(($quantity - $products_moq) / $increment) + 1) * $increment;
                 $error = sprintf($osC_Language->get('error_order_increment'), $osC_Product->getTitle(), $increment);
             }
             //set error to session
             if (isset($error) && !empty($error)) {
                 $this->_contents[$products_id_string]['error'] = $error;
             }
             if ($osC_Product->isGiftCertificate() && $osC_Product->isOpenAmountGiftCertificate()) {
                 $price = $this->_contents[$products_id_string]['price'];
             } else {
                 $price = $osC_Product->getPrice($variants, $quantity);
                 if ($osC_Services->isStarted('specials')) {
                     global $osC_Specials;
                     if ($new_price = $osC_Specials->getPrice($products_id, $variants)) {
                         $price = $new_price;
                     }
                 }
             }
             $this->_contents[$products_id_string]['quantity'] = $quantity;
             $this->_contents[$products_id_string]['price'] = $price;
             $this->_contents[$products_id_string]['final_price'] = $price;
             if ($toC_Customization_Fields->exists($products_id)) {
                 $fields = $toC_Customization_Fields->get($products_id);
                 $this->_contents[$products_id_string]['customizations'][time()] = array('qty' => $quantity - $old_quantity, 'fields' => array_values($fields));
                 $toC_Customization_Fields->remove($products_id);
             }
             // update database
             if ($osC_Customer->isLoggedOn()) {
                 $Qupdate = $osC_Database->query('update :table_customers_basket set customers_basket_quantity = :customers_basket_quantity, gift_certificates_data = :gift_certificates_data, customizations = :customizations where customers_id = :customers_id and products_id = :products_id');
                 $Qupdate->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
                 $Qupdate->bindInt(':customers_basket_quantity', $quantity);
                 if ($osC_Product->getProductType() == PRODUCT_TYPE_GIFT_CERTIFICATE) {
                     $Qupdate->bindValue(':gift_certificates_data', serialize($gift_certificates_data));
                 } else {
                     $Qupdate->bindRaw(':gift_certificates_data', 'null');
                 }
                 if (isset($this->_contents[$products_id_string]['customizations']) && !empty($this->_contents[$products_id_string]['customizations'])) {
                     $Qupdate->bindValue(':customizations', serialize($this->_contents[$products_id_string]['customizations']));
                 } else {
                     $Qupdate->bindRaw(':customizations', 'null');
                 }
                 $Qupdate->bindInt(':customers_id', $osC_Customer->getID());
                 $Qupdate->bindValue(':products_id', $products_id_string);
                 $Qupdate->execute();
             }
         } else {
             if (!is_numeric($quantity)) {
                 $quantity = 1;
             }
             if ($osC_Product->isGiftCertificate()) {
                 if ($quantity > 1) {
                     $quantity = 1;
                     $error = $osC_Language->get('error_gift_certificate_quantity_must_be_one');
                 }
             }
             //check minimum order quantity
             $products_moq = $osC_Product->getMOQ();
             if ($quantity < $products_moq) {
                 $quantity = $products_moq;
                 $error = sprintf($osC_Language->get('error_minimum_order_quantity'), $osC_Product->getTitle(), $products_moq);
             }
             //check order increment
             $increment = $osC_Product->getOrderIncrement();
             if (($quantity - $products_moq) % $increment != 0) {
                 $quantity = $products_moq + (floor(($quantity - $products_moq) / $increment) + 1) * $increment;
                 $error = sprintf($osC_Language->get('error_order_increment'), $osC_Product->getTitle(), $increment);
             }
             //if product has variants and variants is not given
             if ($osC_Product->hasVariants() && $variants == null) {
                 $variant = $osC_Product->getDefaultVariant();
                 $variants = osc_parse_variants_from_id_string($variant['product_id_string']);
             }
             if ($osC_Product->isGiftCertificate() && $osC_Product->isOpenAmountGiftCertificate()) {
                 $price = $gift_certificates_data['price'];
             } else {
                 $price = $osC_Product->getPrice($variants, $quantity);
                 if ($osC_Services->isStarted('specials')) {
                     global $osC_Specials;
                     if ($new_price = $osC_Specials->getPrice($products_id, $variants)) {
                         $price = $new_price;
                     }
                 }
             }
             $this->_contents[$products_id_string] = array('id' => $products_id_string, 'name' => $osC_Product->getTitle(), 'type' => $osC_Product->getProductType(), 'keyword' => $osC_Product->getKeyword(), 'sku' => $osC_Product->getSKU($variants), 'image' => $osC_Product->getImage(), 'price' => $price, 'final_price' => $price, 'quantity' => $quantity, 'weight' => $osC_Product->getWeight($variants), 'tax_class_id' => $osC_Product->getTaxClassID(), 'date_added' => osC_DateTime::getShort(osC_DateTime::getNow()), 'weight_class_id' => $osC_Product->getWeightClass(), 'gc_data' => $gift_certificates_data);
             if ($toC_Customization_Fields->exists($products_id)) {
                 $fields = $toC_Customization_Fields->get($products_id);
                 $time = time();
                 $this->_contents[$products_id_string]['customizations'][$time] = array('qty' => $quantity, 'fields' => array_values($fields));
                 $toC_Customization_Fields->remove($products_id);
             }
             //set error to session
             if (isset($error) && !empty($error)) {
                 $this->_contents[$products_id_string]['error'] = $error;
             }
             // insert into database
             if ($osC_Customer->isLoggedOn()) {
                 $Qnew = $osC_Database->query('insert into :table_customers_basket (customers_id, products_id, customers_basket_quantity, gift_certificates_data, customizations, customers_basket_date_added) values (:customers_id, :products_id, :customers_basket_quantity, :gift_certificates_data, :customizations, now())');
                 $Qnew->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
                 $Qnew->bindInt(':customers_id', $osC_Customer->getID());
                 $Qnew->bindValue(':products_id', $products_id_string);
                 $Qnew->bindInt(':customers_basket_quantity', $quantity);
                 if ($osC_Product->getProductType() == PRODUCT_TYPE_GIFT_CERTIFICATE) {
                     $Qnew->bindValue(':gift_certificates_data', serialize($gift_certificates_data));
                 } else {
                     $Qnew->bindRaw(':gift_certificates_data', 'null');
                 }
                 if (isset($this->_contents[$products_id_string]['customizations']) && !empty($this->_contents[$products_id_string]['customizations'])) {
                     $Qnew->bindValue(':customizations', serialize($this->_contents[$products_id_string]['customizations']));
                 } else {
                     $Qnew->bindRaw(':customizations', 'null');
                 }
                 $Qnew->execute();
             }
             if (is_array($variants) && !empty($variants)) {
                 $variants_array = $osC_Product->getVariants();
                 $products_variants_id_string = osc_get_product_id_string($products_id_string, $variants);
                 $products_variants_id = $variants_array[$products_variants_id_string]['variants_id'];
                 $this->_contents[$products_id_string]['products_variants_id'] = $products_variants_id;
                 if (isset($variants_array[$products_variants_id_string]['filename']) && !empty($variants_array[$products_variants_id_string]['filename'])) {
                     $this->_contents[$products_id_string]['variant_filename'] = $variants_array[$products_variants_id_string]['filename'];
                     $this->_contents[$products_id_string]['variant_cache_filename'] = $variants_array[$products_variants_id_string]['cache_filename'];
                 }
                 foreach ($variants as $group_id => $value_id) {
                     $Qvariants = $osC_Database->query('select pvg.products_variants_groups_name, pvv.products_variants_values_name from :table_products_variants pv, :table_products_variants_entries pve, :table_products_variants_groups pvg, :table_products_variants_values pvv where pv.products_id = :products_id and pv.products_variants_id = pve.products_variants_id and pve.products_variants_groups_id = :groups_id and pve.products_variants_values_id = :variants_values_id and pve.products_variants_groups_id = pvg.products_variants_groups_id and pve.products_variants_values_id = pvv.products_variants_values_id and pvg.language_id = :language_id and pvv.language_id = :language_id');
                     $Qvariants->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                     $Qvariants->bindTable(':table_products_variants_entries', TABLE_PRODUCTS_VARIANTS_ENTRIES);
                     $Qvariants->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
                     $Qvariants->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
                     $Qvariants->bindInt(':products_id', $osC_Product->getID());
                     $Qvariants->bindInt(':groups_id', $group_id);
                     $Qvariants->bindInt(':variants_values_id', $value_id);
                     $Qvariants->bindInt(':language_id', $osC_Language->getID());
                     $Qvariants->bindInt(':language_id', $osC_Language->getID());
                     $Qvariants->execute();
                     $this->_contents[$products_id_string]['variants'][$group_id] = array('groups_id' => $group_id, 'variants_values_id' => $value_id, 'groups_name' => $Qvariants->value('products_variants_groups_name'), 'values_name' => $Qvariants->value('products_variants_values_name'));
                 }
             }
         }
         $this->_cleanUp();
         $this->_calculate();
     }
 }
function output_compare_products_table()
{
    global $osC_Language, $osC_Image, $osC_Weight, $osC_Currencies, $toC_Compare_Products, $osC_Services;
    $content = '';
    $products_images = array();
    $products_titles = array();
    $products_price = array();
    $products_weight = array();
    $products_sku = array();
    $products_manufacturers = array();
    $products_desciptions = array();
    $products_attributes = array();
    $products_variants = array();
    $cols = array('<col width="20%">');
    $col_width = round(80 / count($toC_Compare_Products->getProducts()));
    if ($toC_Compare_Products->hasContents()) {
        foreach ($toC_Compare_Products->getProducts() as $products_id_string) {
            $cols[] = '<col width="' . $col_width . '%">';
            $osC_Product = new osC_Product($products_id_string);
            $products_id = osc_get_product_id($products_id_string);
            $image = $osC_Product->getImages();
            $product_title = $osC_Product->getTitle();
            $product_price = $osC_Product->getPriceFormated(true);
            $product_weight = $osC_Product->getWeight();
            $product_sku = $osC_Product->getSKU();
            //if the product have any variants, it means that the $products_id should be a product string such as 1#1:1;2:2
            $variants = array();
            if ($osC_Product->hasVariants()) {
                $product_variants = $osC_Product->getVariants();
                if (preg_match('/^[0-9]+(?:#?(?:[0-9]+:?[0-9]+)+(?:;?([0-9]+:?[0-9]+)+)*)+$/', $products_id_string)) {
                    $products_variant = $product_variants[$products_id_string];
                    $variants = osc_parse_variants_from_id_string($products_id_string);
                } else {
                    $products_variant = $osC_Product->getDefaultVariant();
                    $variants = $products_variant['groups_id'];
                }
                //if the product have any variants, get the group_name:value_name string
                if (isset($products_variant) && isset($products_variant['groups_name']) && is_array($products_variant['groups_name']) && !empty($products_variant['groups_name'])) {
                    $products_variants[$products_id_string]['variants'] = array();
                    foreach ($products_variant['groups_name'] as $groups_name => $value_name) {
                        $products_variants[$products_id_string]['variants'][] = array('name' => $groups_name, 'value' => $value_name);
                    }
                }
                $product_price = $osC_Currencies->displayPrice($osC_Product->getPrice($variants), $osC_Product->getTaxClassID());
                $product_weight = $products_variant['weight'];
                $product_sku = $products_variant['sku'];
                $image = $products_variant['image'];
            }
            $image = is_array($image) ? $image[0]['image'] : $image;
            $products_titles[] = $product_title;
            if (!osc_empty($product_price)) {
                $products_price[] = $product_price;
            }
            if (!osc_empty($product_weight)) {
                $products_weight[] = $osC_Weight->display($product_weight, $osC_Product->getWeightClass());
            }
            if (!osc_empty($product_sku)) {
                $products_sku[] = $product_sku;
            }
            if (!osc_empty($osC_Product->getManufacturer())) {
                $products_manufacturers[] = $osC_Product->getManufacturer();
            }
            if (!osc_empty($osC_Product->getDescription())) {
                $products_desciptions[] = $osC_Product->getDescription();
            }
            if ($osC_Product->hasAttributes()) {
                foreach ($osC_Product->getAttributes() as $attribute) {
                    $products_attributes[$products_id]['attributes'][] = array('name' => $attribute['name'], 'value' => $attribute['value']);
                }
            }
            $products_id_string = str_replace('#', '_', $products_id_string);
            //used to fix bug [#209 - Compare / wishlist variant problem]
            if (isset($osC_Services) && $osC_Services->isStarted('sefu') && count($variants) > 0) {
                $products_images[] = '<div class="image">' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $products_id), $osC_Image->show($image, $osC_Product->getTitle())) . '</div>' . '<div class="button">' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $products_id . '&pid=' . $products_id_string . '&action=cart_add'), '<i class="icon-shopping-cart icon-white"></i> ' . $osC_Language->get('button_add_to_cart'), 'class="btn btn-mini"') . '</div>';
            } else {
                $products_images[] = '<div class="image">' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $products_id), $osC_Image->show($image, $osC_Product->getTitle())) . '</div>' . '<div class="button">' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $products_id_string . '&action=cart_add'), '<i class="icon-shopping-cart icon-white"></i> ' . $osC_Language->get('button_add_to_cart'), 'class="btn btn-mini"') . '</div>';
            }
        }
        $content .= '<table class="table table-hover table-striped">';
        //add col groups
        $content .= '<colgroup>';
        foreach ($cols as $col) {
            $content .= $col;
        }
        $content .= '</colgroup>';
        //add product header
        $content .= '<tbody>';
        $content .= '<tr class="first">';
        $content .= '<th>&nbsp;</th>';
        if (!osc_empty($products_images)) {
            foreach ($products_images as $k => $product_image) {
                $content .= '<td' . ($k == count($products_images) - 1 ? ' class="last"' : '') . '>' . $product_image . '</td>';
            }
        }
        $content .= '</tr>';
        $content .= '</tbody>';
        //add compare details
        $content .= '<tbody>';
        $row_class = 'even';
        //add product name
        if (!osc_empty($products_titles)) {
            $content .= '<tr class="' . $row_class . '">' . '<th>' . $osC_Language->get('field_products_name') . '</th>';
            foreach ($products_titles as $k => $product_title) {
                $content .= '<td' . ($k == count($products_titles) - 1 ? ' class="last"' : '') . '>' . $product_title . '</td>';
            }
            $content .= '</tr>';
            $row_class = $row_class == 'even' ? 'odd' : 'even';
        }
        //add product price
        if (!osc_empty($products_price)) {
            $content .= '<tr class="' . $row_class . '">' . '<th>' . $osC_Language->get('field_products_price') . '</th>';
            foreach ($products_price as $k => $product_price) {
                $content .= '<td' . ($k == count($products_price) - 1 ? ' class="last"' : '') . '>' . $product_price . '</td>';
            }
            $content .= '</tr>';
            $row_class = $row_class == 'even' ? 'odd' : 'even';
        }
        //add product weight
        if (!osc_empty($products_weight)) {
            $content .= '<tr class="' . $row_class . '">' . '<th>' . $osC_Language->get('field_products_weight') . '</th>';
            foreach ($products_weight as $k => $product_weight) {
                $content .= '<td' . ($k == count($products_weight) - 1 ? ' class="last"' : '') . '>' . $product_weight . '</td>';
            }
            $content .= '</tr>';
            $row_class = $row_class == 'even' ? 'odd' : 'even';
        }
        //add product sku
        if (!osc_empty($products_sku)) {
            $content .= '<tr class="' . $row_class . '">' . '<th>' . $osC_Language->get('field_products_sku') . '</th>';
            foreach ($products_sku as $k => $product_sku) {
                $content .= '<td' . ($k == count($products_sku) - 1 ? ' class="last"' : '') . '>' . $product_sku . '</td>';
            }
            $content .= '</tr>';
            $row_class = $row_class == 'even' ? 'odd' : 'even';
        }
        //add product manufacturers
        if (!osc_empty($products_manufacturers)) {
            $content .= '<tr class="' . $row_class . '">' . '<th>' . $osC_Language->get('field_products_manufacturer') . '</th>';
            foreach ($products_manufacturers as $k => $product_manufacturer) {
                $content .= '<td' . ($k == count($products_manufacturers) - 1 ? ' class="last"' : '') . '>' . $product_manufacturer . '</td>';
            }
            $content .= '</tr>';
            $row_class = $row_class == 'even' ? 'odd' : 'even';
        }
        //add product variants
        if (!osc_empty($products_variants)) {
            $content .= '<tr class="' . $row_class . '">' . '<th>' . $osC_Language->get('field_products_variants') . '</th>';
            foreach ($toC_Compare_Products->getProducts() as $k => $products_id_string) {
                if (isset($products_variants[$products_id_string]['variants']) && !osc_empty($products_variants[$products_id_string]['variants'])) {
                    $content .= '<td' . ($k == count($toC_Compare_Products->getProducts()) - 1 ? ' class="last"' : '') . '>';
                    foreach ($products_variants[$products_id_string]['variants'] as $variant) {
                        $content .= '<span class="variant label label-info">' . $variant['name'] . ': ' . $variant['value'] . '</span>&nbsp;&nbsp;';
                    }
                    $content .= '</td>';
                }
            }
            $content .= '</tr>';
            $row_class = $row_class == 'even' ? 'odd' : 'even';
        }
        //add product attributes
        if (!osc_empty($products_attributes)) {
            $content .= '<tr class="' . $row_class . '">' . '<th>' . $osC_Language->get('field_products_attributes') . '</th>';
            foreach ($toC_Compare_Products->getProducts() as $k => $products_id_string) {
                if (isset($products_attributes[$products_id_string]['attributes']) && !osc_empty($products_attributes[$products_id_string]['attributes'])) {
                    $content .= '<td' . ($k == count($toC_Compare_Products->getProducts()) - 1 ? ' class="last"' : '') . '>';
                    foreach ($products_attributes[$products_id_string]['attributes'] as $attribute) {
                        $content .= '<span class="attribute">' . $attribute['name'] . ': ' . $attribute['value'] . '</span>';
                    }
                    $content .= '</td>';
                }
            }
            $content .= '</tr>';
            $row_class = $row_class == 'even' ? 'odd' : 'even';
        }
        //add product description
        if (!osc_empty($products_desciptions)) {
            $content .= '<tr class="' . $row_class . ' last">' . '<th>' . $osC_Language->get('field_products_description') . '</th>';
            foreach ($products_desciptions as $k => $product_description) {
                $content .= '<td' . ($k == count($products_desciptions) - 1 ? ' class="last"' : '') . '>' . $product_description . '</td>';
            }
            $content .= '</tr>';
            $row_class = $row_class == 'even' ? 'odd' : 'even';
        }
        $content .= '</tbody>';
        $content .= '</table>';
    }
    return $content;
}