public function addCart($data) { // get data post $product_id = $data['product_id']; $colors = $data['colors']; $print = $data['print']; $quantity = $data['quantity']; // get attribute if (isset($data['attribute'])) { $attribute = $data['attribute']; } else { $attribute = false; } if ($quantity < 1) { $quantity = 1; } $time = strtotime("now"); if (isset($data['cliparts'])) { $cliparts = $data['cliparts']; } else { $cliparts = false; } $content = array(); $content['error'] = 1; // load product $products = $this->getProducts(); $product = false; for ($i = 0; $i < count($products); $i++) { if ($product_id == $products[$i]->id) { $product = $products[$i]; break; } } if ($product === false) { $content['msg'] = 'Product could not be found'; } else { $content['error'] = 0; // load cart include_once ROOT . DS . 'includes' . DS . 'cart.php'; $cart = new dgCart(); $post = array('colors' => $colors, 'print' => $print, 'attribute' => $attribute, 'quantity' => $quantity, 'product_id' => $product_id); // load setting $setting = $this->getSetting(); $result = $cart->totalPrice($product, $post, $setting); $result->product = new stdClass(); $result->product->name = $product->title; $result->product->sku = $product->sku; // get cliparts $clipartsPrice = array(); $result->cliparts = $clipartsPrice; $total = new stdClass(); //$total->old = $result->price->base + $result->price->colors + $result->price->prints; $total->old = $result->price->colors + $result->price->prints; //$total->sale = $result->price->sale + $result->price->colors + $result->price->prints; $total->sale = $result->price->colors + $result->price->prints; if (count($result->cliparts)) { foreach ($result->cliparts as $view => $art) { foreach ($art as $id => $amount) { $total->old = $total->old + $amount; $total->sale = $total->sale + $amount; } } } $result->total = $total; // get symbol if (!isset($setting->currency_symbol)) { $setting->currency_symbol = '$'; } $result->symbol = $setting->currency_symbol; // save file image design $path = $this->folder(); $design = array(); $design['images'] = array(); if (isset($data['design']['images']['front'])) { $design['images']['front'] = $this->createFile($data['design']['images']['front'], $path, 'cart-front-' . $time); } if (isset($data['design']['images']['back'])) { $design['images']['back'] = $this->createFile($data['design']['images']['back'], $path, 'cart-back-' . $time); } if (isset($data['design']['images']['left'])) { $design['images']['left'] = $this->createFile($data['design']['images']['left'], $path, 'cart-left-' . $time); } if (isset($data['design']['images']['right'])) { $design['images']['right'] = $this->createFile($data['design']['images']['right'], $path, 'cart-right-' . $time); } if (empty($result->options)) { $result->options = array(); } if (isset($data['teams'])) { $teams = $data['teams']; } else { $teams = ''; } // add cart $item = array('id' => $result->product->sku, 'product_id' => $data['product_id'], 'qty' => $data['quantity'], 'teams' => $teams, 'price' => $result->total->sale, 'prices' => json_encode($result->price), 'cliparts' => json_encode($result->cliparts), 'symbol' => $result->symbol, 'customPrice' => $result->price->attribute, 'name' => $result->product->name, 'time' => $time, 'options' => json_decode(json_encode($result->options), true)); $rowid = md5($result->product->sku . $time); $cache = $this->cache('cart'); $designs = array('color' => $data['colors'][key($data['colors'])], 'images' => $design['images'], 'vector' => $data['design']['vectors'], 'fonts' => $data['fonts'], 'item' => $item); $cache->set($rowid, $designs); $content['product'] = array('rowid' => $rowid, 'price' => $result->total->sale, 'quantity' => $data['quantity'], 'color_hex' => $data['colors'][key($data['colors'])], 'color_title' => $product->design->color_title[key($data['colors'])], 'images' => json_encode($design['images']), 'teams' => $teams, 'options' => json_encode($result->options)); } return $content; }
public function prices() { $data = $this->input->post(); // get data post $product_id = $data['product_id']; $colors = $data['colors']; $print = $data['print']; $quantity = $data['quantity']; // get attribute if (isset($data['attribute'])) { $attribute = $data['attribute']; } else { $attribute = false; } if ($quantity < 1) { $quantity = 1; } // load product $this->load->model('product_m'); $options = array('id' => $product_id); $product = $this->product_m->getProduct($options); if ($product == false) { echo json_encode(array('error' => 'Product could not be found')); exit; } else { // load cart $this->load->helper('cart'); $cart = new dgCart(); $post = array('colors' => $colors, 'print' => $print, 'attribute' => $attribute, 'quantity' => $quantity, 'product_id' => $product_id); // load setting $this->load->model('settings_m'); $row = $this->settings_m->getSetting(); $setting = json_decode($row->settings); $result = $cart->totalPrice($this->product_m, $product[0], $post, $setting); // get cliparts $clipartsPrice = array(); /* if ( isset($data['cliparts']) ) { $this->load->model('art_m'); $cliparts = $data['cliparts']; foreach($cliparts as $view => $arts) { if (count($arts)) { $art = array(); foreach($arts as $art_id) { // check admin shop and desginer $clipart = $this->art_m->getArt($art_id, 'system, add_price'); if ( empty($clipart[0]) ) continue; if ($clipart[0]->add_price == 0) continue; $prices = $clipart[0]->add_price; $art[$art_id] = $prices; } $clipartsPrice[$view] = $art; } } } */ $result->cliparts = $clipartsPrice; $result->quantity = $quantity; $total = new stdClass(); $total->old = $result->price->base + $result->price->colors + $result->price->prints; $total->sale = $result->price->sale + $result->price->colors + $result->price->prints; if (count($result->cliparts)) { foreach ($result->cliparts as $view => $art) { foreach ($art as $id => $amount) { $total->old = $total->old + $amount; $total->sale = $total->sale + $amount; } } } $total->old = $total->old * $quantity + $result->price->attribute; $total->sale = $total->sale * $quantity + $result->price->attribute; $total->old = number_format($total->old, 2, '.', ','); $total->sale = number_format($total->sale, 2, '.', ','); echo json_encode($total); exit; } }