* @copyright 2007-2018 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ include_once _PS_MODULE_DIR_.'paypal/classes/AbstractMethodPaypal.php'; class PaypalEcScInitModuleFrontController extends ModuleFrontController { public $name = 'paypal'; public function postProcess() { if (Tools::getValue('checkAvailability')) { $product = new Product(Tools::getValue('id_product')); $product->id_product_attribute = Tools::getValue('product_attribute') != 0 ? Tools::getValue('product_attribute') : Tools::getValue('id_product_attribute'); if ($product->checkQty(Tools::getValue('quantity'))) { die(Tools::jsonEncode(1)); } else { die(Tools::jsonEncode(0)); } } $method_ec = AbstractMethodPaypal::load('EC'); 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 (Tools::getValue('combination')) { // build group for search product attribute $temp_group = explode('|', Tools::getValue('combination')); $group = array(); foreach ($temp_group as $item) { $temp = explode(':', $item); $group[$temp[0]] = $temp[1]; } $this->context->cart->updateQty(Tools::getValue('quantity'), Tools::getValue('id_product'), Product::getIdProductAttributesByIdAttributes(Tools::getValue('id_product'), $group)); } else { $this->context->cart->updateQty(Tools::getValue('quantity'), Tools::getValue('id_product')); } $response = $method_ec->init(array( 'use_card'=>0, 'short_cut' => 1 )); if (!isset($response['L_ERRORCODE0'])) { if (Tools::getvalue('getToken')) { die($method_ec->token); } Tools::redirect($response); } else { Tools::redirect(Context::getContext()->link->getModuleLink('paypal', 'error', array('error_code' => $response['L_ERRORCODE0']))); } } }