unset($warranty_data[0]); foreach ($warranty_data as $id => $val) { if (!empty($id)) { $val['warranty_id'] = $id; } if ($val['del'] == 'Y') { cw_delete_warranty($id); } } cw_header_location("index.php?target={$target}"); } if ($action == 'update_lng') { $warranty_data['code'] = $edited_language; $warranty_data['warranty_id'] = $warranty_id; cw_array2insert('warranties_lng', $warranty_data, true); cw_header_location("index.php?target={$target}&warranty_id={$warranty_id}"); } if ($action == 'add') { cw_array2insert('warranties', $warranty_data[0], true); cw_header_location("index.php?target=warranties"); cw_header_location("index.php?target={$target}&warranty_id={$warranty_id}"); } if ($warranty_id) { $smarty->assign('warranty', cw_get_warranty($warranty_id, $edited_language)); $smarty->assign('warranty_id', $warranty_id); $smarty->assign('main', 'warranty'); } else { $location[] = array(cw_get_langvar_by_name('lbl_warranties'), ''); $smarty->assign('warranties', cw_get_warranties($edited_language)); $smarty->assign('main', 'warranties'); }
function cw_product_get($params, $return = null) { extract($params); global $customer_id, $customer_id_type, $current_area, $cart, $current_location; global $current_language, $tables, $config, $addons; cw_load('files', 'taxes', 'tags'); $lang = $lang ? $lang : $current_language; $variant_id = $variant_id ? $variant_id : 0; $amount = intval($amount > 0 ? $amount : 1); $fields = $from_tbls = $query_joins = $where = array(); # kornev, merge standart and additional variables if ($return) { foreach ($return as $saname => $sadata) { if (isset(${$saname}) && is_array(${$saname}) && empty(${$saname})) { ${$saname} = $sadata; } } } $from_tbls[] = 'products'; $where[] = "{$tables['products']}.product_id='{$id}'"; # kornev # customer area - all of the checkings # pos area - not check for membership, just available for sale property if (in_array($current_area, array('C'))) { $memberships = array(0); if ($user_account['membership_id'] > 0) { $memberships[] = intval($user_account['membership_id']); } $where[] = "{$tables['products_memberships']}.membership_id IN (" . join(',', $memberships) . ")"; $where[] = "{$tables['products_prices']}.quantity <= {$amount} and {$tables['products_prices']}.membership_id in (" . join(',', $memberships) . ")"; if ($config['Appearance']['categories_in_products'] == '1') { $where[] = "{$tables['categories_memberships']}.membership_id IN (" . join(',', $memberships) . ")"; $query_joins['products_categories'] = array('on' => "{$tables['products_categories']}.product_id = {$tables['products']}.product_id", 'pos' => '0', 'is_straight' => 1); $query_joins['categories'] = array('on' => "{$tables['products_categories']}.category_id = {$tables['categories']}.category_id", 'parent' => 'products_categories'); $query_joins['categories_memberships'] = array('on' => "{$tables['categories_memberships']}.category_id = {$tables['categories']}.category_id", 'parent' => 'categories', 'is_straight' => 1); } $where[] = "{$tables['products']}.status in ('" . implode("', '", cw_core_get_required_status($current_area)) . "')"; } elseif (in_array($current_area, array('G'))) { $where[] = "{$tables['products']}.product_id = {$tables['products_prices']}.product_id AND {$tables['products_prices']}.quantity <= {$amount} and {$tables['products_prices']}.membership_id in (" . join(',', $memberships) . ")"; } $fields[] = "{$tables['products']}.*"; $query_joins['products_warehouses_amount'] = array('on' => "{$tables['products']}.product_id = {$tables['products_warehouses_amount']}.product_id and {$tables['products_warehouses_amount']}.warehouse_customer_id=0 and {$tables['products_warehouses_amount']}.variant_id='{$variant_id}'"); $in_cart = 0; if ($current_area == 'C' && !empty($cart) && !empty($cart['products'])) { foreach ($cart['products'] as $cart_item) { if ($cart_item['product_id'] == $id) { $in_cart += $cart_item['amount']; } } } $fields[] = "{$tables['products_warehouses_amount']}.avail-{$in_cart} AS avail"; # kornev, TOFIX if ($addons['product_options'] && in_array($current_area, array('A', 'P'))) { $query_joins['product_variants'] = array('on' => "{$tables['products']}.product_id = {$tables['product_variants']}.product_id"); $fields[] = "IF({$tables['product_variants']}.product_id IS NULL, '', 'Y') as is_variants"; } /* if ($addons['manufacturers']) { $query_joins['manufacturers'] = array( 'on' => "$tables[manufacturers].manufacturer_id = $tables[products].manufacturer_id", ); $fields[] = "$tables[manufacturers].manufacturer"; } */ // statistic $fields[] = "{$tables['products_stats']}.views_stats"; $fields[] = "{$tables['products_stats']}.sales_stats"; $fields[] = "{$tables['products_stats']}.del_stats"; $fields[] = "{$tables['products_stats']}.add_to_cart"; $query_joins['products_stats'] = array('on' => "{$tables['products_stats']}.product_id = {$tables['products']}.product_id"); if ($current_area == 'A' || $current_area == 'P') { $fields[] = "{$tables['products_prices']}.price"; $fields[] = "{$tables['products_prices']}.list_price"; $query_joins['products_prices'] = array('on' => "{$tables['products_prices']}.product_id={$tables['products']}.product_id AND {$tables['products_prices']}.variant_id = '{$variant_id}' and {$tables['products_prices']}.quantity <= {$amount}"); } else { $query_joins['products_prices'] = array('on' => "{$tables['products_prices']}.product_id={$tables['products']}.product_id", 'is_inner' => 1); # kornev, find the min price and select only this record. $fields[] = "min({$tables['products_prices']}.price) as price"; $fields[] = "{$tables['products_prices']}.variant_id"; $fields[] = "min({$tables['products_prices']}.list_price) as list_price"; } $fields[] = "IF({$tables['products_lng']}.product_id != '', {$tables['products_lng']}.product, {$tables['products']}.product) as product"; $fields[] = "IF({$tables['products_lng']}.product_id != '', {$tables['products_lng']}.descr, {$tables['products']}.descr) as descr"; $fields[] = "IF({$tables['products_lng']}.product_id != '', {$tables['products_lng']}.fulldescr, {$tables['products']}.fulldescr) as fulldescr"; $fields[] = "IF({$tables['products_lng']}.product_id != '', {$tables['products_lng']}.features_text, {$tables['products']}.features_text) as features_text"; $fields[] = "IF({$tables['products_lng']}.product_id != '', {$tables['products_lng']}.specifications, {$tables['products']}.specifications) as specifications"; $query_joins['products_lng'] = array('on' => "{$tables['products_lng']}.code='{$lang}' AND {$tables['products_lng']}.product_id = {$tables['products']}.product_id"); if (in_array($current_area, array('C', 'G', 'S'))) { $fields[] = "{$tables['products_flat']}.*"; $query_joins['products_flat'] = array('on' => "{$tables['products']}.product_id = {$tables['products_flat']}.product_id"); if ($current_area == 'C') { $query_joins['products_memberships'] = array('on' => "{$tables['products_memberships']}.product_id = {$tables['products']}.product_id", 'is_inner' => 1); } } if ($config['Appearance']['categories_in_products'] == '1') { $fields[] = "{$tables['products_categories']}.category_id"; $query_joins['categories'] = array('parent' => 'products_categories', 'on' => "{$tables['categories']}.category_id = {$tables['products_categories']}.category_id"); $query_joins['products_categories'] = array('on' => "{$tables['products_categories']}.product_id = {$tables['products']}.product_id and {$tables['products_categories']}.main=1", 'pos' => '0', 'is_straight' => 1); } $fields[] = "{$tables['products']}.product_id"; $query = cw_db_generate_query($fields, $from_tbls, $query_joins, $where, array("{$tables['products']}.product_id"), array(), array()); $product = cw_query_first($query); # Error handling if (!$product || $current_area == 'C' && !$product['category_id'] && $config['Appearance']['categories_in_products'] == '1') { return false; } $product['system'] = cw_call('cw_product_get_system_info', array($product['product_id'])); $product['attribute_class_ids'] = cw_func_call('cw_items_attribute_classes_get', array('item_id' => $product['product_id'], 'item_type' => 'P', 'for_product_modify' => $for_product_modify)); if ($info_type & 1) { $product['membership_ids'] = cw_query_key("select membership_id from {$tables['products_memberships']} where product_id = '{$product['product_id']}'"); } # kornev, TOFIX if ($info_type & 64 && $product['variant_id'] && $addons['product_options']) { $tmp = cw_query_first("SELECT * FROM {$tables['product_variants']} WHERE variant_id = '{$product['variant_id']}'"); if (!empty($tmp)) { cw_unset($tmp, "def"); $product = cw_array_merge($product, $tmp); } else { cw_unset($product, 'variant_id'); } } if ($info_type & 128) { cw_load('image'); $product['image_thumb'] = cw_image_get('products_images_thumb', $id); } if ($info_type & 512) { $product['image_det'] = cw_image_get('products_images_det', $id); # kornev, TOFIX if (in_array($current_area, array('C', 'B')) && $product['variant_id'] && $addons['product_options']) { $var_image = cw_image_get('products_images_var', $id); if (!$var_image['is_default']) { $product['image_det'] = $var_image; } } } # TOFIX if (in_array($current_area, array('C', 'B', 'G'))) { if (!$addons['egoods']) { $product['distribution'] = ''; } $product['display_price'] = $product['price']; if ($current_area == 'C' && $info_type & 8) { $_tmp_price = $product['price']; $product['price'] = $product['list_price']; cw_get_products_taxes($product, $user_account); $product['list_price_net'] = $product['list_price']; $product['list_price'] = $product['taxed_price']; $product['price'] = $_tmp_price; } $product['taxes'] = cw_get_products_taxes($product, $user_account, false, '', $current_area == 'G' && $user_account['usertype'] != 'R'); } if (in_array($current_area, array('C', 'B'))) { $product['descr'] = cw_eol2br($product['descr']); $product['fulldescr'] = cw_eol2br($product['fulldescr']); } $product['uns_shippings'] = unserialize($product['shippings']); $product['tags'] = cw_tags_get_product_tags($id); if ($info_type & 4096 && $product['warranty_id']) { $wr = cw_get_warranty($product['warranty_id'], $lang); $product['warranties'] = $wr['body']; } // TODO: move to addon as on_product_get handler if ($info_type & 8192) { cw_load('warehouse'); if ($addons['warehouse']) { if (AREA_TYPE == 'A') { $product['avail_ordered'] = cw_warehouse_get_avail($id, 0, 'avail_ordered'); $product['avail_sold'] = cw_warehouse_get_avail($id, 0, 'avail_sold'); $product['avail_reserved'] = cw_warehouse_get_avail($id, 0, 'avail_reserved'); } elseif (AREA_TYPE == 'P') { $product['avail'] = cw_warehouse_get_warehouse_avail($customer_id, $id); $product['avail_ordered'] = cw_warehouse_get_warehouse_avail($customer_id, $id, 'avail_ordered'); } else { // TOFIX: $product['avail'] becomes different meanings when info_type & 8192 flag is raised or not // without flag - avail of all variants without products already in cart // with flag - total avail as set in admin per variant // $product['avail'] = cw_warehouse_get_avail_for_customer($id, $product['variant_id']); // $product['avails']= cw_warehouse_get_avails_customer($id); $product['avail'] = cw_warehouse_get_avail_for_customer($id, $product['variant_id']); } } else { $product['avails'] = cw_warehouse_get_avails_customer($id, $product['avail'] + $product['avail_ordered']); } } return $product; }
<?php cw_load('cart', 'taxes'); $product_info = cw_func_call('cw_product_get', array('id' => $product_id, 'user_account' => $user_account)); $agreement = cw_get_warranty($product_info['warranty_id'], $current_language); $smarty->assign('product', $product_info); $smarty->assign('agreement', $agreement); $smarty->assign('home_style', 'iframe'); $smarty->assign('current_section_dir', 'main'); $smarty->assign('main', 'popup_agrement'); if ($mode == 'pdf') { $smarty->assign('mode', $mode); cw_load('pdf'); cw_pdf_generate($config['Company']['company_name'] . ' - ' . $agreement['title'], 'customer/home.tpl'); } $location[] = array(cw_get_langvar_by_name('lbl_warranties'), '');