function initialize() { global $osC_Language, $osC_Template, $toC_Compare_Products; if ($toC_Compare_Products->hasContents()) { $osC_Template->addStyleSheet('ext/multibox/multibox.css'); $osC_Template->addJavascriptFilename('ext/multibox/Overlay.js'); $osC_Template->addJavascriptFilename('ext/multibox/MultiBox.js'); $this->_content = '<ul>'; foreach ($toC_Compare_Products->getProducts() as $products_id) { $osC_Product = new osC_Product($products_id); $cid = $products_id; $str_variants = ''; //if the product have any variants, it means that the $products_id should be a product string such as 1#1:1;2:2 if ($osC_Product->hasVariants()) { $variants = $osC_Product->getVariants(); if (preg_match('/^[0-9]+(#?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)+$/', $products_id)) { $products_variant = $variants[$products_id]; } else { $products_variant = $osC_Product->getDefaultVariant(); } //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'])) { $str_variants .= ' -- '; foreach ($products_variant['groups_name'] as $groups_name => $value_name) { $str_variants .= '<strong>' . $groups_name . ': ' . $value_name . '</strong>;'; } //clean the last ';' if (($pos = strrpos($str_variants, ';')) !== false) { $str_variants = substr($str_variants, 0, -1); } } //build the product string that could be used if (strpos($products_id, '#') !== false) { $cid = str_replace('#', '_', $products_id); } } $this->_content .= '<li>' . osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), 'cid=' . $cid . '&' . osc_get_all_get_params(array('cid', 'action')) . '&action=compare_products_remove'), osc_draw_image_button('button_delete_icon.png', $osC_Language->get('button_delete')), 'style="float: right; margin: 0 3px 1px 3px"') . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $products_id), $osC_Product->getTitle() . $str_variants) . '</li>'; } $this->_content .= '</ul>'; $this->_content .= '<p>' . '<span style="float: right">' . osc_link_object(osc_href_link(FILENAME_JSON, 'module=products&action=compare_products'), osc_draw_image_button('small_compare_now.png', $osC_Language->get('button_compare_now')), 'class="multibox" rel="ajax:true"') . '</span>' . osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), osc_get_all_get_params(array('action')) . '&action=compare_products_clear'), osc_draw_image_button('small_clear.png', $osC_Language->get('button_clear'))) . ' ' . '</p>'; $js .= '<script type="text/javascript"> window.addEvent("domready",function() { var box = new MultiBox(\'multibox\', { movieWidth: 820, movieHeight: 600 }); }); </script>'; $this->_content .= "\n" . $js; } }
function add($products_id, $variants = array()) { global $osC_Database, $osC_Services, $osC_Customer, $osC_Product; //if wishlist empty, create a new wishlist if (!$this->hasWishlistID()) { $token = $this->generateToken(); $Qnew = $osC_Database->query('insert into :table_wishlists (customers_id, wishlists_token) values (:customers_id, :wishlists_token)'); $Qnew->bindTable(':table_wishlists', TABLE_WISHLISTS); $Qnew->bindInt(':customers_id', $osC_Customer->getID()); $Qnew->bindValue(':wishlists_token', $token); $Qnew->execute(); $this->_wishlists_id = $osC_Database->nextID(); $this->_token = $token; $Qnew->freeResult(); } if (!isset($osC_Product)) { $osC_Product = new osC_Product($products_id); } if ($osC_Product->getID() > 0) { if (!$this->exists($products_id)) { $product_price = $osC_Product->getPrice(); $product_name = $osC_Product->getTitle(); $product_image = $osC_Product->getImage(); if ($osC_Services->isStarted('specials')) { global $osC_Specials; if ($new_price = $osC_Specials->getPrice($products_id)) { $price = $new_price; } } //if the product has variants, set the image, price etc according to the variants if ($osC_Product->hasVariants()) { $products_variants = $osC_Product->getVariants(); if (is_array($variants) && !osc_empty($variants)) { $product_id_string = osc_get_product_id_string($products_id, $variants); $products_variant = $products_variants[$product_id_string]; } else { $products_variant = $osC_Product->getDefaultVariant(); } $variants_groups_id = $products_variant['groups_id']; $variants_groups_name = $products_variant['groups_name']; if (!osc_empty($variants_groups_name)) { $product_name .= '<br />'; foreach ($variants_groups_name as $group_name => $value_name) { $product_name .= '<em>' . $group_name . ': ' . $value_name . '</em>' . '<br />'; } } $product_price = $products_variant['price']; $product_image = $products_variant['image']; } $this->_contents[$products_id] = array('products_id' => $products_id, 'name' => $product_name, 'image' => $product_image, 'price' => $product_price, 'date_added' => osC_DateTime::getShort(osC_DateTime::getNow()), 'variants' => $variants, 'comments' => ''); //insert into wishlist products $Qnew = $osC_Database->query('insert into :table_wishlist_products (wishlists_id, products_id, date_added, comments) values (:wishlists_id, :products_id, now(), :comments)'); $Qnew->bindTable(':table_wishlist_products', TABLE_WISHLISTS_PRODUCTS); $Qnew->bindInt(':wishlists_id', $this->_wishlists_id); $Qnew->bindInt(':products_id', $products_id); $Qnew->bindValue(':comments', ''); $Qnew->execute(); $wishlists_products_id = $osC_Database->nextID(); $Qnew->freeResult(); //if the wishlists products has variants $products_variants_groups_id = array(); $products_variants_groups_name = array(); if (isset($variants_groups_id) && isset($variants_groups_name)) { foreach ($variants_groups_id as $groups_id => $values_id) { $products_variants_groups_id[] = array('groups_id' => $groups_id, 'values_id' => $values_id); } foreach ($variants_groups_name as $groups_name => $values_name) { $products_variants_groups_name[] = array('groups_name' => $groups_name, 'values_name' => $values_name); } } if (!osc_empty($products_variants_groups_id)) { foreach ($products_variants_groups_id as $key => $groups_id) { $Qinsert = $osC_Database->query('insert into :table_wishlists_products_variants (wishlists_id, wishlists_products_id, products_variants_groups_id, products_variants_groups, products_variants_values_id, products_variants_values) values (:wishlists_id, :wishlists_products_id, :products_variants_groups_id, :products_variants_groups, :products_variants_values_id, :products_variants_values)'); $Qinsert->bindTable(':table_wishlists_products_variants', TABLE_WISHLISTS_PRODUCTS_VARIANTS); $Qinsert->bindInt(':wishlists_id', $this->_wishlists_id); $Qinsert->bindInt(':wishlists_products_id', $wishlists_products_id); $Qinsert->bindInt(':products_variants_groups_id', $groups_id['groups_id']); $Qinsert->bindInt(':products_variants_values_id', $groups_id['values_id']); $Qinsert->bindValue(':products_variants_groups', $products_variants_groups_name[$key]['groups_name']); $Qinsert->bindValue(':products_variants_values', $products_variants_groups_name[$key]['values_name']); $Qinsert->execute(); } } } } }
case 'PRODUCT_LIST_BUY_NOW': $lc_align = 'center'; $lc_text = ''; if ($Qlisting->value('products_type') == PRODUCT_TYPE_SIMPLE) { //enable quantity input field if (defined('PRODUCT_LIST_QUANTITY_INPUT') && PRODUCT_LIST_QUANTITY_INPUT == 1) { $lc_text .= '<input type="text" id="qty_' . $Qlisting->value('products_id') . '" value="1" size="1" class="qtyField" />'; } $lc_text .= osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $Qlisting->value('products_id') . '&' . osc_get_all_get_params(array('action')) . '&action=cart_add'), osc_draw_image_button('button_buy_now.gif', $osC_Language->get('button_buy_now'), 'class="ajaxAddToCart" id="ac_productlisting_' . $Qlisting->value('products_id') . '"')) . ' <br />'; } else { $lc_text .= osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $Qlisting->value('products_id') . '&' . osc_get_all_get_params(array('action')) . '&action=cart_add'), osc_draw_image_button('button_buy_now.gif', $osC_Language->get('button_buy_now'))) . ' <br />'; } //used to fix bug [#209] - support variants products for the wishlist if ($variants_enabled) { if ($osC_Product->hasVariants()) { $default_variant = $osC_Product->getDefaultVariant(); $product_id_string = str_replace('#', '_', $default_variant['product_id_string']); if ($osC_Template->isInstalled('compare_products', 'boxes')) { $lc_text .= osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), 'cid=' . $product_id_string . '&' . osc_get_all_get_params(array('action')) . '&action=compare_products_add'), $osC_Language->get('add_to_compare'), 'class="compare"') . ' <br />'; } $lc_text .= osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $Qlisting->value('products_id') . '&' . osc_get_all_get_params(array('action')) . '&wid=' . $product_id_string . '&action=wishlist_add'), $osC_Language->get('add_to_wishlist'), 'class="wishlist"'); } else { if ($osC_Template->isInstalled('compare_products', 'boxes')) { $lc_text .= osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), 'cid=' . $Qlisting->value('products_id') . '&' . osc_get_all_get_params(array('action')) . '&action=compare_products_add'), $osC_Language->get('add_to_compare'), 'class="compare"') . ' <br />'; } $lc_text .= osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $Qlisting->value('products_id') . '&' . osc_get_all_get_params(array('action')) . '&action=wishlist_add'), $osC_Language->get('add_to_wishlist'), 'class="wishlist"'); } } else { if ($osC_Template->isInstalled('compare_products', 'boxes')) { $lc_text .= osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), 'cid=' . $Qlisting->value('products_id') . '&' . osc_get_all_get_params(array('action')) . '&action=compare_products_add'), $osC_Language->get('add_to_compare'), 'class="compare"') . ' <br />'; }
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> </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; }
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> </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> '; } $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; }