values['source_page'] = Tools::getvalue('source_page'); $this->values['checkAvailability'] = Tools::getvalue('checkAvailability'); $this->values['id_product'] = Tools::getvalue('id_product'); $this->values['product_attribute'] = Tools::getvalue('product_attribute'); $this->values['id_product_attribute'] = Tools::getvalue('id_product_attribute'); $this->values['quantity'] = Tools::getvalue('quantity'); $this->values['combination'] = Tools::getvalue('combination'); $this->values['getToken'] = Tools::getvalue('getToken'); $this->values['credit_card'] = 0; $this->values['short_cut'] = 1; if ($this->module->paypal_method == 'MB') { $methodType = 'EC'; } else { $methodType = $this->module->paypal_method; } $this->setMethod(AbstractMethodPaypal::load($methodType)); } public function displayAjaxCheckAvailability() { $request = $this->getRequest(); switch ($request->page) { case 'cart': if ($this->context->cart->checkQuantities() && $this->context->cart->nbProducts()) { $this->jsonValues = array('success' => true); } else { $this->jsonValues = array('success' => false); } break; case 'product': $product = new Product((int)$request->idProduct); $group = $this->parseCombination($request->combination); $product->id_product_attribute = $this->module->getIdProductAttributeByIdAttributes($request->idProduct, $group); if ($product->checkQty($request->quantity)) { $this->jsonValues = array('success' => true); } else { $this->jsonValues = array('success' => false); } break; default: } } protected function parseCombination($combination) { $temp_group = explode('|', $combination); $group = array(); foreach ($temp_group as $item) { $temp = explode(':', $item); $temp = array_map( function ($value) { return trim($value); }, $temp ); $group[$temp[0]] = $temp[1]; } return $group; } public function prepareProduct() { if (empty($this->context->cart->id)) { $this->context->cart->add(); $this->context->cookie->id_cart = $this->context->cart->id; $this->context->cookie->write(); } else { // delete all product in cart $products = $this->context->cart->getProducts(); foreach ($products as $product) { $this->context->cart->deleteProduct($product['id_product'], $product['id_product_attribute'], $product['id_customization'], $product['id_address_delivery']); } } if ($this->values['combination']) { // build group for search product attribute $group = $this->parseCombination($this->values['combination']); $this->context->cart->updateQty($this->values['quantity'], $this->values['id_product'], $this->module->getIdProductAttributeByIdAttributes($this->values['id_product'], $group)); } else { $this->context->cart->updateQty($this->values['quantity'], $this->values['id_product']); } } public function setMethod($method) { $this->method = $method; } public function displayAjaxCreateOrder() { $request = $this->getRequest(); if ($request->page == 'product') { $this->values['quantity'] = $request->quantity; $this->values['id_product'] = $request->idProduct; $this->values['combination'] = $request->combination; $this->prepareProduct(); } $this->method->setShortCut(true); $this->method->init(); $this->jsonValues = ['success' => true, 'idOrder' => $this->method->getPaymentId()]; } public function getRequest() { return json_decode(file_get_contents('php://input')); } }