/** * @param $data */ protected function addService($data) { $item = $this->cart_model->getById($data['parent_id']); if (!$item) { $this->errors = _w('Error'); return; } unset($item['id']); $item['parent_id'] = $data['parent_id']; $item['type'] = 'service'; $item['service_id'] = $data['service_id']; if (isset($data['service_variant_id'])) { $item['service_variant_id'] = $data['service_variant_id']; } else { $service_model = new shopServiceModel(); $service = $service_model->getById($data['service_id']); $item['service_variant_id'] = $service['variant_id']; } $id = $this->cart->addItem($item); $total = $this->cart->total(); $discount = $this->cart->discount(); $this->response['id'] = $id; $this->response['total'] = $this->currencyFormat($total); $this->response['count'] = $this->cart->count(); $this->response['discount'] = $this->currencyFormat($discount); $item_total = $this->cart->getItemTotal($data['parent_id']); $this->response['item_total'] = $this->currencyFormat($item_total); if (shopAffiliate::isEnabled()) { $add_affiliate_bonus = shopAffiliate::calculateBonus(array('total' => $total, 'discount' => $discount, 'items' => $this->cart->items(false))); $this->response['add_affiliate_bonus'] = sprintf(_w("This order will add +%s points to your affiliate bonus."), round($add_affiliate_bonus, 2)); } }
public function execute() { $cart = new shopCart(); $item_id = waRequest::post('id'); $cart_items_model = new shopCartItemsModel(); $item = $cart_items_model->getById($item_id); $is_html = waRequest::request('html'); if ($q = waRequest::post('quantity', 0, 'int')) { if (!wa()->getSetting('ignore_stock_count')) { if ($item['type'] == 'product') { $product_model = new shopProductModel(); $p = $product_model->getById($item['product_id']); $sku_model = new shopProductSkusModel(); $sku = $sku_model->getById($item['sku_id']); // check quantity if ($sku['count'] !== null && $q > $sku['count']) { $q = $sku['count']; $name = $p['name'] . ($sku['name'] ? ' (' . $sku['name'] . ')' : ''); $this->response['error'] = sprintf(_w('Only %d pcs of %s are available, and you already have all of them in your shopping cart.'), $q, $name); $this->response['q'] = $q; } } } $cart->setQuantity($item_id, $q); $this->response['item_total'] = $is_html ? shop_currency_html($cart->getItemTotal($item_id), true) : shop_currency($cart->getItemTotal($item_id), true); } elseif ($v = waRequest::post('service_variant_id')) { $cart->setServiceVariantId($item_id, $v); $this->response['item_total'] = $is_html ? shop_currency_html($cart->getItemTotal($item['parent_id']), true) : shop_currency($cart->getItemTotal($item['parent_id']), true); } $total = $cart->total(); $discount = $cart->discount(); $this->response['total'] = $is_html ? shop_currency_html($total, true) : shop_currency($total, true); $this->response['discount'] = $is_html ? shop_currency_html($discount, true) : shop_currency($discount, true); $this->response['discount_numeric'] = $discount; $this->response['count'] = $cart->count(); if (shopAffiliate::isEnabled()) { $add_affiliate_bonus = shopAffiliate::calculateBonus(array('total' => $total, 'discount' => $discount, 'items' => $cart->items(false))); $this->response['add_affiliate_bonus'] = sprintf(_w("This order will add +%s points to your affiliate bonus."), round($add_affiliate_bonus, 2)); } }
public function execute() { $id = waRequest::post('id'); $cart = new shopCart(); $is_html = waRequest::request('html'); if ($id) { $item = $cart->deleteItem($id); if ($item && !empty($item['parent_id'])) { $item_total = $cart->getItemTotal($item['parent_id']); $this->response['item_total'] = $is_html ? shop_currency_html($item_total, true) : shop_currency($item_total, true); } } $total = $cart->total(); $discount = $cart->discount(); $this->response['total'] = $is_html ? shop_currency_html($total, true) : shop_currency($total, true); $this->response['discount'] = $is_html ? shop_currency_html($discount, true) : shop_currency($discount, true); $this->response['count'] = $cart->count(); if (shopAffiliate::isEnabled()) { $add_affiliate_bonus = shopAffiliate::calculateBonus(array('total' => $total, 'discount' => $discount, 'items' => $cart->items(false))); $this->response['add_affiliate_bonus'] = sprintf(_w("This order will add +%s points to your affiliate bonus."), round($add_affiliate_bonus, 2)); } }