/** * Insert Order * * @access public * @return boolean */ public function insert_order($order_status = NULL) { //order data $data = array('customers_id' => $this->customer->get_id(), 'customers_name' => $this->customer->get_name(), 'customers_company' => '', 'customers_street_address' => '', 'customers_suburb' => '', 'customers_city' => '', 'customers_postcode' => '', 'customers_state' => '', 'customers_state_code' => '', 'customers_country_iso2' => '', 'customers_country_iso3' => '', 'customers_telephone' => '', 'customers_email_address' => $this->customer->get_email_address(), 'customers_comment' => $this->session->userdata('payment_comments'), 'customers_address_format' => '', 'customers_ip_address' => $this->input->ip_address(), 'delivery_name' => $this->shopping_cart->get_shipping_address('firstname') . ' ' . $this->shopping_cart->get_shipping_address('lastname'), 'delivery_company' => $this->shopping_cart->get_shipping_address('company'), 'delivery_street_address' => $this->shopping_cart->get_shipping_address('street_address'), 'delivery_suburb' => $this->shopping_cart->get_shipping_address('suburb'), 'delivery_city' => $this->shopping_cart->get_shipping_address('city'), 'delivery_postcode' => $this->shopping_cart->get_shipping_address('postcode'), 'delivery_state' => $this->shopping_cart->get_shipping_address('state'), 'delivery_zone_id' => $this->shopping_cart->get_shipping_address('zone_id'), 'delivery_state_code' => $this->shopping_cart->get_shipping_address('zone_code'), 'delivery_country_id' => $this->shopping_cart->get_shipping_address('country_id'), 'delivery_country' => $this->shopping_cart->get_shipping_address('country_title'), 'delivery_country_iso2' => $this->shopping_cart->get_shipping_address('country_iso_code_2'), 'delivery_country_iso3' => $this->shopping_cart->get_shipping_address('country_iso_code_3'), 'delivery_address_format' => $this->shopping_cart->get_shipping_address('format'), 'delivery_telephone' => $this->shopping_cart->get_shipping_address('telephone_number'), 'billing_name' => $this->shopping_cart->get_billing_address('firstname') . ' ' . $this->shopping_cart->get_billing_address('lastname'), 'billing_company' => $this->shopping_cart->get_billing_address('company'), 'billing_street_address' => $this->shopping_cart->get_billing_address('street_address'), 'billing_suburb' => $this->shopping_cart->get_billing_address('suburb'), 'billing_city' => $this->shopping_cart->get_billing_address('city'), 'billing_postcode' => $this->shopping_cart->get_billing_address('postcode'), 'billing_state' => $this->shopping_cart->get_billing_address('state'), 'billing_zone_id' => $this->shopping_cart->get_billing_address('zone_id'), 'billing_state_code' => $this->shopping_cart->get_billing_address('zone_code'), 'billing_country_id' => $this->shopping_cart->get_billing_address('country_id'), 'billing_country' => $this->shopping_cart->get_billing_address('country_title'), 'billing_country_iso2' => $this->shopping_cart->get_billing_address('country_iso_code_2'), 'billing_country_iso3' => $this->shopping_cart->get_billing_address('country_iso_code_3'), 'billing_address_format' => $this->shopping_cart->get_billing_address('format'), 'billing_telephone' => $this->shopping_cart->get_billing_address('telephone_number'), 'payment_method' => $this->shopping_cart->get_billing_method('title'), 'payment_module' => $this->shopping_cart->get_billing_method('id'), 'uses_store_credit' => 0, 'store_credit_amount' => 0, 'orders_status' => $order_status === NULL ? config('DEFAULT_ORDERS_STATUS_ID') : $order_status, 'currency' => $this->currencies->get_code(), 'currency_value' => $this->currencies->value($this->currencies->get_code()), 'gift_wrapping' => '0', 'wrapping_message' => ''); $this->db->insert('orders', $data); //get insert id $insert_id = $this->db->insert_id(); //insert order totals $order_totals = $this->shopping_cart->get_order_totals(); foreach ($order_totals as $total) { $data = array('orders_id' => $insert_id, 'title' => $total['title'], 'text' => $total['text'], 'value' => $total['value'], 'class' => $total['code'], 'sort_order' => $total['sort_order']); $this->db->insert('orders_total', $data); } //insert comment $data = array('orders_id' => $insert_id, 'orders_status_id' => config('DEFAULT_ORDERS_STATUS_ID'), 'customer_notified' => 0, 'comments' => $this->session->userdata('payment_comments'), 'date_added' => date('Y-m-d H:i:s', now())); $this->db->insert('orders_status_history', $data); //products $products = $this->shopping_cart->get_products(); foreach ($products as $product) { $data = array('orders_id' => $insert_id, 'products_id' => get_product_id($product['id']), 'products_type' => $product['type'], 'products_sku' => $product['sku'], 'products_name' => $product['name'], 'products_price' => $product['price'], 'final_price' => $product['final_price'], 'products_tax' => get_tax_rate($product['tax_class_id'], $this->shopping_cart->get_taxing_address('country_id'), $this->shopping_cart->get_taxing_address('zone_id')), 'products_quantity' => $product['quantity']); $this->db->insert('orders_products', $data); //variants $order_products_id = $this->db->insert_id(); if ($this->shopping_cart->has_variants($product['id'])) { foreach ($this->shopping_cart->get_variants($product['id']) as $variants_id => $variants) { $result = $this->db->select('pvg.products_variants_groups_name, pvv.products_variants_values_name')->from('products_variants pv')->join('products_variants_entries pve', 'pv.products_variants_id = pve.products_variants_id', 'inner')->join('products_variants_groups pvg', 'pve.products_variants_groups_id = pvg.products_variants_groups_id', 'inner')->join('products_variants_values pvv', 'pve.products_variants_values_id = pvv.products_variants_values_id', 'inner')->where('pv.products_id', $product['id'])->where('pve.products_variants_groups_id', $variants['groups_id'])->where('pve.products_variants_values_id', $variants['variants_values_id'])->where('pvg.language_id', lang_id())->where('pvv.language_id', lang_id())->get(); if ($result->num_rows() > 0) { $row = $result->row_array(); $data = array('orders_id' => $insert_id, 'orders_products_id' => $order_products_id, 'products_variants_groups_id' => $variants['groups_id'], 'products_variants_groups' => $row['products_variants_groups_name'], 'products_variants_values_id' => $variants['variants_values_id'], 'products_variants_values' => $row['products_variants_values_name']); $this->db->insert('orders_products_variants', $data); } } } } return $insert_id; }
} //取得product_id function get_product_id(array $category_id) { $query = 'select `product_id` from product where `product_status` != "delete" and product_category_id IN (' . implode(',', $category_id) . ') ;'; $query = query_despace($query); $result = mysql_query($query); $product_id_list = array(); while ($row = mysql_fetch_assoc($result)) { $product_id_list[] = $row['product_id']; } return !empty($product_id_list) ? $product_id_list : null; } $category_id[] = $id; //取得項目下的產品ID及刪除產品 $product_id = get_product_id($category_id); if ($product_id != null) { if (!del_product($product_id)) { json_encode_return(0, '刪除產品時發生錯誤,請重新操作。', URL_ADMIN2_ROOT . 'category/'); } if (!del_product_meta($product_id)) { json_encode_return(0, '刪除產品描述時發生錯誤,請重新操作。', URL_ADMIN2_ROOT . 'category/'); } } //刪除項目 del_category($category_id) ? json_encode_return(1, '刪除資料完成', URL_ADMIN2_ROOT . 'category/') : json_encode_return(0, '刪除失敗', URL_ADMIN2_ROOT . 'category/'); break; default: json_encode_return(0, '流程異常,請重新操作[ACT#2]'); break; }
# 记录进入日志 取消 if ($num0 <= 0) { // $docStr = implode(',',$docArr); // toLog($docStr); } # 第一优先级取出的数据不足36的时候 $num0 < 12 true if ($num0 < $needNum) { # 获取第一优先级的数据的docId $res1_0_1 = array(); # 储存第一优先级的文章id,用于排重 foreach ($res1_0 as $key => $value) { $unArr[] = $key; $res1_0_1[] = $key; } # 得到一个文章关联的产品id $proIdArr = get_product_id($docArr); #var_dump($proIdArr);exit('128_1'); # 没有proId则使用“看了又看” $proId if ($proIdArr) { # 返回形如array(0=>5255718,1=>5255719...) $docArr1_1 = get_docid_by_proid($proIdArr, $needNum - $num0, $unArr); //var_dump($docArr1_1);exit(); # 通过proId获得了文章id if (is_array($docArr1_1)) { # 第一优先级和第二优先级的规则的数据合并 $docArr1_1 = array_merge($res1_0_1, $docArr1_1); } else { $docArr1_1 = $res1_0_1; } //var_dump($docArr1_1);exit('144_1'); // array(0=>5255718,...) # 用于排重
function set_product($upc, $sid, $description, $brand, $upc, $sku, $wholesale_price, $retail_price) { global $link; $pid = get_product_id($upc, $sid); if (empty($pid)) { $data = array('created_at' => '2014-11-11 11:11:11', 'is_archived' => 0, 'is_processed' => 0, 'is_tracked' => 1, 'is_violated' => 0, 'price_floor' => 0, 'retail_price' => $retail_price, 'sku' => $sku, 'status' => 1, 'store_id' => $sid, 'title' => $description, 'upc_code' => $upc, 'wholesale_price' => $wholesale_price); $pid = dbinsert($link, 'products', $data); if (!$pid) { var_dump($pid); exit; } } return $pid; }
/** * Synchronize shopping cart contents with database * * @access public * @return boolean */ function synchronize_with_database() { //if customer is not logged on if (!$this->ci->customer->is_logged_on()) { return FALSE; } // insert current cart contents in database if ($this->has_contents()) { foreach ($this->contents as $products_id_string => $data) { $basket = $this->ci->shopping_cart_model->get_content($this->ci->customer->get_id(), $products_id_string); if ($basket !== NULL) { $this->ci->shopping_cart_model->update_content($this->ci->customer->get_id(), $products_id_string, $data['quantity'] + $basket['customers_basket_quantity']); } else { $this->ci->shopping_cart_model->insert_content($this->ci->customer->get_id(), $products_id_string, $data['quantity'], $data['final_price']); } } } // reset per-session cart contents, but not the database contents $this->reset(); // synchronize content $products = $this->ci->shopping_cart_model->get_contents($this->ci->customer->get_id()); if ($products != NULL) { foreach ($products as $data) { $products_id = $data['products_id']; $variants = parse_variants_from_id_string($products_id); $quantity = $data['customers_basket_quantity']; $product = load_product_library($products_id); if ($product->is_valid()) { $this->contents[$products_id] = array('id' => $products_id, 'name' => $product->get_title(), 'type' => $product->get_product_type(), 'keyword' => $product->get_keyword(), 'sku' => $product->get_sku($variants), 'image' => $product->get_image(), 'price' => $product->get_price($variants, $quantity), 'final_price' => $product->get_price($variants, $quantity), 'quantity' => $quantity > $product->get_quantity($products_id) ? $product->get_quantity($products_id) : $quantity, 'weight' => $product->get_weight($variants), 'tax_class_id' => $product->get_tax_class_id(), 'date_added' => get_date_short($data['customers_basket_date_added']), 'weight_class_id' => $product->get_weight_class()); //set in stock status $this->contents[$products_id]['in_stock'] = $this->is_in_stock($products_id); if ($variants !== NULL) { foreach ($variants as $group_id => $value_id) { $data = $this->ci->shopping_cart_model->get_variants_data(get_product_id($products_id), $group_id, $value_id); if ($data !== NULL) { $this->contents[$products_id]['variants'][$group_id] = array('groups_id' => $group_id, 'variants_values_id' => $value_id, 'groups_name' => $data['products_variants_groups_name'], 'values_name' => $data['products_variants_values_name']); } } } } } } $this->clean_up(); $this->calculate(); }
?> "> <img alt="<?php echo $product['name']; ?> " title="<?php echo $product['name']; ?> " src="<?php echo product_image_url($product['image'], 'mini'); ?> " alt="default thumb" class="thumb" /> </a> <div class="info"> <a class="name" href="<?php echo site_url('product/' . get_product_id($product['id'])); ?> "><?php echo $product['name']; ?> </a> <span class="sku"><?php echo lang('field_sku') . ' ' . $product['sku']; ?> </span> <?php if (config('STOCK_CHECK') == '1' && $product['in_stock'] === FALSE) { ?> <span class="markProductOutOfStock"><?php echo config('STOCK_MARK_PRODUCT_OUT_OF_STOCK'); ?>
function load_product_library($products_id) { $id = get_product_id($products_id); //get products id part and omit the variants part //get ci instance $CI =& get_instance(); //load library $CI->load->library('product', $products_id, 'product_' . $products_id); //return the object return $CI->{'product_' . $products_id}; }