public function hookheader($params) { //Change context Shop to be default if ($this->isVersionOneDotFive() && Shop::isFeatureActive()) { $oldContextShop = $this->getContextShop(); $this->setContextShop(); } //End of change // Check if the module is configured if (!Configuration::get('EBAY_PAYPAL_EMAIL')) { return false; } // Fix hook update product attribute $this->hookupdateProductAttributeEbay(); // init date to check from if (Configuration::get('EBAY_INSTALL_DATE') < date('Y-m-d', strtotime('-30 days')) . 'T' . date('H:i:s', strtotime('-30 days'))) { //If it is more than 30 days that we installed the module $dateToCheckFrom = Configuration::get('EBAY_ORDER_LAST_UPDATE'); $dateToCheckFromArray = explode('T', $dateToCheckFrom); $dateToCheckFrom = date("Y-m-d", strtotime($dateToCheckFromArray[0] . " -30 day")); $dateToCheckFrom .= 'T' . $dateToCheckFromArray[1]; } else { //If it is less than 30 days that we installed the module $dateToCheckFrom = Configuration::get('EBAY_INSTALL_DATE'); $dateToCheckFromArray = explode('T', $dateToCheckFrom); $dateToCheckFrom = date("Y-m-d", strtotime($dateToCheckFromArray[0] . " -1 day")); $dateToCheckFrom .= 'T' . $dateToCheckFromArray[1]; } if (Configuration::get('EBAY_ORDER_LAST_UPDATE') < date('Y-m-d', strtotime('-30 minutes')) . 'T' . date('H:i:s', strtotime('-30 minutes')) . '.000Z') { $dateNew = date('Y-m-d') . 'T' . date('H:i:s') . '.000Z'; $this->setConfiguration('EBAY_ORDER_LAST_UPDATE', $dateNew); // eBay Request $ebay = new eBayRequest(); $page = 1; $orderList = array(); $orderCount = 0; $orderCountTmp = 100; while ($orderCountTmp == 100 && $page < 10) { $orderListTmp = $ebay->getOrders($dateToCheckFrom, $dateNew, $page); $orderCountTmp = count($orderListTmp); $orderList = array_merge((array) $orderList, (array) $orderListTmp); $orderCount += $orderCountTmp; $page++; } // Lock if ($orderList) { foreach ($orderList as $korder => $order) { if ($order['status'] == 'Complete' && $order['amount'] > 0.1 && isset($order['product_list']) && count($order['product_list'])) { if (!Db::getInstance()->getValue('SELECT `id_ebay_order` FROM `' . _DB_PREFIX_ . 'ebay_order` WHERE `id_order_ref` = \'' . pSQL($order['id_order_ref']) . '\'')) { // Check for empty name $order['firstname'] = trim($order['firstname']); $order['familyname'] = trim($order['familyname']); if (empty($order['familyname'])) { $order['familyname'] = $order['firstname']; } if (empty($order['firstname'])) { $order['firstname'] = $order['familyname']; } if (empty($order['phone']) || !Validate::isPhoneNumber($order['phone'])) { $order['phone'] = '0100000000'; } if (Validate::isEmail($order['email']) && !empty($order['firstname']) && !empty($order['familyname'])) { // Getting the customer $id_customer = (int) Db::getInstance()->getValue('SELECT `id_customer` FROM `' . _DB_PREFIX_ . 'customer` WHERE `active` = 1 AND `email` = \'' . pSQL($order['email']) . '\' AND `deleted` = 0' . (substr(_PS_VERSION_, 0, 3) == '1.3' ? '' : ' AND `is_guest` = 0')); // Add customer if he doesn't exist if ($id_customer < 1) { $customer = new Customer(); $customer->id_gender = 0; $customer->id_default_group = 1; $customer->secure_key = md5(uniqid(rand(), true)); $customer->email = $order['email']; $customer->passwd = md5(pSQL(_COOKIE_KEY_ . rand())); $customer->last_passwd_gen = pSQL(date('Y-m-d H:i:s')); $customer->newsletter = 0; $customer->lastname = pSQL($order['familyname']); $customer->firstname = pSQL($order['firstname']); $customer->active = 1; $customer->add(); $id_customer = $customer->id; } // Search if address exists $id_address = (int) Db::getInstance()->getValue('SELECT `id_address` FROM `' . _DB_PREFIX_ . 'address` WHERE `id_customer` = ' . (int) $id_customer . ' AND `alias` = \'eBay\''); if ($id_address > 0) { $address = new Address((int) $id_address); } else { $address = new Address(); $address->id_customer = (int) $id_customer; } $address->id_country = (int) Country::getByIso($order['country_iso_code']); $address->alias = 'eBay'; $address->lastname = pSQL($order['familyname']); $address->firstname = pSQL($order['firstname']); $address->address1 = pSQL($order['address1']); $address->address2 = pSQL($order['address2']); $address->postcode = pSQL($order['postalcode']); $address->city = pSQL($order['city']); $address->phone = pSQL($order['phone']); $address->active = 1; if ($id_address > 0 && Validate::isLoadedObject($address)) { $address->update(); } else { $address->add(); } $id_address = $address->id; $flag = 1; foreach ($order['product_list'] as $product) { if ((int) $product['id_product'] < 1 || !Db::getInstance()->getValue('SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product` WHERE `id_product` = ' . (int) $product['id_product'])) { $flag = 0; } if (isset($product['id_product_attribute']) && $product['id_product_attribute'] > 0 && !Db::getInstance()->getValue('SELECT `id_product_attribute` FROM `' . _DB_PREFIX_ . 'product_attribute` WHERE `id_product` = ' . (int) $product['id_product'] . ' AND `id_product_attribute` = ' . (int) $product['id_product_attribute'])) { $flag = 0; } } if ($flag == 1) { //Create a Cart for the order $cartNbProducts = 0; $cartAdd = new Cart(); Context::getContext()->customer = new Customer($id_customer); $cartAdd->id_customer = $id_customer; $cartAdd->id_address_invoice = $id_address; $cartAdd->id_address_delivery = $id_address; $cartAdd->id_carrier = 0; $cartAdd->id_lang = $this->id_lang; $cartAdd->id_currency = Currency::getIdByIsoCode('EUR'); $cartAdd->recyclable = 0; $cartAdd->gift = 0; $cartAdd->add(); $id_lang = (int) Configuration::get('PS_LANG_DEFAULT'); foreach ($order['product_list'] as $product) { $prod = new Product($product['id_product'], false, $id_lang); // Qty of product or attribute if (isset($product['id_product_attribute']) && !empty($product['id_product_attribute'])) { $minimalQty = (int) Attribute::getAttributeMinimalQty($product['id_product_attribute']); } else { $minimalQty = $prod->minimal_quantity; } if ($product['quantity'] >= $minimalQty) { if ($this->isVersionOneDotFive()) { $update = $cartAdd->updateQty((int) $product['quantity'], (int) $product['id_product'], isset($product['id_product_attribute']) && $product['id_product_attribute'] > 0 ? $product['id_product_attribute'] : NULL, false, 'up', 0, new Shop(Configuration::get('PS_SHOP_DEFAULT'))); if ($update === TRUE) { $cartNbProducts++; } } elseif ($cartAdd->updateQty((int) $product['quantity'], (int) $product['id_product'], isset($product['id_product_attribute']) && $product['id_product_attribute'] > 0 ? $product['id_product_attribute'] : NULL)) { $cartNbProducts++; } } else { $templateVars = array('{name_product}' => $prod->name, '{min_qty}' => $minimalQty, '{cart_qty}' => $product['quantity']); Mail::Send((int) Configuration::get('PS_LANG_DEFAULT'), 'alertEbay', Mail::l('Product quantity', $id_lang), $templateVars, strval(Configuration::get('PS_SHOP_EMAIL')), NULL, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__) . '/mails/'); } } $cartAdd->update(); // Check number of products in the cart and check if order has already been taken if ($cartNbProducts > 0 && !Db::getInstance()->getValue('SELECT `id_ebay_order` FROM `' . _DB_PREFIX_ . 'ebay_order` WHERE `id_order_ref` = \'' . pSQL($order['id_order_ref']) . '\'')) { // Fix on sending e-mail Db::getInstance()->autoExecute(_DB_PREFIX_ . 'customer', array('email' => 'NOSEND-EBAY'), 'UPDATE', '`id_customer` = ' . (int) $id_customer); $customerClear = new Customer(); if (method_exists($customerClear, 'clearCache')) { $customerClear->clearCache(true); } $paiement = new eBayPayment(); // Validate order if ($this->isVersionOneDotFive()) { $customer = new Customer($id_customer); $paiement->validateOrder(intval($cartAdd->id), Configuration::get('PS_OS_PAYMENT'), floatval($cartAdd->getOrderTotal(true, 3)), 'eBay ' . $order['payment_method'] . ' ' . $order['id_order_seller'], NULL, array(), intval($cartAdd->id_currency), false, $customer->secure_key, new Shop(Configuration::get('PS_SHOP_DEFAULT'))); } else { $customer = new Customer($id_customer); $paiement->validateOrder(intval($cartAdd->id), Configuration::get('PS_OS_PAYMENT'), floatval($cartAdd->getOrderTotal(true, 3)), 'eBay ' . $order['payment_method'] . ' ' . $order['id_order_seller'], NULL, array(), intval($cartAdd->id_currency), false, $customer->secure_key); } $id_order = $paiement->currentOrder; // Fix on date Db::getInstance()->autoExecute(_DB_PREFIX_ . 'orders', array('date_add' => pSQL($order['date_add'])), 'UPDATE', '`id_order` = ' . (int) $id_order); // Fix on sending e-mail Db::getInstance()->autoExecute(_DB_PREFIX_ . 'customer', array('email' => pSQL($order['email'])), 'UPDATE', '`id_customer` = ' . (int) $id_customer); // Update price (because of possibility of price impact) foreach ($order['product_list'] as $product) { $tax_rate = Db::getInstance()->getValue('SELECT `tax_rate` FROM `' . _DB_PREFIX_ . 'order_detail` WHERE `id_order` = ' . (int) $id_order . ' AND `product_id` = ' . (int) $product['id_product'] . ' AND `product_attribute_id` = ' . (int) $product['id_product_attribute']); Db::getInstance()->autoExecute(_DB_PREFIX_ . 'order_detail', array('product_price' => floatval($product['price'] / (1 + $tax_rate / 100)), 'reduction_percent' => 0), 'UPDATE', '`id_order` = ' . (int) $id_order . ' AND `product_id` = ' . (int) $product['id_product'] . ' AND `product_attribute_id` = ' . (int) $product['id_product_attribute']); } $updateOrder = array('total_paid' => floatval($order['amount']), 'total_paid_real' => floatval($order['amount']), 'total_products' => floatval(Db::getInstance()->getValue('SELECT SUM(`product_price`) FROM `' . _DB_PREFIX_ . 'order_detail` WHERE `id_order` = ' . (int) $id_order)), 'total_products_wt' => floatval($order['amount'] - $order['shippingServiceCost']), 'total_shipping' => floatval($order['shippingServiceCost'])); Db::getInstance()->autoExecute(_DB_PREFIX_ . 'orders', $updateOrder, 'UPDATE', '`id_order` = ' . (int) $id_order); // Register the ebay order ref Db::getInstance()->autoExecute(_DB_PREFIX_ . 'ebay_order', array('id_order_ref' => pSQL($order['id_order_ref']), 'id_order' => (int) $id_order), 'INSERT'); if (!$this->isVersionOneDotFive()) { //Fix on eBay not updating $params = array(); foreach ($order['product_list'] as $product) { $params['product'] = new Product((int) $product['id_product']); $this->hookaddproduct($params); } } } else { $cartAdd->delete(); $orderList[$korder]['errors'][] = $this->l('Could not add product to cart (maybe your stock quantity is 0)'); } } else { $orderList[$korder]['errors'][] = $this->l('Could not found products in database'); } } else { $orderList[$korder]['errors'][] = $this->l('Invalid e-mail'); } } else { $orderList[$korder]['errors'][] = $this->l('Order already imported'); } } else { $orderList[$korder]['errors'][] = $this->l('Status not complete or amount less than 0.1 or no product matching'); } } file_put_contents(dirname(__FILE__) . '/log/orders.php', "<?php\n\n" . '$dateLastImport = ' . "'" . date('d/m/Y H:i:s') . "';\n\n" . '$orderList = ' . var_export($orderList, true) . ";\n\n"); } } // Set old Context Shop if ($this->isVersionOneDotFive() && Shop::isFeatureActive()) { $this->setContextShop($oldContextShop); } }
public function postProcess() { $order_id = $_POST['ORDERID']; $res_code = $_POST['RESPCODE']; $res_desc = $_POST['RESPMSG']; $checksum_recv = $_POST['CHECKSUMHASH']; $paramList = $_POST; //var_dump($paramList); $secret_key = Configuration::get('PayTM_SECRET_KEY'); $order_amount = $_POST['TXNAMOUNT']; $bool = "FALSE"; $bool = verifychecksum_e($paramList, $secret_key, $checksum_recv); /*if(isset($DR)){ $DR = preg_replace("/\s/","+",$DR); $rc4 = new Crypt_RC4($secret_key); $QueryString = base64_decode($DR); $rc4->decrypt($QueryString); $QueryString = explode('&',$QueryString); $response = array(); foreach($QueryString as $param){ $param = explode('=',$param); $response[$param[0]] = urldecode($param[1]); array(8) { ["RESPCODE"]=> string(3) "141" ["RESPMSG"]=> string(26) "Cancel Request by Customer" ["STATUS"]=> string(11) "TXN_FAILURE" ["MID"]=> string(20) "pebble49164290093828" ["TXNAMOUNT"]=> string(3) "199" ["ORDERID"]=> string(4) "1105" ["TXNID"]=> string(4) "9051" ["CHECKSUMHASH"]=> string(108) "8JTqSis+Uqe2iVMo/vWLgjFQkay2pZQkoN/uUVaBbkZrwkYEZMXIKfKy9NfYd2Fk9JaHiemzwNVpfRJrqiWzyeDWxZSJBhCi5NBEaTdbcZA=" } } }*/ $cartID = $order_id; $extras = array(); $extras['transaction_id'] = $_POST['TXNID']; $cart = new Cart(intval($cartID)); $amount = $cart->getOrderTotal(true, Cart::BOTH); $responseMsg = $_POST['RESPMSG']; if ($bool == "TRUE") { if ($res_code == "01") { $status_code = "Ok"; $message = "Transaction Successful"; // $status = "15" ; $status = Configuration::get('Paytm_ID_ORDER_SUCCESS'); } else { if ($res_code == "141") { $responseMsg = "Transaction Cancelled. "; $message = "Transaction Cancelled"; $status = "6"; } else { $responseMsg = "Transaction Failed. "; $message = "Transaction Failed"; $status = Configuration::get('Paytm_ID_ORDER_FAILED'); } } } else { $status_code = "Failed"; $responseMsg = "Security Error ..!"; $status = Configuration::get('Paytm_ID_ORDER_FAILED'); } $history_message = $responseMsg . '. Paytm Payment ID: ' . $_POST['TXNID']; $obj = new Paytm(); $obj->validateOrder(intval($cart->id), $status, $order_amount, $obj->displayName, $history_message, $extras, '', false, $cart->secure_key); $this->context->smarty->assign(array('status' => $status_code, 'responseMsg' => $message, 'this_path' => $this->module->getPathUri(), 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->module->name . '/')); $cart_qties == 0; $cart->delete(); $this->setTemplate('payment_response.tpl'); }
public static function addOrder($uid = 0, $username = '', $pay_name = '货到付款', $default_address_id = 0) { if ($uid) { //从购物车里获取到商品列表 $cart_goods_list = Cart::select($uid); if ($cart_goods_list) { //计算订单总金额 $order_total_data = self::getOrderTotal($cart_goods_list); $total = $order_total_data['total']; //运费 $shipping_fee = self::getOrderShippingFee($total); //优惠 $bonus = 0; //使用优惠券... //收货地址 $address_info = UserAddress::getAddrByAddressId($uid, $default_address_id); if (!$address_info) { $address_info = UserAddress::getDefaultAddress($uid); } $data['sn'] = self::createOrderSn(); //订单号 $data['uid'] = $uid; //用户id $data['username'] = $username; //用户名 $data['order_status'] = 'yes'; //订单有效 $data['consignee'] = $address_info['consignee']; //联系人 $data['province'] = $address_info['province']; //省 $data['city'] = $address_info['city']; //市 $data['district'] = $address_info['district']; //区 $data['address'] = $address_info['address']; //详细地址 $data['mobile'] = $address_info['mobile']; //手机或电话 $data['shipping_fee'] = $shipping_fee; //运费 $data['bonus'] = $bonus; //优惠 $data['order_money'] = $total; //货物总金额 $data['money_paid'] = $total + $shipping_fee + $bonus; //应付款金额 $data['pay_name'] = $pay_name; //付款方式 //非货到付款操作 if ($pay_name !== '货到付款') { $data['pay_time'] = time(); //支付时间 $data['confirm_status'] = 'yes'; //确认订单状态(非货到付款自动确认) $data['confirm_time'] = time(); //确认订单时间 } $rs = OrderInfo::addOrder($data); if ($rs) { //下单成功,减少库存 AdminGoodsM::minusStock($cart_goods_list); //添加到订单商品表 OrderGoodsInfo::addGoods($rs, $cart_goods_list); //删除购物车里面的商品信息 $where = self::_where($uid); Cart::delete($where); } //下单成功 return $rs; } } //下单失败 return false; }
public static function getCarriersByCountry($id_country, $id_state, $zipcode, $exiting_cart, $id_customer) { // Create temporary Address $addr_temp = new Address(); $addr_temp->id_customer = $id_customer; $addr_temp->id_country = $id_country; $addr_temp->id_state = $id_state; $addr_temp->postcode = $zipcode; // Populate required attributes // Note: Some carrier needs the whole address // the '.' will do the job $addr_temp->firstname = "."; $addr_temp->lastname = "."; $addr_temp->address1 = "."; $addr_temp->city = "."; $addr_temp->alias = "TEMPORARY_ADDRESS_TO_DELETE"; $addr_temp->save(); $cart = new Cart(); $cart->id_currency = $exiting_cart->id_currency; $cart->id_customer = $exiting_cart->id_customer; $cart->id_lang = $exiting_cart->id_lang; $cart->id_address_delivery = $addr_temp->id; $cart->add(); $products = $exiting_cart->getProducts(); foreach ($products as $key => $product) { $cart->updateQty($product['quantity'], $product['id_product'], $product['id_product_attribute']); } $carriers = $cart->simulateCarriersOutput(null, true); //delete temporary objects $addr_temp->delete(); $cart->delete(); return $carriers; }
public function delcartone($cart_id) { $uid = LuS::get('uid'); if ($cart_id) { $where['uid'] = $uid; $where['cart_id'] = $cart_id; Cart::delete($where); $cart_goods_list = Cart::select($uid); $data = Cart::getOrderTotal($cart_goods_list); $total = $data['total']; //总金额 $num = $data['num']; //总件数 $shipping_fee = Cart::getOrderShippingFee($total); echo json_encode(array('1', $total, $shipping_fee, $num)); } throw new Exception('exit'); }
public function hookbackOfficeTop($params) { // Check if the module is configured if (!Configuration::get('EBAY_PAYPAL_EMAIL')) { return false; } // If no update yet if (!Configuration::get('EBAY_ORDER_LAST_UPDATE')) { Configuration::updateValue('EBAY_ORDER_LAST_UPDATE', date('Y-m-d') . 'T' . date('H:i:s') . '.000Z'); } // init Var $dateNew = date('Y-m-d') . 'T' . date('H:i:s') . '.000Z'; if (Configuration::get('EBAY_ORDER_LAST_UPDATE') < date('Y-m-d', strtotime('-30 minutes')) . 'T' . date('H:i:s', strtotime('-30 minutes')) . '.000Z') { // Lock Configuration::updateValue('EBAY_ORDER_LAST_UPDATE', $dateNew); // eBay Request $ebay = new eBayRequest(); $page = 1; $orderList = array(); $orderCount = 0; $orderCountTmp = 100; while ($orderCountTmp == 100 && $page < 10) { $orderListTmp = $ebay->getOrders(date('Y-m-d', strtotime('-30 days')) . 'T' . date('H:i:s', strtotime('-30 days')) . '.000Z', $dateNew, $page); $orderCountTmp = count($orderListTmp); $orderList = array_merge((array) $orderList, (array) $orderListTmp); $orderCount += $orderCountTmp; $page++; } if ($orderList) { foreach ($orderList as $korder => $order) { if ($order['status'] == 'Complete' && $order['amount'] > 0.1 && isset($order['product_list']) && count($order['product_list'])) { if (!Db::getInstance()->getValue('SELECT `id_ebay_order` FROM `' . _DB_PREFIX_ . 'ebay_order` WHERE `id_order_ref` = \'' . pSQL($order['id_order_ref']) . '\'')) { $id_customer = (int) Db::getInstance()->getValue('SELECT `id_customer` FROM `' . _DB_PREFIX_ . 'customer` WHERE `active` = 1 AND `email` = \'' . pSQL($order['email']) . '\' AND `deleted` = 0' . (substr(_PS_VERSION_, 0, 3) == '1.3' ? '' : ' AND `is_guest` = 0')); // Check for empty name $order['firstname'] = trim($order['firstname']); $order['familyname'] = trim($order['familyname']); if (empty($order['familyname'])) { $order['familyname'] = $order['firstname']; } if (empty($order['firstname'])) { $order['firstname'] = $order['familyname']; } if (empty($order['phone']) || !Validate::isPhoneNumber($order['phone'])) { $order['phone'] = '0100000000'; } if (Validate::isEmail($order['email']) && !empty($order['firstname']) && !empty($order['familyname'])) { // Add customer if he doesn't exist if ($id_customer < 1) { $customer = new Customer(); $customer->id_gender = 9; $customer->id_default_group = 1; $customer->secure_key = md5(uniqid(rand(), true)); $customer->email = $order['email']; $customer->passwd = md5(pSQL(_COOKIE_KEY_ . rand())); $customer->last_passwd_gen = pSQL(date('Y-m-d H:i:s')); $customer->newsletter = 0; $customer->lastname = pSQL($order['familyname']); $customer->firstname = pSQL($order['firstname']); $customer->active = 1; $customer->add(); $id_customer = $customer->id; } // Search if address exists $id_address = (int) Db::getInstance()->getValue('SELECT `id_address` FROM `' . _DB_PREFIX_ . 'address` WHERE `id_customer` = ' . (int) $id_customer . ' AND `alias` = \'eBay\''); if ($id_address > 0) { $address = new Address((int) $id_address); } else { $address = new Address(); $address->id_customer = (int) $id_customer; } $address->id_country = (int) Country::getByIso($order['country_iso_code']); $address->alias = 'eBay'; $address->lastname = pSQL($order['familyname']); $address->firstname = pSQL($order['firstname']); $address->address1 = pSQL($order['address1']); $address->address2 = pSQL($order['address2']); $address->postcode = pSQL($order['postalcode']); $address->city = pSQL($order['city']); $address->phone = pSQL($order['phone']); $address->active = 1; if ($id_address > 0 && Validate::isLoadedObject($address)) { $address->update(); } else { $address->add(); } $id_address = $address->id; $flag = 1; foreach ($order['product_list'] as $product) { if ((int) $product['id_product'] < 1 || !Db::getInstance()->getValue('SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product` WHERE `id_product` = ' . (int) $product['id_product'])) { $flag = 0; } if (isset($product['id_product_attribute']) && $product['id_product_attribute'] > 0 && !Db::getInstance()->getValue('SELECT `id_product_attribute` FROM `' . _DB_PREFIX_ . 'product_attribute` WHERE `id_product` = ' . (int) $product['id_product'] . ' AND `id_product_attribute` = ' . (int) $product['id_product_attribute'])) { $flag = 0; } } if ($flag == 1) { $cartNbProducts = 0; $cartAdd = new Cart(); $cartAdd->id_customer = $id_customer; $cartAdd->id_address_invoice = $id_address; $cartAdd->id_address_delivery = $id_address; $cartAdd->id_carrier = 1; $cartAdd->id_lang = $this->id_lang; $cartAdd->id_currency = Currency::getIdByIsoCode('EUR'); $cartAdd->recyclable = 0; $cartAdd->gift = 0; $cartAdd->add(); foreach ($order['product_list'] as $product) { if ($cartAdd->updateQty((int) $product['quantity'], (int) $product['id_product'], isset($product['id_product_attribute']) && $product['id_product_attribute'] > 0 ? $product['id_product_attribute'] : NULL)) { $cartNbProducts++; } } $cartAdd->update(); // Check number of products in the cart if ($cartNbProducts > 0) { // Fix on sending e-mail Db::getInstance()->autoExecute(_DB_PREFIX_ . 'customer', array('email' => 'NOSEND-EBAY'), 'UPDATE', '`id_customer` = ' . (int) $id_customer); $customerClear = new Customer(); if (method_exists($customerClear, 'clearCache')) { $customerClear->clearCache(true); } // Validate order $paiement = new eBayPayment(); $paiement->validateOrder(intval($cartAdd->id), Configuration::get('PS_OS_PAYMENT'), floatval($cartAdd->getOrderTotal(true, 3)), 'eBay ' . $order['payment_method'] . ' ' . $order['id_order_seller'], NULL, array(), intval($cartAdd->id_currency)); $id_order = $paiement->currentOrder; // Fix on date Db::getInstance()->autoExecute(_DB_PREFIX_ . 'orders', array('date_add' => pSQL($order['date_add'])), 'UPDATE', '`id_order` = ' . (int) $id_order); // Fix on sending e-mail Db::getInstance()->autoExecute(_DB_PREFIX_ . 'customer', array('email' => pSQL($order['email'])), 'UPDATE', '`id_customer` = ' . (int) $id_customer); // Update price (because of possibility of price impact) $updateOrder = array('total_paid' => floatval($order['amount']), 'total_paid_real' => floatval($order['amount']), 'total_products' => floatval($order['amount']), 'total_products_wt' => floatval($order['amount']), 'total_shipping' => floatval($order['shippingServiceCost'])); Db::getInstance()->autoExecute(_DB_PREFIX_ . 'orders', $updateOrder, 'UPDATE', '`id_order` = ' . (int) $id_order); foreach ($order['product_list'] as $product) { Db::getInstance()->autoExecute(_DB_PREFIX_ . 'order_detail', array('product_price' => floatval($product['price']), 'tax_rate' => 0, 'reduction_percent' => 0), 'UPDATE', '`id_order` = ' . (int) $id_order . ' AND `product_id` = ' . (int) $product['id_product'] . ' AND `product_attribute_id` = ' . (int) $product['id_product_attribute']); } // Register the ebay order ref Db::getInstance()->autoExecute(_DB_PREFIX_ . 'ebay_order', array('id_order_ref' => pSQL($order['id_order_ref']), 'id_order' => (int) $id_order), 'INSERT'); } else { $cartAdd->delete(); $orderList[$korder]['errors'][] = $this->l('Could not add product to cart (maybe your stock quantity is 0)'); } } else { $orderList[$korder]['errors'][] = $this->l('Could not found products in database'); } } else { $orderList[$korder]['errors'][] = $this->l('Invalid e-mail'); } } else { $orderList[$korder]['errors'][] = $this->l('Order already imported'); } } else { $orderList[$korder]['errors'][] = $this->l('Status not complete or amount less than 0.1 or no product matching'); } } file_put_contents(dirname(__FILE__) . '/log/orders.php', "<?php\n\n" . '$dateLastImport = ' . "'" . date('d/m/Y H:i:s') . "';\n\n" . '$orderList = ' . var_export($orderList, true) . ";\n\n"); } } }
//Display cart content. require_once 'model/cart.php'; require_once 'view/cart.php'; $cart = new Cart($user->userName, $session); if (!$_POST) { if ($cart->getCid()) { $cartPanel = new cartView($cart); $cartPanel->addBn(); } else { return $boxMsg[] = "You have no items in your carts."; } } } else { return $boxMsg[] = "Please login first."; } // Check if there is user input. if (isset($_POST["submitQty"])) { $cart->getCid(); $cart->input($_POST["productId"], $_POST["cartQtyBox"]); if ($cart->getDifferences() === false) { return $boxMsg[] = "Please change the amount before clicking on the submit button."; } else { if ($_POST["cartQtyBox"] === 0) { return $boxMsg[] = $cart->delete(); // deletes the sku from cart completely. } else { return $boxMsg[] = $cart->add(); // while the name is "add", it really indicate changes to amount that don't delete sku from cart. } } }
$app->on('GET /api/cart', function () { $cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : []; $this->json($cart); }); $app->on('POST /api/cart', function () { $cart = new Cart(); $a = $cart->add($this->body); $this->json($a); }); $app->on('PUT /api/cart/:?/:?', function ($productid, $action) { $cart = new Cart(); $a = $cart->update($productid, $action); $this->json($a); }); $app->on('DELETE /api/cart/:?', function ($productid) { $cart = new Cart(); $a = $cart->delete($productid); $this->json($a); }); // CHECKOUT API // ================ $app->on('GET /api/checkout', function () { $checkout = new Checkout(); $a = $checkout->summary(); $this->json($a); }); $app->on('POST /api/checkout', function () { $checkout = new Checkout(); $a = $checkout->validate($this->body); $this->json($a); });