function handleAdd($id_product_param, $count) { $product = ProductModel::getProductIdentifyByParam($id_product_param, $this->getPresenter()->id_lang, $this->getPresenter()->user); $item = new \ShoppingCart\Item(); $item = $this->repository->mapper->load($product); //$this->repository->deleteAll(); $this->repository->add($item, $count); $this->invalidateControl('defaultcart'); }
function handleCreateOrder() { $order_info = NEnvironment::getSession('user_order_info'); $values = $order_info['values']; // dump($values);exit; //presmerovanie ak nieco nieje v poriadku $session = NEnvironment::getSession('cart'); if (empty($session->products)) { $this->redirect('default'); } if (empty($order_info['values'])) { $this->redirect('step2'); } //znama polick login na email $values['email'] = $values['login']; $values['id_lang'] = $this->id_lang; //odstranenie loginu unset($values['login']); //odstranenie terms_and_conditions unset($values['terms_and_conditions']); //odstranenie discount_hash // $discount_hash = $values['discount_hash']; if ($values['type'] == NULL) { $values['type'] = 0; } $values['user_discount'] = 0; // ak je prihlaseny setni id_user if ($this->user->isLoggedIn()) { $values['id_user'] = $this->user->getIdentity()->data['user_id']; $values['user_discount'] = $this->user->getIdentity()->data['discount']; } $cart_info = OrderModel::getCartInfo($session->products, $order_info['values']['id_delivery'], $order_info['values']['id_payment'], $this->context, false); $values['total_price'] = $cart_info['total_sum']; $values['total_price_with_tax'] = $cart_info['total_sum_with_tax']; $values['delivery_title'] = $cart_info['delivery_title']; $values['delivery_price'] = $cart_info['delivery_price']['price']; $values['delivery_tax'] = $cart_info['delivery_price']['tax']; $values['payment_title'] = $cart_info['payment_title']; $values['payment_price'] = $cart_info['payment_price']['price']; $values['payment_tax'] = $cart_info['payment_price']['tax']; //odstranenie id_delivery unset($values['id_delivery']); //odstranenie id_payment unset($values['id_payment']); $values['rate'] = Lang::get($this->id_lang)->rate; try { $id_order = OrderModel::createOrder($values, $session->products, $this->id_lang, $this->user); $conf = $this->context->parameters; $template = $this->template; $template->setFile(APP_DIR . '/FrontModule/templates/Order/OrderEmail.phtml'); $template->discount = false; $template->o = OrderModel::get($id_order); $mail = new MyMail(); $mail->addTo($values['email']); $mail->addBcc($conf['client_email']); $mail->setSubject(_('Objednávka č. ') . $id_order); $mail->setTemplate($template); $mail->send(); if ($conf['HEUREKA']['ENABLE'] == 1) { try { $overeno = new HeurekaOvereno($conf['HEURELA']['API_KEY'], HeurekaOvereno::LANGUAGE_SK); $overeno->setEmail($values['email']); foreach ($session->products as $id_product_param => $p) { $product = ProductModel::getProductIdentifyByParam($id_product_param, $this->id_lang, $this->user); $overeno->addProduct($product->name); } $overeno->send(); } catch (Exception $e) { } } //vymazanie z kosika $session = NEnvironment::getSession('cart'); unset($session->products); //vymazanie info o uzivatelovi unset($order_info['values']); $this->redirect('Cart:success'); } catch (OrderException $e) { $form->addError($e); } }
static function getCartInfo($products, $id_delivery = false, $id_payment = false, $context, $isCache = false) { $param = array('total_sum' => 0, 'total_sum_tax' => 0, 'total_sum_with_tax' => 0, 'delivery_title' => '', 'delivery_price' => array(), 'payment_title' => '', 'payment_price' => array(), 'taxies' => array(), 'product_count' => 0, 'products' => array()); $taxies = $context->getService('Vat')->getFluent()->fetchPairs('value', 'value'); foreach ($taxies as $k => $t) { $taxies[$k] = 0; } foreach ($products as $id_product_param => $count) { $product = ProductModel::getProductIdentifyByParam($id_product_param, $context->application->presenter->id_lang, $context->user); //pripocitanie do produktu $product['sum_price'] = $product['price_array']['price'] * $count; $product['count'] = $count; //pripocitanie do celkovej ceny $param['total_sum'] += $product['price_array']['price'] * $count; //tax $taxies[$product['price_array']['tax']] += $product['price_array']['tax_price'] * $count; //spocitanie produktov $param['product_count'] += $count; $param['products'][$id_product_param] = $product; } if ($id_delivery) { $delivery = $context->getService('Delivery')->getDeliveryWithPrice($id_delivery); $param['delivery_title'] = $delivery['name']; $taxies[$delivery['price_array']['tax']] += $delivery['price_array']['tax_price']; $param['total_sum'] += $delivery['price_array']['price']; $param['delivery_price'] = $delivery['price_array']; } if ($id_payment) { $payment = $context->getService('Payment')->getDeliveryWithPrice($id_payment); $param['payment_title'] = $payment['name']; $taxies[$payment['price_array']['tax']] += $payment['price_array']['tax_price']; $param['total_sum'] += $payment['price_array']['price']; $param['payment_price'] = $payment['price_array']; } $param['taxies'] = $taxies; foreach ($taxies as $k => $tax_sum_price) { $param['total_sum_tax'] += $tax_sum_price; } $param['total_sum_with_tax'] = $param['total_sum'] + $param['total_sum_tax']; return $param; }