public function lC_Products_Products() { global $lC_Database, $lC_Services, $lC_Session, $lC_Language, $lC_Breadcrumb, $lC_Product, $lC_Image, $lC_Currencies, $cPath_array; $template_code = isset($_SESSION['template']['code']) && $_SESSION['template']['code'] != NULL ? $_SESSION['template']['code'] : 'core'; if (empty($_GET) === false) { $id = false; // PHP < 5.0.2; array_slice() does not preserve keys and will not work with numerical key values, so foreach() is used foreach ($_GET as $key => $value) { $key = end(explode("/", $key)); if ((preg_match('/^[0-9]+(#?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$/', $key) || preg_match('/^[a-zA-Z0-9 -_]*$/', $key)) && $key != $lC_Session->getName()) { $id = $key; } break; } if ($id !== false && lC_Product::checkEntry($id)) { $lC_Product = new lC_Product($id); $lC_Product->incrementCounter(); if (strtotime($lC_Product->getDateAvailable()) <= strtotime(lC_Datetime::getShort())) { $this->addPageTags('description', substr(strip_tags($lC_Product->getDescription()), 0, 300)); $this->addPageTags('keywords', $lC_Product->getTitle()); $this->addPageTags('keywords', $lC_Product->getModel()); if ($lC_Product->hasTags()) { $this->addPageTags('keywords', $lC_Product->getTags()); } $this->addOGPTags('type', 'product'); $this->addOGPTags('title', $lC_Product->getTitle() . ' ' . $lC_Product->getModel()); $this->addOGPTags('description', $lC_Currencies->displayPrice($lC_Product->getPrice(), $lC_Product->getTaxClassID()) . ' - ' . $lC_Product->getTitle() . ' ' . lc_clean_html($lC_Product->getDescription())); $this->addOGPTags('url', lc_href_link(FILENAME_PRODUCTS, $lC_Product->getKeyword(), 'NONSSL', false, true, true)); $this->addOGPTags('image', HTTP_SERVER . DIR_WS_CATALOG . 'templates/' . $template_code . '/images/logo.png'); $this->addOGPTags('image', HTTP_SERVER . DIR_WS_CATALOG . $lC_Image->getAddress($lC_Product->getImage(), 'large')); if ($lC_Product->getImages() != '') { foreach ($lC_Product->getImages() as $key => $value) { if ($value['default_flag'] == true) { continue; } if (file_exists(DIR_FS_CATALOG . $lC_Image->getAddress($value['image'], 'popup'))) { $this->addOGPTags('image', HTTP_SERVER . DIR_WS_CATALOG . $lC_Image->getAddress($value['image'], 'large')); } } } lC_Services_category_path::process($lC_Product->getCategoryID()); if (empty($cPath_array) && $_GET['cPath'] == '' && isset($lC_Services) && $lC_Services->isStarted('seo')) { foreach ($_GET as $cats => $values) { $cats = explode("/", $cats); foreach ($cats as $cat) { $Qcid = $lC_Database->query('select item_id from :table_permalinks where permalink = :permalink and type = 1 and language_id = :language_id'); $Qcid->bindTable(':table_permalinks', TABLE_PERMALINKS); $Qcid->bindValue(':permalink', $cat); $Qcid->bindInt(':language_id', $lC_Language->getID()); $Qcid->execute(); $cPath_array[] = $Qcid->valueInt('item_id'); } } } if ($lC_Services->isStarted('breadcrumb')) { if (isset($_GET['cPath']) && $_GET['cPath'] != '') { $path = $_GET['cPath']; } else { $path = implode("_", $cPath_array); } $lC_Breadcrumb->add($lC_Product->getTitle(), lc_href_link(FILENAME_PRODUCTS, $lC_Product->getKeyword()), $path); } $this->_page_title = $lC_Product->getTitle(); } else { $this->_page_title = $lC_Language->get('product_not_found_heading'); $this->_page_contents = 'info_not_available.php'; } } else { $this->_page_title = $lC_Language->get('product_not_found_heading'); $this->_page_contents = 'info_not_found.php'; } } else { $this->_page_title = $lC_Language->get('product_not_found_heading'); $this->_page_contents = 'info_not_found.php'; } }
public function add($product_id, $quantity = null) { global $lC_Database, $lC_Services, $lC_Language, $lC_Customer, $lC_Product; if (!is_numeric($product_id)) { return false; } $Qproduct = $lC_Database->query('select p.*, i.image from :table_products p left join :table_products_images i on (p.products_id = i.products_id and i.default_flag = :default_flag) where p.products_id = :products_id'); $Qproduct->bindTable(':table_products', TABLE_PRODUCTS); $Qproduct->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES); $Qproduct->bindInt(':default_flag', 1); $Qproduct->bindInt(':products_id', $product_id); $Qproduct->execute(); if ($Qproduct->value('image') == null) { // check for parent image $Qimage = $lC_Database->query('select image from :table_products_images where products_id = :parent_id'); $Qimage->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES); $Qimage->bindInt(':default_flag', 1); $Qimage->bindInt(':parent_id', $Qproduct->valueInt('parent_id')); $Qimage->execute(); $image = $Qimage->value('image'); } else { $image = $Qproduct->value('image'); } if ($Qproduct->valueInt('products_status') === 1) { if ($this->exists($product_id)) { $item_id = $this->getBasketID($product_id); if (is_numeric($quantity)) { $quantity = $this->getQuantity($item_id) + 1; } $this->_contents[$item_id]['quantity'] = $quantity; if ($lC_Customer->isLoggedOn()) { $Qupdate = $lC_Database->query('update :table_shopping_carts set quantity = :quantity where customers_id = :customers_id and item_id = :item_id'); $Qupdate->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS); $Qupdate->bindInt(':quantity', $quantity); $Qupdate->bindInt(':customers_id', $lC_Customer->getID()); $Qupdate->bindInt(':item_id', $item_id); $Qupdate->execute(); } } else { if (!is_numeric($quantity)) { $quantity = 1; } $Qdescription = $lC_Database->query('select products_name, products_keyword, products_description, products_tags, products_url from :table_products_description where products_id = :products_id and language_id = :language_id'); $Qdescription->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION); $Qdescription->bindInt(':products_id', $product_id); $Qdescription->bindInt(':language_id', $lC_Language->getID()); $Qdescription->execute(); $desc = $Qdescription->toArray(); if ($Qproduct->valueInt('parent_id') > 0) { $Qmaster = $lC_Database->query('select products_name as parent_name, products_description as description, products_keyword as keyword, products_tags as tags, products_url as url from :table_products_description where products_id = :products_id and language_id = :language_id limit 1'); $Qmaster->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION); $Qmaster->bindInt(':products_id', $Qproduct->valueInt('parent_id')); $Qmaster->bindInt(':language_id', $lC_Language->getID()); $Qmaster->execute(); if ($Qproduct->valueInt('is_subproduct') > 0) { $desc['products_name'] = $Qmaster->value('parent_name') . ' - ' . $desc['products_name']; } else { $desc['products_name'] = $Qmaster->value('parent_name'); } $desc['products_description'] = $Qmaster->value('description'); $desc['products_keyword'] = $Qmaster->value('keyword'); $desc['products_tags'] = $Qmaster->value('tags'); $desc['products_url'] = $Qmaster->value('url'); } // we get the product price from the product class - price already includes options, etc. if (!isset($lC_Product)) { $lC_Product = new lC_Product($product_id); } $price = $lC_Product->getPrice($product_id, $lC_Customer->getCustomerGroup(), $_POST); if ($lC_Customer->isLoggedOn()) { $Qid = $lC_Database->query('select max(item_id) as item_id from :table_shopping_carts where customers_id = :customers_id'); $Qid->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS); $Qid->bindInt(':customers_id', $lC_Customer->getID()); $Qid->execute(); $item_id = $Qid->valueInt('item_id') + 1; } else { if (empty($this->_contents)) { $item_id = 1; } else { $item_id = max(array_keys($this->_contents)) + 1; } } $this->_contents[$item_id] = array('item_id' => $item_id, 'id' => $product_id, 'parent_id' => $Qproduct->valueInt('parent_id'), 'name' => $desc['products_name'], 'model' => $Qproduct->value('products_model'), 'sku' => $Qproduct->value('products_sku'), 'keyword' => $desc['products_keyword'], 'tags' => $desc['products_tags'], 'url' => $desc['products_url'], 'description' => $desc['products_description'], 'image' => $image, 'price' => $price, 'quantity' => $quantity, 'weight' => $Qproduct->value('products_weight'), 'tax_class_id' => $Qproduct->valueInt('products_tax_class_id'), 'date_added' => lC_DateTime::getShort(lC_DateTime::getNow()), 'weight_class_id' => $Qproduct->valueInt('products_weight_class')); // simple options if (isset($_POST['simple_options']) && empty($_POST['simple_options']) === false) { foreach ($_POST['simple_options'] as $options_id => $values_id) { if (is_array($values_id)) { $text_value = current($values_id); // for text fields $values_id = key($values_id); } $QsimpleOptionsValues = $lC_Database->query('select price_modifier from :table_products_simple_options_values where options_id = :options_id and values_id = :values_id and customers_group_id = :customers_group_id'); $QsimpleOptionsValues->bindTable(':table_products_simple_options_values', TABLE_PRODUCTS_SIMPLE_OPTIONS_VALUES); $QsimpleOptionsValues->bindInt(':options_id', $options_id); $QsimpleOptionsValues->bindInt(':values_id', $values_id); $QsimpleOptionsValues->bindInt(':customers_group_id', '1'); $QsimpleOptionsValues->execute(); $Qvariants = $lC_Database->query('select pvg.title as group_title, pvg.module, pvv.title as value_title from :table_products_variants_groups pvg, :table_products_variants_values pvv where pvg.id = :options_id and pvv.id = :values_id and pvv.languages_id = :languages_id and pvv.products_variants_groups_id = pvg.id and pvg.languages_id = :languages_id limit 1'); $Qvariants->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS); $Qvariants->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES); $Qvariants->bindInt(':options_id', $options_id); $Qvariants->bindInt(':values_id', $values_id); $Qvariants->bindInt(':languages_id', $lC_Language->getID()); $Qvariants->bindInt(':languages_id', $lC_Language->getID()); $Qvariants->execute(); if (strstr($Qvariants->value('module'), 'file_upload')) { $group_title = is_array($_FILES['simple_options_upload']['name']) && count($_FILES['simple_options_upload']['name']) > 2 ? $lC_Language->get('text_label_files') : $lC_Language->get('text_label_file'); $value_title = is_array($_FILES['simple_options_upload']['name']) ? implode(', ', $_FILES['simple_options_upload']['name']) : $_FILES['simple_options_upload']['name']; if (substr($value_title, -2) == ', ') { $value_title = substr($value_title, 0, -2); } $value_title = str_replace(', ,', ', ', $value_title); if ($value_title == '') { $group_title = ''; } if (is_array($_FILES['simple_options_upload']['name'])) { $filesArr = $_FILES; $_SESSION['file_upload'] = $_FILES['simple_options_upload']; foreach ($filesArr['simple_options_upload']['name'] as $key => $file) { $_FILES = array('simple_options_upload' => array('name' => $file, 'type' => $filesArr['simple_options_upload']['type'][$key], 'tmp_name' => $filesArr['simple_options_upload']['tmp_name'][$key], 'error' => $filesArr['simple_options_upload']['error'][$key], 'size' => $filesArr['simple_options_upload']['size'][$key])); // upload the file $image = new upload('simple_options_upload', realpath('pub')); if ($image->exists()) { if ($image->parse() && $image->save()) { // success } } } } } else { if ($Qvariants->value('module') == 'text_field') { $group_title = $Qvariants->value('group_title'); $value_title = $text_value; } else { $group_title = $Qvariants->value('group_title'); $value_title = $Qvariants->value('value_title'); } } $this->_contents[$item_id]['simple_options'][] = array('value_id' => $values_id, 'group_id' => $options_id, 'group_title' => $group_title, 'value_title' => $value_title, 'price_modifier' => $QsimpleOptionsValues->valueDecimal('price_modifier')); $QsimpleOptionsValues->freeResult(); $Qvariants->freeResult(); } } if ($lC_Customer->isLoggedOn()) { $Qnew = $lC_Database->query('insert into :table_shopping_carts (customers_id, item_id, products_id, quantity, meta_data, date_added) values (:customers_id, :item_id, :products_id, :quantity, :meta_data, :date_added)'); $Qnew->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS); $Qnew->bindInt(':customers_id', $lC_Customer->getID()); $Qnew->bindInt(':item_id', $item_id); $Qnew->bindInt(':products_id', $product_id); $Qnew->bindInt(':quantity', $quantity); $Qnew->bindValue(':meta_data', serialize($this->_contents[$item_id]['simple_options'])); $Qnew->bindRaw(':date_added', 'now()'); $Qnew->execute(); } if ($Qproduct->valueInt('parent_id') > 0) { $Qvariant = $lC_Database->query('select pvg.id as group_id, pvg.title as group_title, pvg.module, pvv.id as value_id, pvv.title as value_title from :table_products_variants pv, :table_products_variants_values pvv, :table_products_variants_groups pvg where pv.products_id = :products_id and pv.products_variants_values_id = pvv.id and pvv.languages_id = :languages_id and pvv.products_variants_groups_id = pvg.id and pvg.languages_id = :languages_id'); $Qvariant->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS); $Qvariant->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES); $Qvariant->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS); $Qvariant->bindInt(':products_id', $product_id); $Qvariant->bindInt(':languages_id', $lC_Language->getID()); $Qvariant->bindInt(':languages_id', $lC_Language->getID()); $Qvariant->execute(); while ($Qvariant->next()) { $group_title = lC_Variants::getGroupTitle($Qvariant->value('module'), $Qvariant->toArray()); $value_title = lC_Variants::getValueTitle($Qvariant->value('module'), $Qvariant->toArray()); $has_custom_value = lC_Variants::hasCustomValue($Qvariant->value('module')); if (strstr($Qvariant->value('module'), 'file_upload')) { $group_title = is_array($_FILES['variants_upload']['name']) && count($_FILES['variants_upload']['name']) > 2 ? $lC_Language->get('text_label_files') : $lC_Language->get('text_label_file'); $value_title = is_array($_FILES['variants_upload']['name']) ? implode(', ', $_FILES['variants_upload']['name']) : $_FILES['variants_upload']['name']; if (substr($value_title, -2) == ', ') { $value_title = substr($value_title, 0, -2); } if (is_array($_FILES['variants_upload']['name'])) { $filesArr = $_FILES; $_SESSION['file_upload'] = $_FILES['variants_upload']; foreach ($filesArr['variants_upload']['name'] as $key => $file) { $_FILES = array('variants_upload' => array('name' => $file, 'type' => $filesArr['variants_upload']['type'][$key], 'tmp_name' => $filesArr['variants_upload']['tmp_name'][$key], 'error' => $filesArr['variants_upload']['error'][$key], 'size' => $filesArr['variants_upload']['size'][$key])); // upload the file $image = new upload('variants_upload', realpath('pub')); if ($image->exists()) { if ($image->parse() && $image->save()) { // success } } } } } else { if ($Qvariant->value('module') == 'text_field') { $group_title = $Qvariant->value('group_title'); } else { $group_title = $Qvariant->value('group_title'); $value_title = $Qvariant->value('value_title'); } } $this->_contents[$item_id]['variants'][] = array('group_id' => $Qvariant->valueInt('group_id'), 'value_id' => $Qvariant->valueInt('value_id'), 'group_title' => $group_title, 'value_title' => $value_title, 'has_custom_value' => $has_custom_value); if ($lC_Customer->isLoggedOn() && $has_custom_value === true) { $Qnew = $lC_Database->query('insert into :table_shopping_carts_custom_variants_values (shopping_carts_item_id, customers_id, products_id, products_variants_values_id, products_variants_values_text) values (:shopping_carts_item_id, :customers_id, :products_id, :products_variants_values_id, :products_variants_values_text)'); $Qnew->bindTable(':table_shopping_carts_custom_variants_values', TABLE_SHOPPING_CARTS_CUSTOM_VARIANTS_VALUES); $Qnew->bindInt(':shopping_carts_item_id', $item_id); $Qnew->bindInt(':customers_id', $lC_Customer->getID()); $Qnew->bindInt(':products_id', $product_id); $Qnew->bindInt(':products_variants_values_id', $Qvariant->valueInt('value_id')); $Qnew->bindValue(':products_variants_values_text', $value_title); $Qnew->execute(); } } } } $this->_cleanUp(); $this->_calculate(); } }
public function lC_Products_Reviews() { global $lC_Services, $lC_Session, $lC_Language, $lC_Breadcrumb, $lC_Product, $lC_Customer, $lC_NavigationHistory, $lC_Image, $lC_Currencies; if ($lC_Services->isStarted('reviews') === false) { lc_redirect(lc_href_link(FILENAME_DEFAULT)); } $this->_page_title = $lC_Language->get('reviews_heading'); $template_code = isset($_SESSION['template']['code']) && $_SESSION['template']['code'] != NULL ? $_SESSION['template']['code'] : 'core'; $this->addJavascriptPhpFilename('templates/' . $template_code . '/javascript/form_check.js.php'); if ($lC_Services->isStarted('breadcrumb')) { $lC_Breadcrumb->add($lC_Language->get('breadcrumb_reviews'), lc_href_link(FILENAME_PRODUCTS, $this->_module)); } if (is_numeric($_GET[$this->_module])) { if (lC_Reviews::exists($_GET[$this->_module])) { $lC_Product = new lC_Product(lC_Reviews::getProductID($_GET[$this->_module])); $this->_page_title = $lC_Product->getTitle(); $this->addOGPTags('type', 'product'); $this->addOGPTags('title', $lC_Product->getTitle() . ' ' . $lC_Product->getModel()); $this->addOGPTags('description', $lC_Currencies->displayPrice($lC_Product->getPrice(), $lC_Product->getTaxClassID()) . ' - ' . $lC_Product->getTitle() . ' ' . lc_clean_html($lC_Product->getDescription())); $this->addOGPTags('url', lc_href_link(FILENAME_PRODUCTS, $lC_Product->getKeyword(), 'NONSSL', false, true, true)); $this->addOGPTags('image', HTTP_SERVER . DIR_WS_CATALOG . 'templates/' . $template_code . '/images/logo.png'); $this->addOGPTags('image', HTTP_SERVER . DIR_WS_CATALOG . $lC_Image->getAddress($lC_Product->getImage(), 'large')); foreach ($lC_Product->getImages() as $key => $value) { if ($value['default_flag'] == true) { continue; } if (file_exists(DIR_FS_CATALOG . $lC_Image->getAddress($value['image'], 'popup'))) { $this->addOGPTags('image', HTTP_SERVER . DIR_WS_CATALOG . $lC_Image->getAddress($value['image'], 'large')); } } } $this->_page_contents = 'reviews_info.php'; if ($lC_Services->isStarted('breadcrumb')) { $lC_Breadcrumb->add($lC_Product->getTitle(), lc_href_link(FILENAME_PRODUCTS, $this->_module . '=' . $_GET[$this->_module])); } } else { $this->_page_contents = 'reviews_not_found.php'; } $counter = 0; foreach ($_GET as $key => $value) { $counter++; if ($counter < 2) { continue; } if ((preg_match('/^[0-9]+(#?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$/', $key) || preg_match('/^[a-zA-Z0-9 -_]*$/', $key)) && $key != $lC_Session->getName()) { if (lC_Product::checkEntry($key) === false) { $this->_page_contents = 'info_not_found.php'; } elseif ($_GET[$this->_module] == 'new') { if ($lC_Customer->isLoggedOn() === false && SERVICE_REVIEW_ENABLE_REVIEWS == 1) { $lC_NavigationHistory->setSnapshot(); lc_redirect(lc_href_link(FILENAME_ACCOUNT, 'login', 'SSL')); } $lC_Product = new lC_Product($key); $this->_page_title = $lC_Product->getTitle(); $this->_page_contents = 'reviews_new.php'; if ($lC_Services->isStarted('breadcrumb')) { $lC_Breadcrumb->add($lC_Product->getTitle(), lc_href_link(FILENAME_PRODUCTS, $this->_module . '&' . $lC_Product->getKeyword())); $lC_Breadcrumb->add($lC_Language->get('breadcrumb_reviews_new'), lc_href_link(FILENAME_PRODUCTS, $this->_module . '=new&' . $lC_Product->getKeyword())); } if (isset($_GET['action']) && $_GET['action'] == 'process') { $this->_process($lC_Product->getID()); } } else { $lC_Product = new lC_Product($key); $this->_page_title = $lC_Product->getTitle(); $this->_page_contents = 'product_reviews.php'; if ($lC_Services->isStarted('breadcrumb')) { $lC_Breadcrumb->add($lC_Product->getTitle(), lc_href_link(FILENAME_PRODUCTS, $this->_module . '&' . $lC_Product->getKeyword())); } } } break; } if ($counter < 2) { if (lC_Reviews::exists() === false) { $this->_page_contents = 'reviews_not_found.php'; } } }