/** * Default Function * * @access public * @param $id products id * @param $variants variants * @return void */ public function index($id, $variants = NULL) { if (is_numeric($id)) { $product = load_product_library($id); //if product is found if ($product->is_valid()) { if ($variants === NULL) { $variants = $this->input->post('variants'); } else { $variants = parse_variants_string($variants); } //quantity $quantity = $this->input->post('quantity'); //add to shopping cart $this->shopping_cart->add($id, $variants, $quantity); } } //redirect to shopping cart redirect('shopping_cart'); }
/** * Default Function * * @access public * @return string contains the html content of categories module */ public function index() { $ids = $this->ci->compare_products->get_products(); if (is_array($ids) && !empty($ids)) { $products = array(); foreach ($ids as $products_id) { $product = load_product_library($products_id); $products[] = array('products_id' => $products_id, 'products_name' => $product->get_title()); } return $this->load_view('index.php', array('products' => $products)); } }
<?php } ?> </div> <div class="tab-pane <?php echo $tab == 'accessories' ? 'active' : ''; ?> " id="tab-accessories"> <?php if (is_array($accessories)) { ?> <ul class="products-list grid clearfix"> <?php foreach ($accessories as $accessory) { $product = load_product_library($accessory['accessories_id']); ?> <li class="clearfix"> <div class="left"> <a href="<?php echo site_url('product/' . $product->get_id()); ?> "> <img alt="<?php echo $product->get_title(); ?> " title="<?php echo $product->get_title(); ?> " src="<?php echo product_image_url($product->get_image());
/** * Synchronize with database * * @access public * @return void */ public function synchronize_with_database() { if (!$this->ci->customer->is_logged_on()) { return; } $this->customers_id = $this->ci->customer->get_id(); //get wishlist $data = $this->ci->wishlist_model->get_wishlist_by_customers_id($this->customers_id); if ($data !== NULL) { $products = $this->ci->wishlist_model->get_wishlist_products($this->wishlists_id); if (is_array($products) && !empty($products)) { //delete temp wishlist $temp_wishlists_id = $this->wishlists_id; $contents = $this->contents; //reset wishlist $this->reset(); //assign wishlists data $this->wishlists_id = $data['wishlists_id']; $this->token = $data['wishlists_token']; //assign products foreach ($products as $products_id) { $product = load_product_library($products_id); if ($product->is_valid()) { $this->contents[$products_id] = array('products_id' => $products_id, 'name' => $product->get_title(), 'image' => $product->get_image(), 'price' => $product->get_price(), 'date_added' => get_date_short(get_date_now()), 'variants' => array(), 'comments' => ''); } else { //remove invalid products id from database $this->ci->wishlist_model->delete_product($this->wishlists_id, $products_id); } } //merge current wishlists foreach ($contents as $products_id => $content) { $this->add_product($products_id); } //remove temp wishlists $this->ci->wishlist_model->delete_product($temp_wishlists_id); //remove temp wishlists $this->ci->wishlist_model->delete_wishlist($temp_wishlists_id); //save session $this->save_session(); } } else { if ($this->has_wishlist_id()) { //regenerate token $token = $this->generate_token(); //update model $this->ci->wishlist_model->update_wishlist($this->wishlists_id, $this->customers_id, $token); //save session $this->save_session(); } } }
/** * Check if product is in stock * * @access public * @param $products_id_string * @return boolean */ function is_in_stock($products_id_string) { $product = load_product_library($products_id_string); if ($product->get_quantity($products_id_string) - $this->contents[$products_id_string]['quantity'] >= 0) { return TRUE; } elseif ($this->products_in_stock === TRUE) { $this->products_in_stock = FALSE; } return FALSE; }
/** * Output compare products table * * @access public * @return string */ function output_compare_products_table() { $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(); if ($this->has_contents()) { $cols = array('<col width="20%">'); $col_width = round(80 / count($this->get_products())); foreach ($this->get_products() as $products_id) { $cols[] = '<col width="' . $col_width . '%">'; $product = load_product_library($products_id); $images = $product->get_images(); $product_title = $product->get_title(); $product_price = $product->get_price_formated(true); $product_weight = $product->get_weight(); $product_sku = $product->get_sku(); $image = is_array($images) ? $images[0]['image'] : $images; $products_titles[] = $product_title; if (!empty($product_price)) { $products_price[] = $product_price; } if (!empty($product_weight)) { $products_weight[] = ''; //$osC_Weight->display($product_weight, $product->get_weightClass()); } if (!empty($product_sku)) { $products_sku[] = $product_sku; } $manufacturer = $product->get_manufacturer(); if (!empty($manufacturer)) { $products_manufacturers[] = $manufacturer; } $description = $product->get_description(); if (!empty($description)) { $products_desciptions[] = $description; } $products_id = str_replace('#', '_', $products_id); $products_images[] = '<div class="image"> <a href="' . site_url('product/' . $products_id) . '" title="' . $product->get_title() . '"> <img alt="' . $product->get_title() . '" src="' . product_image_url($image) . '" /> </a> </div>' . '<a class="btn btn-mini" href="' . site_url('cart_add/' . $products_id) . '">' . lang('button_add_to_cart') . '</a>'; } $content .= '<table id="compareProducts" cellspacing="0" cellpadding="2" border="0" class="table-striped table-bordered">'; //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 (!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 (!empty($products_titles)) { $content .= '<tr class="' . $row_class . '">' . '<th valign="top">' . lang('field_products_name') . '</th>'; foreach ($products_titles as $k => $product_title) { $content .= '<td' . ($k == count($products_titles) - 1 ? ' class="last"' : '') . ' valign="top">' . $product_title . '</td>'; } $content .= '</tr>'; $row_class = $row_class == 'even' ? 'odd' : 'even'; } //add product price if (!empty($products_price)) { $content .= '<tr class="' . $row_class . '">' . '<th>' . lang('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 (!empty($products_weight)) { $content .= '<tr class="' . $row_class . '">' . '<th>' . lang('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 (!empty($products_sku)) { $content .= '<tr class="' . $row_class . '">' . '<th>' . lang('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 (!empty($products_manufacturers)) { $content .= '<tr class="' . $row_class . '">' . '<th>' . lang('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 //add product description if (!empty($products_desciptions)) { $content .= '<tr class="' . $row_class . ' last">' . '<th valign="top">' . lang('field_products_description') . '</th>'; foreach ($products_desciptions as $k => $product_description) { $content .= '<td' . ($k == count($products_desciptions) - 1 ? ' class="last"' : '') . ' valign="top">' . $product_description . '</td>'; } $content .= '</tr>'; $row_class = $row_class == 'even' ? 'odd' : 'even'; } $content .= '</tbody>'; $content .= '</table>'; } return $content; }
/** * Display wishlist * * @access public * @return void */ public function display($token = NULL) { if ($token !== NULL) { $contents = $this->wishlist->get_products_by_token($token); $products = array(); if ($contents != NULL) { foreach ($contents as $content) { $product = load_product_library($content['products_id']); if ($product->is_valid()) { $products[] = array('products_id' => $content['products_id'], 'name' => $product->get_title(), 'image' => $product->get_image(), 'price' => $product->get_price(), 'date_added' => get_date_short($content['date_added']), 'variants' => array(), 'comments' => $content['comments']); } } } } $this->template->build('account/display_wishlist', array('products' => $products)); }