public function getCustomer($user, $pass) { $id_customer = (int) Db::getInstance()->getValue(' SELECT `id_customer` FROM `' . _DB_PREFIX_ . 'customer` WHERE `active` AND `email` = \'' . pSQL($user) . '\' AND `passwd` = \'' . Tools::encrypt($pass) . '\' AND `deleted` = 0 ' . (version_compare(_PS_VERSION_, '1.4.1.0', '>=') ? ' AND `is_guest` = 0' : '')); if (!$id_customer) { throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_WRONG_USERNAME_OR_PASSWORD, 'Username or password is incorrect'); } $customer = new Customer($id_customer); $gender = array(1 => 'm', 2 => 'f', 9 => null); $shopgateCustomer = new ShopgateCustomer(); $shopgateCustomer->setCustomerId($customer->id); $shopgateCustomer->setCustomerNumber($customer->id); $shopgateCustomer->setCustomerGroup(Db::getInstance()->getValue('SELECT `name` FROM `' . _DB_PREFIX_ . 'group_lang` WHERE `id_group`=\'' . $customer->id_default_group . '\' AND `id_lang`=' . $this->id_lang)); $shopgateCustomer->setCustomerGroupId($customer->id_default_group); $shopgateCustomer->setFirstName($customer->firstname); $shopgateCustomer->setLastName($customer->lastname); $shopgateCustomer->setGender(isset($gender[$customer->id_gender]) ? $gender[$customer->id_gender] : null); $shopgateCustomer->setBirthday($customer->birthday); $shopgateCustomer->setMail($customer->email); $shopgateCustomer->setNewsletterSubscription($customer->newsletter); $addresses = array(); foreach ($customer->getAddresses($this->id_lang) as $a) { $address = new ShopgateAddress(); $address->setId($a['id_address']); $address->setFirstName($a['firstname']); $address->setLastName($a['lastname']); $address->setCompany($a['company']); $address->setStreet1($a['address1']); $address->setStreet2($a['address2']); $address->setCity($a['city']); $address->setZipcode($a['postcode']); $address->setCountry($a['country']); $address->setState($a['state']); $address->setPhone($a['phone']); $address->setMobile($a['phone_mobile']); array_push($addresses, $address); } $shopgateCustomer->setAddresses($addresses); return $shopgateCustomer; }
public function customerImport() { $customer_exist = false; $this->receiveTab(); $handle = $this->openCsvFile(); AdminImportController::setLocale(); for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) { if (Tools::getValue('convert')) { $line = $this->utf8EncodeArray($line); } $info = AdminImportController::getMaskedRow($line); AdminImportController::setDefaultValues($info); if (array_key_exists('id', $info) && (int) $info['id'] && Customer::customerIdExistsStatic((int) $info['id'])) { $customer = new Customer((int) $info['id']); $current_id_customer = $customer->id; $current_id_shop = $customer->id_shop; $current_id_shop_group = $customer->id_shop_group; $customer_exist = true; $customer_groups = $customer->getGroups(); $addresses = $customer->getAddresses((int) Configuration::get('PS_LANG_DEFAULT')); foreach ($customer_groups as $key => $group) { if ($group == $customer->id_default_group) { unset($customer_groups[$key]); } } } else { $customer = new Customer(); } AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $customer); if ($customer->passwd) { $customer->passwd = Tools::encrypt($customer->passwd); } $id_shop_list = explode($this->multiple_value_separator, $customer->id_shop); $customers_shop = array(); $customers_shop['shared'] = array(); $default_shop = new Shop((int) Configuration::get('PS_SHOP_DEFAULT')); if (Shop::isFeatureActive() && $id_shop_list) { foreach ($id_shop_list as $id_shop) { $shop = new Shop((int) $id_shop); $group_shop = $shop->getGroup(); if ($group_shop->share_customer) { if (!in_array($group_shop->id, $customers_shop['shared'])) { $customers_shop['shared'][(int) $id_shop] = $group_shop->id; } } else { $customers_shop[(int) $id_shop] = $group_shop->id; } } } else { $default_shop = new Shop((int) Configuration::get('PS_SHOP_DEFAULT')); $default_shop->getGroup(); $customers_shop[$default_shop->id] = $default_shop->getGroup()->id; } //set temporally for validate field $customer->id_shop = $default_shop->id; $customer->id_shop_group = $default_shop->getGroup()->id; $res = true; if (($field_error = $customer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $customer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { foreach ($customers_shop as $id_shop => $id_group) { if ($id_shop == 'shared') { foreach ($id_group as $key => $id) { $customer->id_shop = (int) $key; $customer->id_shop_group = (int) $id; if ($customer_exist && ($current_id_shop_group == $id || in_array($current_id_shop, ShopGroup::getShopsFromGroup($id)))) { $customer->id = $current_id_customer; $res &= $customer->update(); } else { unset($customer->id); $res &= $customer->add(); if (isset($customer_groups)) { $customer->addGroups($customer_groups); } if (isset($addresses)) { foreach ($addresses as $address) { $address['id_customer'] = $customer->id; unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']); Db::getInstance()->insert('address', $address); } } } } } else { $customer->id_shop = $id_shop; $customer->id_shop_group = $id_group; if ($customer_exist && $id_shop == $current_id_shop) { $customer->id = $current_id_customer; $res &= $customer->update(); } else { unset($customer->id); $res &= $customer->add(); if (isset($customer_groups)) { $customer->addGroups($customer_groups); } if (isset($addresses)) { foreach ($addresses as $address) { $address['id_customer'] = $customer->id; unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']); Db::getInstance()->insert('address', $address); } } } } } } $customer_exist = false; if (!$res) { $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $info['email'], isset($info['id']) ? $info['id'] : 'null'); $this->errors[] = ($field_error !== true ? $field_error : '') . ($lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } $this->closeCsvFile($handle); }
public function ajaxProcessChangePaymentMethod() { $id_customer = Tools::getValue('id_customer'); $customer = new Customer(Tools::getValue('id_customer')); $this->context->customer = $customer; //by webkul code to add id_customer in cart table $this->context->customer = new Customer($id_customer); if ($id_customer) { // setting data in the cart set from book now page by webkul $this->context->cart = new Cart(Tools::getValue('id_cart')); $this->context->cart->id_customer = $id_customer; /*if (Validate::isLoadedObject($this->context->cart) && $this->context->cart->OrderExists()) return;*/ if (!$this->context->cart->secure_key) { $this->context->cart->secure_key = $this->context->customer->secure_key; } if (!$this->context->cart->id_shop) { $this->context->cart->id_shop = (int) $this->context->shop->id; } if (!$this->context->cart->id_lang) { $this->context->cart->id_lang = ($id_lang = (int) Tools::getValue('id_lang')) ? $id_lang : Configuration::get('PS_LANG_DEFAULT'); } if (!$this->context->cart->id_currency) { $this->context->cart->id_currency = ($id_currency = (int) Tools::getValue('id_currency')) ? $id_currency : Configuration::get('PS_CURRENCY_DEFAULT'); } $addresses = $customer->getAddresses((int) $this->context->cart->id_lang); if (!$this->context->cart->id_address_invoice && isset($addresses[0])) { $this->context->cart->id_address_invoice = (int) $addresses[0]['id_address']; } elseif ($id_address_invoice) { $this->context->cart->id_address_invoice = (int) $id_address_invoice; } if (!$this->context->cart->id_address_delivery && isset($addresses[0])) { $this->context->cart->id_address_delivery = $addresses[0]['id_address']; } $this->context->cart->save(); } //end $modules = Module::getAuthorizedModules($customer->id_default_group); $authorized_modules = array(); if (!Validate::isLoadedObject($customer) || !is_array($modules)) { die(Tools::jsonEncode(array('result' => false))); } foreach ($modules as $module) { $authorized_modules[] = (int) $module['id_module']; } $payment_modules = array(); foreach (PaymentModule::getInstalledPaymentModules() as $p_module) { if (in_array((int) $p_module['id_module'], $authorized_modules)) { $payment_modules[] = Module::getInstanceById((int) $p_module['id_module']); } } $this->context->smarty->assign(array('payment_modules' => $payment_modules)); die(Tools::jsonEncode(array('result' => true, 'view' => $this->createTemplate('_select_payment.tpl')->fetch()))); }
$customer_isnew = 1; if (Agile_Logging == 'on') { $paypal->log_message("tmppass:"******"email:" . $customer->email); } try { Mail::Send(intval($oldcart->id_lang), 'account', 'Welcome!', array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => $tmppass), $customer->email, $customer->firstname . ' ' . $customer->lastname); } catch (Exception $e) { if (Agile_Logging == 'on') { $paypal->log_message('error at sending email:' . $e->getMessage()); } } } $addresses = $customer->getAddresses($oldcart->id_lang); if ($findid = $paypal->findExistingAddress($addresses)) { $address = new Address($findid); } else { $address = new Address(); $address->id = 0; $address->id_customer = $customer->id; $address->address1 = $_POST['address_street']; $address->city = $_POST['address_city']; if (empty($address->city)) { $address->city = "Unknown"; } $address->postcode = utf8_encode($_POST['address_zip']); $address->phone = isset($_POST['contact_phone']) ? utf8_encode($_POST['contact_phone']) : ""; $address->id_country = Country::getByIso($_POST['address_country_code']); $theCountry = new Country($address->id_country);
/** * When the customer is back from PayPal after filling his/her credit card info or credentials, this function is preparing the order * PayPal is providing us with the customer info (E-mail address, billing address) and we are trying to find a matching customer in the Shop database. * If no customer is found, we create a new one and we simulate a logged customer session. * Eventually it will redirect the customer to the "Shipping" step/page of the order process */ private function _expressCheckout() { /* We need to double-check that the token provided by PayPal is the one expected */ $result = $this->paypal_usa->postToPayPal('GetExpressCheckoutDetails', '&TOKEN=' . urlencode(Tools::getValue('token'))); if ((strtoupper($result['ACK']) == 'SUCCESS' || strtoupper($result['ACK']) == 'SUCCESSWITHWARNING') && $result['TOKEN'] == Tools::getValue('token') && $result['PAYERID'] == Tools::getValue('PayerID')) { /* Checks if a customer already exists for this e-mail address */ if (Validate::isEmail($result['EMAIL'])) { $customer = new Customer(); $customer->getByEmail($result['EMAIL']); } /* If the customer does not exist yet, create a new one */ if (!Validate::isLoadedObject($customer)) { $customer = new Customer(); $customer->email = $result['EMAIL']; $customer->firstname = $result['FIRSTNAME']; $customer->lastname = $result['LASTNAME']; $customer->passwd = Tools::encrypt(Tools::passwdGen()); $customer->add(); } /* Look for an existing PayPal address for this customer */ $addresses = $customer->getAddresses((int) Configuration::get('PS_LANG_DEFAULT')); foreach ($addresses as $address) { if ($address['alias'] == 'PayPal') { $id_address = (int) $address['id_address']; break; } } /* Create or update a PayPal address for this customer */ $address = new Address(isset($id_address) ? (int) $id_address : 0); $address->id_customer = (int) $customer->id; $address->id_country = (int) Country::getByIso($result['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE']); $address->id_state = (int) State::getIdByIso($result['PAYMENTREQUEST_0_SHIPTOSTATE'], (int) $address->id_country); $address->alias = 'PayPal'; $address->lastname = substr($result['PAYMENTREQUEST_0_SHIPTONAME'], 0, strpos($result['PAYMENTREQUEST_0_SHIPTONAME'], ' ')); $address->firstname = substr($result['PAYMENTREQUEST_0_SHIPTONAME'], strpos($result['PAYMENTREQUEST_0_SHIPTONAME'], ' '), strlen($result['PAYMENTREQUEST_0_SHIPTONAME']) - strlen($address->lastname)); $address->address1 = $result['PAYMENTREQUEST_0_SHIPTOSTREET']; if ($result['PAYMENTREQUEST_0_SHIPTOSTREET2'] != '') { $address->address2 = $result['PAYMENTREQUEST_0_SHIPTOSTREET2']; } $address->city = $result['PAYMENTREQUEST_0_SHIPTOCITY']; $address->postcode = $result['PAYMENTREQUEST_0_SHIPTOZIP']; $address->save(); /* Update the cart billing and delivery addresses */ $this->context->cart->id_address_delivery = (int) $address->id; $this->context->cart->id_address_invoice = (int) $address->id; $this->context->cart->update(); /* Update the customer cookie to simulate a logged-in session */ $this->context->cookie->id_customer = (int) $customer->id; $this->context->cookie->customer_lastname = $customer->lastname; $this->context->cookie->customer_firstname = $customer->firstname; $this->context->cookie->passwd = $customer->passwd; $this->context->cookie->email = $customer->email; $this->context->cookie->is_guest = $customer->isGuest(); $this->context->cookie->logged = 1; /* Save the Payer ID and Checkout token for later use (during the payment step/page) */ $this->context->cookie->paypal_express_checkout_token = $result['TOKEN']; $this->context->cookie->paypal_express_checkout_payer_id = $result['PAYERID']; if (_PS_VERSION_ < '1.5') { Module::hookExec('authentication'); } else { Hook::exec('authentication'); } /* Redirect the use to the "Shipping" step/page of the order process */ Tools::redirectLink($this->context->link->getPageLink('order.php', false, null, array('step' => '3'))); exit; } else { foreach ($result as $key => $val) { $result[$key] = urldecode($val); } $this->context->smarty->assign('paypal_usa_errors', $result); $this->setTemplate('express-checkout-messages.tpl'); } }
public function hookAdminOrder($params) { $shipment = new DpdGroupShipment((int) $params['id_order']); if (Tools::isSubmit('printLabels')) { $pdf_file_contents = $shipment->getLabelsPdf(); if ($pdf_file_contents) { ob_end_clean(); header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="shipment_labels_' . (int) Tools::getValue('id_order') . '.pdf"'); echo $pdf_file_contents; } else { $this->addFlashError(reset(DpdGroupShipment::$errors)); Tools::redirectAdmin(self::getAdminOrderLink() . '&id_order=' . (int) $params['id_order']); } } $this->displayFlashMessagesIfIsset(); $order = new Order((int) $params['id_order']); $customer = new Customer($order->id_customer); $products = $shipment->getParcelsSetUp($order->getProductsDetail()); if ($shipment->parcels) { DpdGroupParcel::addParcelDataToProducts($products, $order->id); } $id_method = self::getMethodIdByCarrierId($order->id_carrier); DpdGroupWS::$parcel_weight_warning_message = false; $price = $shipment->calculatePriceForOrder((int) $id_method, $order->id_address_delivery, $products); $carrier = new Carrier((int) $order->id_carrier, $order->id_lang); $ws_shipping_price = $price !== false ? $price : '---'; $total_shipping = version_compare(_PS_VERSION_, '1.5', '>=') ? $order->total_shipping_tax_incl : $order->total_shipping; $this->context->smarty->assign(array('order' => $order, 'module_link' => $this->getModuleLink('AdminModules'), 'settings' => new DpdGroupConfiguration(), 'total_weight' => DpdGroupShipment::convertWeight($order->getTotalWeight()), 'shipment' => $shipment, 'selected_shipping_method_id' => $id_method, 'ws_shippingPrice' => $price !== false ? $price : '---', 'products' => $products, 'customer_addresses' => $customer->getAddresses($this->context->language->id), 'carrier_url' => $carrier->url, 'order_link' => self::getAdminOrderLink() . '&id_order=' . (int) Tools::getValue('id_order'), 'errors' => $this->getErrorMessagesForOrderPage(), 'warnings' => $this->getWarningMessagesForOrderPage($shipment->id_shipment, $id_method, $ws_shipping_price, $total_shipping), 'force_enable_button' => DpdGroupWS::$parcel_weight_warning_message, 'display_product_weight_warning' => $this->orderProductsWithoutWeight($products))); if (!$this->ps_14) { $this->context->controller->addJS(_DPDGROUP_JS_URI_ . 'jquery.bpopup.min.js'); $this->context->controller->addJS(_DPDGROUP_JS_URI_ . 'adminOrder.js'); $css_filename = $this->bootstrap ? 'adminOrder_16' : 'adminOrder'; $this->context->controller->addCSS(_DPDGROUP_CSS_URI_ . $css_filename . '.css'); } $this->setGlobalVariablesForAjax(); $template_filename = $this->bootstrap ? 'adminOrder_16' : 'adminOrder'; return $this->context->smarty->fetch(_DPDGROUP_TPL_DIR_ . 'hook/' . $template_filename . '.tpl'); }
public function renderView() { $order = new Order(Tools::getValue('id_order')); if (!Validate::isLoadedObject($order)) { $this->errors[] = Tools::displayError('The order cannot be found within your database.'); } $customer = new Customer($order->id_customer); $carrier = new Carrier($order->id_carrier); $products = $this->getProducts($order); $order_details = AphOrderDetail::getList($order->id); foreach ($order_details as &$order_detail) { $products[$order_detail['id_order_detail']]['delivery_date'] = $order_detail['delivery_date']; $products[$order_detail['id_order_detail']]['delivery_time_from'] = $order_detail['delivery_time_from']; $products[$order_detail['id_order_detail']]['delivery_time_to'] = $order_detail['delivery_time_to']; } $currency = new Currency((int) $order->id_currency); // Carrier module call $carrier_module_call = null; if ($carrier->is_module) { $module = Module::getInstanceByName($carrier->external_module_name); if (method_exists($module, 'displayInfoByCart')) { $carrier_module_call = call_user_func(array($module, 'displayInfoByCart'), $order->id_cart); } } // Retrieve addresses information $addressInvoice = new Address($order->id_address_invoice, $this->context->language->id); if (Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state) { $invoiceState = new State((int) $addressInvoice->id_state); } if ($order->id_address_invoice == $order->id_address_delivery) { $addressDelivery = $addressInvoice; if (isset($invoiceState)) { $deliveryState = $invoiceState; } } else { $addressDelivery = new Address($order->id_address_delivery, $this->context->language->id); if (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state) { $deliveryState = new State((int) $addressDelivery->id_state); } } $this->toolbar_title = sprintf($this->l('Order #%1$d (%2$s) - %3$s %4$s'), $order->id, $order->reference, $customer->firstname, $customer->lastname); if (Shop::isFeatureActive()) { $shop = new Shop((int) $order->id_shop); $this->toolbar_title .= ' - ' . sprintf($this->l('Shop: %s'), $shop->name); } // gets warehouses to ship products, if and only if advanced stock management is activated $warehouse_list = null; $order_details = $order->getOrderDetailList(); foreach ($order_details as $order_detail) { $product = new Product($order_detail['product_id']); if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management) { $warehouses = Warehouse::getWarehousesByProductId($order_detail['product_id'], $order_detail['product_attribute_id']); foreach ($warehouses as $warehouse) { if (!isset($warehouse_list[$warehouse['id_warehouse']])) { $warehouse_list[$warehouse['id_warehouse']] = $warehouse; } } } } $payment_methods = array(); foreach (PaymentModule::getInstalledPaymentModules() as $payment) { $module = Module::getInstanceByName($payment['name']); if (Validate::isLoadedObject($module) && $module->active) { $payment_methods[] = $module->displayName; } } // display warning if there are products out of stock $display_out_of_stock_warning = false; $current_order_state = $order->getCurrentOrderState(); if (Configuration::get('PS_STOCK_MANAGEMENT') && (!Validate::isLoadedObject($current_order_state) || $current_order_state->delivery != 1 && $current_order_state->shipped != 1)) { $display_out_of_stock_warning = true; } // products current stock (from stock_available) foreach ($products as &$product) { // Get total customized quantity for current product $customized_product_quantity = 0; if (is_array($product['customizedDatas'])) { foreach ($product['customizedDatas'] as $customizationPerAddress) { foreach ($customizationPerAddress as $customizationId => $customization) { $customized_product_quantity += (int) $customization['quantity']; } } } $product['customized_product_quantity'] = $customized_product_quantity; $product['current_stock'] = StockAvailable::getQuantityAvailableByProduct($product['product_id'], $product['product_attribute_id'], $product['id_shop']); $resume = OrderSlip::getProductSlipResume($product['id_order_detail']); $product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity']; $product['amount_refundable'] = $product['total_price_tax_excl'] - $resume['amount_tax_excl']; $product['amount_refundable_tax_incl'] = $product['total_price_tax_incl'] - $resume['amount_tax_incl']; $product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl'], $currency); $product['refund_history'] = OrderSlip::getProductSlipDetail($product['id_order_detail']); $product['return_history'] = OrderReturn::getProductReturnDetail($product['id_order_detail']); // if the current stock requires a warning if ($product['current_stock'] <= 0 && $display_out_of_stock_warning) { $this->displayWarning($this->l('This product is out of stock: ') . ' ' . $product['product_name']); } if ($product['id_warehouse'] != 0) { $warehouse = new Warehouse((int) $product['id_warehouse']); $product['warehouse_name'] = $warehouse->name; $warehouse_location = WarehouseProductLocation::getProductLocation($product['product_id'], $product['product_attribute_id'], $product['id_warehouse']); if (!empty($warehouse_location)) { $product['warehouse_location'] = $warehouse_location; } else { $product['warehouse_location'] = false; } } else { $product['warehouse_name'] = '--'; $product['warehouse_location'] = false; } } $gender = new Gender((int) $customer->id_gender, $this->context->language->id); $history = $order->getHistory($this->context->language->id); foreach ($history as &$order_state) { $order_state['text-color'] = Tools::getBrightness($order_state['color']) < 128 ? 'white' : 'black'; } // Smarty assign $this->tpl_view_vars = array('order' => $order, 'cart' => new Cart($order->id_cart), 'customer' => $customer, 'gender' => $gender, 'customer_addresses' => $customer->getAddresses($this->context->language->id), 'addresses' => array('delivery' => $addressDelivery, 'deliveryState' => isset($deliveryState) ? $deliveryState : null, 'invoice' => $addressInvoice, 'invoiceState' => isset($invoiceState) ? $invoiceState : null), 'customerStats' => $customer->getStats(), 'products' => $products, 'discounts' => $order->getCartRules(), 'orders_total_paid_tax_incl' => $order->getOrdersTotalPaid(), 'total_paid' => $order->getTotalPaid(), 'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id), 'customer_thread_message' => CustomerThread::getCustomerMessages($order->id_customer, null, $order->id), 'orderMessages' => OrderMessage::getOrderMessages($order->id_lang), 'messages' => Message::getMessagesByOrderId($order->id, true), 'carrier' => new Carrier($order->id_carrier), 'history' => $history, 'states' => OrderState::getOrderStates($this->context->language->id), 'warehouse_list' => $warehouse_list, 'sources' => ConnectionsSource::getOrderSources($order->id), 'currentState' => $order->getCurrentOrderState(), 'currency' => new Currency($order->id_currency), 'currencies' => Currency::getCurrenciesByIdShop($order->id_shop), 'previousOrder' => $order->getPreviousOrderId(), 'nextOrder' => $order->getNextOrderId(), 'current_index' => self::$currentIndex, 'carrierModuleCall' => $carrier_module_call, 'iso_code_lang' => $this->context->language->iso_code, 'id_lang' => $this->context->language->id, 'can_edit' => $this->tabAccess['edit'] == 1, 'current_id_lang' => $this->context->language->id, 'invoices_collection' => $order->getInvoicesCollection(), 'not_paid_invoices_collection' => $order->getNotPaidInvoicesCollection(), 'payment_methods' => $payment_methods, 'invoice_management_active' => Configuration::get('PS_INVOICE', null, null, $order->id_shop), 'display_warehouse' => (int) Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'), 'HOOK_CONTENT_ORDER' => Hook::exec('displayAdminOrderContentOrder', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_CONTENT_SHIP' => Hook::exec('displayAdminOrderContentShip', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_TAB_ORDER' => Hook::exec('displayAdminOrderTabOrder', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_TAB_SHIP' => Hook::exec('displayAdminOrderTabShip', array('order' => $order, 'products' => $products, 'customer' => $customer))); $options_time = array(); $time_slice = Configuration::get('APH_CALENDAR_TIME_SLICE'); for ($hours = 0; $hours < 24; $hours++) { // the interval for hours is '1' for ($mins = 0; $mins < 60; $mins += $time_slice) { // the interval for mins is 'APH_CALENDAR_TIME_SLICE' $options_time[str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($mins, 2, '0', STR_PAD_LEFT)] = str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($mins, 2, '0', STR_PAD_LEFT); } } $this->tpl_view_vars['options_time'] = $options_time; $employees = array(); $e = AphEmployeeProduct::getEmployeesByShop((int) Context::getContext()->shop->id); foreach ($e as $employee) { $employees[$employee['id_employee']] = $employee['fullName']; } $this->tpl_view_vars['employees'] = $employees; $helper = new HelperView($this); $this->setHelperDisplay($helper); $helper->tpl_vars = $this->getTemplateViewVars(); $helper->base_folder = $this->getTemplatePath() . 'aph_orders/helpers/'; $helper->base_tpl = 'view/view.tpl'; $view = $helper->generateView(); return $view; }
public function hookAdminOrder($params) { if (!$this->soapClientExists()) { return ''; } $order = new Order((int) $params['id_order']); if (!DpdPolandConfiguration::checkRequiredConfiguration()) { $this->context->smarty->assign(array('displayBlock' => false, 'moduleSettingsLink' => $this->context->link->getAdminLink('AdminModules') . '&configure=' . $this->name . '&menu=configuration')); } else { $this->displayFlashMessagesIfIsset(); // PDF error might be set as flash error $order = new Order((int) $params['id_order']); $package = DpdPolandPackage::getInstanceByIdOrder((int) $order->id); $parcels = DpdPolandParcel::getParcels($order, $package->id_package_ws); $products = DpdPolandParcelProduct::getShippedProducts($order, DpdPolandParcelProduct::getProductDetailsByParcels($parcels)); $customer = new Customer((int) $order->id_customer); $settings = new DpdPolandConfiguration(); if (version_compare(_PS_VERSION_, '1.5', '<')) { $this->addJS(_PS_JS_DIR_ . 'jquery/jquery.scrollTo-1.4.2-min.js'); $this->addJS(_PS_JS_DIR_ . 'jquery/jquery-ui-1.8.10.custom.min.js'); $this->addJS(_PS_JS_DIR_ . 'jquery/accordion/accordion.ui.js'); $this->addJS(_PS_JS_DIR_ . 'jquery/jquery.autocomplete.js'); $this->addJS(_DPDPOLAND_JS_URI_ . 'adminOrder.js'); $this->addCSS(_DPDPOLAND_CSS_URI_ . 'adminOrder.css'); $this->addCSS(_PS_CSS_DIR_ . 'jquery-ui-1.8.10.custom.css'); } else { $this->context->controller->addJqueryUI(array('ui.core', 'ui.widget', 'ui.accordion')); $this->context->controller->addJqueryPlugin('scrollTo'); $this->context->controller->addJS(_DPDPOLAND_JS_URI_ . 'adminOrder.js'); $this->context->controller->addCSS(_DPDPOLAND_CSS_URI_ . 'adminOrder.css'); } $selectedPayerNumber = $package->payerNumber ? $package->payerNumber : $settings->client_number; $selectedRecipientIdAddress = $package->id_address_delivery ? $package->id_address_delivery : $order->id_address_delivery; $id_currency_pl = Currency::getIdByIsoCode(_DPDPOLAND_CURRENCY_ISO_, (int) $this->context->shop->id); $currency_to = new Currency((int) $id_currency_pl); $currency_from = new Currency($order->id_currency); $id_method = $this->getMethodIdByCarrierId((int) $order->id_carrier); if ($id_method) { $payment_method_compatible = false; $is_cod_module = Configuration::get(DpdPolandConfiguration::COD_MODULE_PREFIX . $order->module); if ($id_method == _DPDPOLAND_STANDARD_COD_ID_ && $is_cod_module || $id_method == _DPDPOLAND_STANDARD_ID_ && !$is_cod_module || $id_method == _DPDPOLAND_CLASSIC_ID_ && !$is_cod_module) { $payment_method_compatible = true; } } else { $payment_method_compatible = true; } if (!$payment_method_compatible) { $error_message = $this->l('Your payment method and Shipping method is not compatible.') . '<br />'; $error_message .= ' ' . $this->l('If delivery address is not Poland, then COD payment method is not supported.') . '<br />'; $error_message .= ' ' . $this->l('If delivery address is not Poland, then COD payment method is not supported.') . '<br />'; $error_message .= ' ' . $this->l('If delivery address is Poland and payment method is COD please use shipping method DPD Domestic + COD.') . '<br />'; $error_message .= ' ' . $this->l('If delivery address is Poland and no COD payment is used please select DPD Domestic shipping method.'); $this->context->smarty->assign('compatibility_warning_message', $error_message); } if (!$this->validateAddressForPackageSession((int) $selectedRecipientIdAddress, (int) $id_method)) { $error_message = $this->l('Your develivery address is not compatible with the selected shipping method.') . ' ' . $this->l('DPD Poland Domestic is available only if develivery address is Poland.') . ' ' . $this->l('DPD Internationl shipping method is available only if delivery address is not Poland.'); $this->context->smarty->assign('address_warning_message', $error_message); } $cookie = new Cookie(_DPDPOLAND_COOKIE_); $this->context->smarty->assign(array('displayBlock' => true, 'order' => $order, 'messages' => $this->html, 'package' => $package, 'selected_id_method' => self::getMethodIdByCarrierId($order->id_carrier), 'settings' => $settings, 'payerNumbers' => DpdPolandPayerNumber::getPayerNumbers(), 'selectedPayerNumber' => $selectedPayerNumber, 'products' => $products, 'parcels' => $parcels, 'senderAddress' => $this->getSenderAddress($settings, $package->id_address_sender), 'recipientAddresses' => $customer->getAddresses($this->context->language->id), 'selectedRecipientIdAddress' => $selectedRecipientIdAddress, 'recipientAddress' => $this->getRecipientAddress($selectedRecipientIdAddress), 'currency_from' => $currency_from, 'currency_to' => $currency_to, 'redirect_and_open' => $cookie->dpdpoland_package_id, 'printout_format' => $cookie->dpdpoland_printout_format)); $this->setGlobalVariablesForAjax(); } if (version_compare(_PS_VERSION_, '1.6', '<')) { return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_ . 'hook/adminOrder.tpl'); } return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_ . 'hook/adminOrder_16.tpl'); }
public function ajaxProcessSearchCustomers() { $searches = explode(' ', Tools::getValue('customer_search')); $customers = array(); $searches = array_unique($searches); foreach ($searches as $search) { $sql_base = 'SELECT * FROM `' . _DB_PREFIX_ . 'customer`'; $sql = '(' . $sql_base . ' WHERE `email` LIKE \'%' . pSQL($search) . '%\')'; $sql .= ' UNION (' . $sql_base . ' WHERE `id_customer` = ' . (int) $search . ')'; $sql .= ' UNION (' . $sql_base . ' WHERE `lastname` LIKE \'%' . pSQL($search) . '%\')'; $sql .= ' UNION (' . $sql_base . ' WHERE `firstname` LIKE \'%' . pSQL($search) . '%\')'; $sql .= ' LIMIT 0, 50'; $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if (!empty($search) && $results) { foreach ($results as $result) { if ($result['active']) { $customer = new Customer($result['id_customer']); $addresses = $customer->getAddresses((int) Context::getContext()->language->id); $result['address'] = $addresses[0]; $customers[$result['id_customer']] = $result; } } } } if (count($customers)) { $to_return = array('customers' => $customers, 'found' => true); } else { $to_return = array('found' => false); } $this->content = Tools::jsonEncode($to_return); }
/** * Function DO HOOK */ public function doHook($aParams, $sEvent = '') { if ($this->_allowToWork == false) { return; } $oCustomer = new Customer($aParams['cart']->id_customer); $oCurrency = new Currency($aParams['cart']->id_currency); $aAddress = $oCustomer->getAddresses($aParams['cart']->id_lang); $aAddress = $aAddress[0]; $sUserCountry = ''; if (isset($aAddress['id_country']) && !empty($aAddress['id_country'])) { $sUserCountry = Country::getIsoById($aAddress['id_country']); } // for 1.3 compatibility $tva = false; if (isset($aParams['objOrder']) && !empty($aParams['objOrder'])) { $tax = $aParams['objOrder']->total_paid_tax_incl - $aParams['objOrder']->total_shipping_tax_incl - ($aParams['objOrder']->total_paid_tax_excl - $aParams['objOrder']->total_shipping_tax_excl); $tva = $aParams['objOrder']->carrier_tax_rate; } else { $tax = $aParams['cart']->getOrderTotal(true, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING) - $aParams['cart']->getOrderTotal(false, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING); if ($aParams['cart']->getOrderTotal(false, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING) > 0) { $tva = $tax * 100 / $aParams['cart']->getOrderTotal(false, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING); } } $aParamsToTwenga = array(); $aParamsToTwenga['event'] = $sEvent; $aParamsToTwenga['user_id'] = $aParams['cart']->id_customer; $aParamsToTwenga['user_global_id'] = md5($oCustomer->email); $aParamsToTwenga['user_email'] = $oCustomer->email; $aParamsToTwenga['user_firstname'] = $oCustomer->firstname; $aParamsToTwenga['user_city'] = $aParams['cart']->id_customer ? $aAddress['city'] : ''; $aParamsToTwenga['user_state'] = $aParams['cart']->id_customer ? $aAddress['state'] : ''; $aParamsToTwenga['user_country'] = $aParams['cart']->id_customer ? $sUserCountry : ''; $aParamsToTwenga['user_segment'] = ''; $aParamsToTwenga['user_is_customer'] = 1; $aParamsToTwenga['ecommerce_platform'] = 'Prestashop'; $aParamsToTwenga['tag_platform'] = ''; $aParamsToTwenga['basket_id'] = $aParams['cart']->id; $aParamsToTwenga['currency'] = $oCurrency->iso_code; $aParamsToTwenga['total_ht'] = isset($aParams['objOrder']) ? $aParams['objOrder']->total_paid_tax_excl - $aParams['objOrder']->total_shipping_tax_excl : $aParams['cart']->getOrderTotal(false, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING); $aParamsToTwenga['tva'] = $tva !== false ? Tools::ps_round($tva, 2) : ''; $aParamsToTwenga['total_ttc'] = isset($aParams['objOrder']) ? $aParams['objOrder']->total_paid_tax_incl - $aParams['objOrder']->total_shipping_tax_incl : $aParams['cart']->getOrderTotal(true, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING); $aParamsToTwenga['shipping'] = isset($aParams['objOrder']) ? $aParams['objOrder']->total_shipping_tax_incl : $aParams['cart']->getOrderTotal(true, Twenga::ONLY_SHIPPING); $aParamsToTwenga['tax'] = $tax; if (isset($aParams['objOrder']) && !empty($aParams['objOrder'])) { $aParamsToTwenga['order_id'] = $aParams['objOrder']->id; } $aParamsToTwenga['items'] = array(); if ($sEvent == 'product' && isset($_POST['id_product']) || isset($_GET['id_product'])) { $iIdProduct = isset($_POST['id_product']) ? $_POST['id_product'] : $_GET['id_product']; $oProduct = new Product($iIdProduct); if ($oProduct) { $oCategory = new Category($oProduct->id_category_default); if ($oCategory) { $arr_item = array(); $arr_item['price'] = $oProduct->price; $arr_item['quantity'] = ''; $arr_item['ref_id'] = $oProduct->reference; $arr_item['item_id'] = $iIdProduct; $arr_item['name'] = $oProduct->name[1]; $arr_item['category_name'] = $oCategory->name; $aParamsToTwenga['items'][] = $arr_item; } } } elseif (isset($aParams['objOrder']) && !empty($aParams['objOrder'])) { foreach ($aParams['objOrder']->getProducts() as $product) { $oCategory = new Category($product['id_category_default']); $arr_item = array(); if ($product['unit_price_tax_excl'] != '') { $arr_item['price'] = (double) $product['unit_price_tax_excl']; } if ($product['product_quantity'] != '') { $arr_item['quantity'] = (int) $product['product_quantity']; } if ($product['reference'] != '') { $arr_item['ref_id'] = (string) $product['reference']; } if ($product['id_product'] != '') { $arr_item['item_id'] = (string) $product['id_product']; } if ($product['product_name'] != '') { $arr_item['name'] = (string) $product['product_name']; } if (isset($oCategory) && !empty($oCategory)) { $arr_item['category_name'] = $oCategory->name; } $aParamsToTwenga['items'][] = $arr_item; } } else { foreach ($aParams['cart']->getProducts() as $product) { $arr_item = array(); if ($product['price'] != '') { $arr_item['price'] = (double) $product['price']; } if ($product['cart_quantity'] != '') { $arr_item['quantity'] = (int) $product['cart_quantity']; } if ($product['reference'] != '') { $arr_item['ref_id'] = (string) $product['reference']; } if ($product['id_product'] != '') { $arr_item['item_id'] = (string) $product['id_product']; } if ($product['name'] != '') { $arr_item['name'] = (string) $product['name']; } if ($product['category']) { $arr_item['category_name'] = (string) $product['category']; } $aParamsToTwenga['items'][] = $arr_item; } } $aParamsToTwenga = array_filter($aParamsToTwenga); try { $tracking_code = self::$obj_twenga->getTrackingScript($aParamsToTwenga); return $tracking_code; } catch (TwengaFieldsException $e) { return $this->l('Error occurred when params passed in Twenga API') . ' : <br />' . $e->getMessage(); } catch (Exception $e) { return $e->getMessage(); } }
public function renderView() { $neoExchange = new NeoExchanges(Tools::getValue('id_neo_exchange')); $order = new Order(Tools::getValue('id_neo_exchange')); if (!Validate::isLoadedObject($neoExchange)) { $this->errors[] = Tools::displayError('The order cannot be found within your database.'); } $customer = new Customer($neoExchange->id_customer); //$carrier = new Carrier($neoExchange->id_carrier); $currency = new Currency((int) $neoExchange->id_currency); $buys = new NeoItemsBuyCore(Tools::getValue('id_neo_exchange')); $sales = new NeoItemsSalesCore(Tools::getValue('id_neo_exchange')); $products = $this->getProducts($buys); $products2 = $this->getProducts($sales); //$products = $this->getProducts($neoExchange); // Carrier module call /*$carrier_module_call = null; if ($carrier->is_module) { $module = Module::getInstanceByName($carrier->external_module_name); if (method_exists($module, 'displayInfoByCart')) $carrier_module_call = call_user_func(array($module, 'displayInfoByCart'), $neoExchange->id_cart); } // Retrieve addresses information $addressInvoice = new Address($neoExchange->id_address_invoice, $this->context->language->id); if (Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state) $invoiceState = new State((int)$addressInvoice->id_state); if ($neoExchange->id_address_invoice == $neoExchange->id_address_delivery) { $addressDelivery = $addressInvoice; if (isset($invoiceState)) $deliveryState = $invoiceState; } else { $addressDelivery = new Address($neoExchange->id_address_delivery, $this->context->language->id); if (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state) $deliveryState = new State((int)($addressDelivery->id_state)); }*/ $this->toolbar_title = sprintf($this->l('Intercambio #%1$d (%2$s) - %3$s %4$s'), $neoExchange->id, $neoExchange->reference, $customer->firstname, $customer->lastname); if (Shop::isFeatureActive()) { $shop = new Shop((int) $neoExchange->id_shop); $this->toolbar_title .= ' - ' . sprintf($this->l('Shop: %s'), $shop->name); } // gets warehouses to ship products, if and only if advanced stock management is activated $warehouse_list = null; $payment_methods = array(); foreach (PaymentModule::getInstalledPaymentModules() as $payment) { $module = Module::getInstanceByName($payment['name']); if (Validate::isLoadedObject($module) && $module->active) { $payment_methods[] = $module->displayName; } } // display warning if there are products out of stock $display_out_of_stock_warning = false; $current_order_state = $neoExchange->getCurrentOrderState(); if (Configuration::get('PS_STOCK_MANAGEMENT') && (!Validate::isLoadedObject($current_order_state) || $current_order_state->delivery != 1 && $current_order_state->shipped != 1)) { $display_out_of_stock_warning = true; } $total_buy = 0; $total_sale = 0; $products_buy = count($products); $products_sale = count($products2); // products current stock (from stock_available) foreach ($products as &$product) { $total_buy += $product['price']; } foreach ($products2 as &$product) { $total_sale += $product['price']; } $gender = new Gender((int) $customer->id_gender, $this->context->language->id); $history = $neoExchange->getHistory($this->context->language->id); foreach ($history as &$order_state) { $order_state['text-color'] = Tools::getBrightness($order_state['color']) < 128 ? 'white' : 'black'; } // Smarty assign $this->tpl_view_vars = array('order' => $neoExchange, 'customer' => $customer, 'gender' => $gender, 'customer_addresses' => $customer->getAddresses($this->context->language->id), 'customerStats' => $customer->getStats(), 'products' => $products, 'products2' => $products2, 'total_buy' => $total_buy, 'total_sale' => $total_sale, 'products_buy' => $products_buy, 'products_sale' => $products_sale, 'neo_order_shipping_price' => 0, 'orders_total_paid_tax_incl' => $neoExchange->getOrdersTotalPaid(), 'total_paid' => $neoExchange->getTotalPaid(), 'returns' => OrderReturn::getOrdersReturn($neoExchange->id_customer, $neoExchange->id), 'customer_thread_message' => CustomerThread::getCustomerMessages($neoExchange->id_customer), 'orderMessages' => OrderMessage::getOrderMessages($neoExchange->id_lang), 'messages' => Message::getMessagesByOrderId($neoExchange->id, true), 'history' => $history, 'neoStatus' => NeoStatusCore::getNeoStatus(), 'warehouse_list' => $warehouse_list, 'sources' => ConnectionsSource::getOrderSources($neoExchange->id), 'currentState' => $neoExchange->getCurrentOrderState(), 'currency' => new Currency($neoExchange->id_currency), 'currencies' => Currency::getCurrenciesByIdShop($neoExchange->id_shop), 'previousOrder' => $neoExchange->getPreviousOrderId(), 'nextOrder' => $neoExchange->getNextOrderId(), 'current_index' => self::$currentIndex, 'iso_code_lang' => $this->context->language->iso_code, 'id_lang' => $this->context->language->id, 'can_edit' => $this->tabAccess['edit'] == 1, 'current_id_lang' => $this->context->language->id, 'invoices_collection' => $neoExchange->getInvoicesCollection(), 'not_paid_invoices_collection' => $neoExchange->getNotPaidInvoicesCollection(), 'payment_methods' => $payment_methods, 'invoice_management_active' => Configuration::get('PS_INVOICE', null, null, $neoExchange->id_shop), 'display_warehouse' => (int) Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'), 'HOOK_CONTENT_ORDER' => Hook::exec('displayAdminOrderContentOrder', array('order' => $neoExchange, 'products' => $products, 'customer' => $customer)), 'HOOK_CONTENT_SHIP' => Hook::exec('displayAdminOrderContentShip', array('order' => $neoExchange, 'products' => $products, 'customer' => $customer)), 'HOOK_TAB_ORDER' => Hook::exec('displayAdminOrderTabOrder', array('order' => $neoExchange, 'products' => $products, 'customer' => $customer)), 'HOOK_TAB_SHIP' => Hook::exec('displayAdminOrderTabShip', array('order' => $neoExchange, 'products' => $products, 'customer' => $customer))); return parent::renderView(); }
/** * Execute hook * * @param mixed $params */ public function hookOrderConfirmation($params) { global $smarty, $cookie, $link; if (!$this->active) { return; } // seting error handler eval('function itembaseErrorHandler($errno, $errstr, $errfile, $errline) { ' . ((bool) Configuration::get('PS_ITEMBASE_DEBUG') ? 'echo " <!--ITEMBASE ".print_r(array($errno, $errstr, $errfile, $errline), true)."ITEMBASE--> ";' : '') . ' return true; }'); set_error_handler('itembaseErrorHandler', E_ALL); try { include_once rtrim(_PS_MODULE_DIR_, '/') . '/itembase/plugindata.php'; include_once rtrim(_PS_MODULE_DIR_, '/') . '/itembase/oauth.php'; // geting access token $responseArray = $this->jsonDecode(authenticateClient(Configuration::get('PS_ITEMBASE_APIKEY'), Configuration::get('PS_ITEMBASE_SECRET'))); if (!isset($responseArray['access_token'])) { itembaseErrorHandler(0, 'no access_token for ' . Tools::safeOutput(Configuration::get('PS_ITEMBASE_APIKEY')) . ' ' . substr(Tools::safeOutput(Configuration::get('PS_ITEMBASE_SECRET')), 0, 4) . '... ' . PS_ITEMBASE_SERVER_OAUTH . ' ' . print_r($responseArray, true), __FILE__, __LINE__ - 1); } // order data gathering $order = new Order($params['objOrder']->id, NULL); $currency = Currency::getCurrency((int) $order->id_currency); $carrier = new Carrier((int) $order->id_carrier); $language = Language::getLanguage((int) $cookie->id_lang); $customer = new Customer((int) $order->id_customer); $address = $customer->getAddresses($cookie->id_lang); if (is_object($address)) { $address = (array) $address; } if (isset($address['0'])) { $address = $address['0']; } // products data gathering $allProducts = array(); foreach ($order->getProductsDetail() as $order_detail) { $product_id = $order_detail['product_id']; $product = new Product($product_id, true, null); $cover = Product::getCover($product_id); $product_img = $link->getImageLink($product->link_rewrite, $product_id . '-' . $cover['id_image']); if (strpos($product_img, 'http') !== 0) { $product_img = Tools::getHttpHost(true) . $product_img; } $category = new Category($product->id_category_default); $allProducts[] = array('id' => $order_detail['product_id'], 'category' => $category->name, 'name' => $product->name, 'quantity' => $order_detail['product_quantity'], 'price' => $product->getPrice(true, NULL, 2), 'ean' => $product->ean13, 'isbn' => '', 'asin' => '', 'description' => $product->description_short, 'pic_thumb' => $product_img, 'pic_medium' => $product_img, 'pic_large' => $product_img, 'url' => $product->getLink(), 'presta_lang_id' => $language['id_lang']); } $dataForItembase = array('access_token' => $responseArray['access_token'], 'email' => $customer->email, 'firstname' => $customer->firstname, 'lastname' => $customer->lastname, 'street' => $address['address1'] . ($address['address2'] ? ' ' . $address['address2'] : ''), 'zip' => $address['postcode'], 'city' => $address['city'], 'country' => $address['country'], 'phone' => $address['phone'], 'lang' => $language['iso_code'], 'purchase_date' => $order->date_add, 'currency' => $currency['iso_code'], 'total' => $order->total_products_wt, 'order_number' => $order->id, 'customer_id' => $order->id_customer, 'invoice_number' => $order->invoice_number, 'shipping_cost' => $order->total_shipping, 'carrier' => $carrier->name, 'payment_option' => $order->payment, 'is_opt_in' => $customer->newsletter, 'shop_name' => class_exists('Context', false) ? Context::getContext()->shop->name : Configuration::get('PS_SHOP_NAME'), 'products' => $allProducts); // encoding data utf8EncodeRecursive($dataForItembase); $smarty->assign('ibdata', $dataForItembase); $smarty->assign('ibdatajson', $this->jsonEncode($dataForItembase)); $smarty->assign('ibembedserver', PS_ITEMBASE_SERVER_EMBED); $smarty->assign('ibhostserver', PS_ITEMBASE_SERVER_HOST); $smarty->assign('ibpluginversion', PS_ITEMBASE_PLUGIN_VERSION); $smarty->assign('ibtop', Configuration::get('PS_ITEMBASE_TOP')); } catch (Exception $e) { itembaseErrorHandler($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine()); } // restoring error handler restore_error_handler(); return $this->display(__FILE__, 'views/templates/front/checkout_plugin.tpl'); }
public function hookPaymentTop($param) { if (!$this->_activeVerification()) { return false; } $smarty = Context::getContext()->smarty; $customer = new Customer($param['cart']->id_customer); $addresses = $customer->getAddresses(Context::getContext()->language->id); $address = new Address($addresses[0]['id_address']); $cart = new Cart($param['cart']->id); $link = new Link(); $fidbag_user = new FidbagUser($param['cart']->id_customer); $fidbag_user->getFidBagUser(); $var = array('path' => $this->_path, 'img' => _PS_IMG_, 'id_customer' => $param['cart']->id_customer, 'id_cart' => $param['cart']->id, 'fidbag_token' => Configuration::get('FIDBAG_TOKEN'), 'module' => _PS_MODULE_DIR_ . $this->_moduleName . '/'); $smarty->assign('glob', $var); $smarty->assign('main_url', $this->getMainUrl()); $smarty->assign('fidbag_token', Tools::encrypt((int) $param['cart']->id_customer)); $smarty->assign('price', $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING)); $smarty->assign('shipment', $cart->getOrderTotal(true, Cart::ONLY_SHIPPING)); $smarty->assign('total_cart', $cart->getOrderTotal()); $smarty->assign('shipping', $cart->getOrderTotal(true, Cart::ONLY_SHIPPING)); $smarty->assign('discount', $cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS)); $smarty->assign('fidbag_login', $fidbag_user->getLogin()); $smarty->assign('fidbag_password', $fidbag_user->getPassword()); if (_PS_VERSION_ < '1.5') { $smarty->assign('base_dir', Tools::getProtocol() . Tools::getHttpHost() . __PS_BASE_URI__); } if ((int) Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { $smarty->assign('redirect', $link->getPageLink('order-opc.php')); } else { if (_PS_VERSION_ >= '1.5') { $smarty->assign('redirect', $link->getPageLink('order.php', false, null, array('step' => '3'))); } else { $smarty->assign('redirect', $link->getPageLink('order.php?step=3')); } } if (isset($customer->id_gender)) { $smarty->assign('sub_gender', $customer->id_gender); } $smarty->assign('sub_lastname', $customer->lastname); $smarty->assign('sub_firstname', $customer->firstname); $smarty->assign('sub_email', $customer->email); $smarty->assign('sub_address', $address->address1 . ' ' . $address->address2); $smarty->assign('sub_zipcode', $address->postcode); $smarty->assign('sub_city', $address->city); if (_PS_VERSION_ < '1.5') { return $this->display(__FILE__, 'views/templates/hook/payment_top_14x.tpl'); } return $this->display(__FILE__, 'views/templates/hook/payment_top.tpl'); }
public function renderView() { $order = new Order(Tools::getValue('id_order')); if (!Validate::isLoadedObject($order)) { $this->errors[] = $this->trans('The order cannot be found within your database.', array(), 'Admin.OrdersCustomers.Notification'); } $customer = new Customer($order->id_customer); $carrier = new Carrier($order->id_carrier); $products = $this->getProducts($order); $currency = new Currency((int) $order->id_currency); // Carrier module call $carrier_module_call = null; if ($carrier->is_module) { $module = Module::getInstanceByName($carrier->external_module_name); if (method_exists($module, 'displayInfoByCart')) { $carrier_module_call = call_user_func(array($module, 'displayInfoByCart'), $order->id_cart); } } // Retrieve addresses information $addressInvoice = new Address($order->id_address_invoice, $this->context->language->id); if (Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state) { $invoiceState = new State((int) $addressInvoice->id_state); } if ($order->id_address_invoice == $order->id_address_delivery) { $addressDelivery = $addressInvoice; if (isset($invoiceState)) { $deliveryState = $invoiceState; } } else { $addressDelivery = new Address($order->id_address_delivery, $this->context->language->id); if (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state) { $deliveryState = new State((int) $addressDelivery->id_state); } } $this->toolbar_title = $this->trans('Order #%id% (%ref%) - %firstname% %lastname%', array('%id%' => $order->id, '%ref%' => $order->reference, '%firstname%' => $customer->firstname, '%lastname%' => $customer->lastname), 'Admin.OrdersCustomers.Feature'); if (Shop::isFeatureActive()) { $shop = new Shop((int) $order->id_shop); $this->toolbar_title .= ' - ' . sprintf($this->trans('Shop: %s', array(), 'Admin.OrdersCustomers.Feature'), $shop->name); } // gets warehouses to ship products, if and only if advanced stock management is activated $warehouse_list = null; $order_details = $order->getOrderDetailList(); foreach ($order_details as $order_detail) { $product = new Product($order_detail['product_id']); if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management) { $warehouses = Warehouse::getWarehousesByProductId($order_detail['product_id'], $order_detail['product_attribute_id']); foreach ($warehouses as $warehouse) { if (!isset($warehouse_list[$warehouse['id_warehouse']])) { $warehouse_list[$warehouse['id_warehouse']] = $warehouse; } } } } $payment_methods = array(); foreach (PaymentModule::getInstalledPaymentModules() as $payment) { $module = Module::getInstanceByName($payment['name']); if (Validate::isLoadedObject($module) && $module->active) { $payment_methods[] = $module->displayName; } } // display warning if there are products out of stock $display_out_of_stock_warning = false; $current_order_state = $order->getCurrentOrderState(); if (Configuration::get('PS_STOCK_MANAGEMENT') && (!Validate::isLoadedObject($current_order_state) || $current_order_state->delivery != 1 && $current_order_state->shipped != 1)) { $display_out_of_stock_warning = true; } // products current stock (from stock_available) foreach ($products as &$product) { // Get total customized quantity for current product $customized_product_quantity = 0; if (is_array($product['customizedDatas'])) { foreach ($product['customizedDatas'] as $customizationPerAddress) { foreach ($customizationPerAddress as $customizationId => $customization) { $customized_product_quantity += (int) $customization['quantity']; } } } $product['customized_product_quantity'] = $customized_product_quantity; $product['current_stock'] = StockAvailable::getQuantityAvailableByProduct($product['product_id'], $product['product_attribute_id'], $product['id_shop']); $resume = OrderSlip::getProductSlipResume($product['id_order_detail']); $product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity']; $product['amount_refundable'] = $product['total_price_tax_excl'] - $resume['amount_tax_excl']; $product['amount_refundable_tax_incl'] = $product['total_price_tax_incl'] - $resume['amount_tax_incl']; $product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl'], $currency); $product['refund_history'] = OrderSlip::getProductSlipDetail($product['id_order_detail']); $product['return_history'] = OrderReturn::getProductReturnDetail($product['id_order_detail']); // if the current stock requires a warning if ($product['current_stock'] <= 0 && $display_out_of_stock_warning) { $this->displayWarning($this->trans('This product is out of stock: ', array(), 'Admin.OrdersCustomers.Notification') . ' ' . $product['product_name']); } if ($product['id_warehouse'] != 0) { $warehouse = new Warehouse((int) $product['id_warehouse']); $product['warehouse_name'] = $warehouse->name; $warehouse_location = WarehouseProductLocation::getProductLocation($product['product_id'], $product['product_attribute_id'], $product['id_warehouse']); if (!empty($warehouse_location)) { $product['warehouse_location'] = $warehouse_location; } else { $product['warehouse_location'] = false; } } else { $product['warehouse_name'] = '--'; $product['warehouse_location'] = false; } } // Package management for order foreach ($products as &$product) { $pack_items = $product['cache_is_pack'] ? Pack::getItemTable($product['id_product'], $this->context->language->id, true) : array(); foreach ($pack_items as &$pack_item) { $pack_item['current_stock'] = StockAvailable::getQuantityAvailableByProduct($pack_item['id_product'], $pack_item['id_product_attribute'], $pack_item['id_shop']); // if the current stock requires a warning if ($product['current_stock'] <= 0 && $display_out_of_stock_warning) { $this->displayWarning($this->trans('This product, included in package (' . $product['product_name'] . ') is out of stock: ', array(), 'Admin.OrdersCustomers.Notification') . ' ' . $pack_item['product_name']); } $this->setProductImageInformations($pack_item); if ($pack_item['image'] != null) { $name = 'product_mini_' . (int) $pack_item['id_product'] . (isset($pack_item['id_product_attribute']) ? '_' . (int) $pack_item['id_product_attribute'] : '') . '.jpg'; // generate image cache, only for back office $pack_item['image_tag'] = ImageManager::thumbnail(_PS_IMG_DIR_ . 'p/' . $pack_item['image']->getExistingImgPath() . '.jpg', $name, 45, 'jpg'); if (file_exists(_PS_TMP_IMG_DIR_ . $name)) { $pack_item['image_size'] = getimagesize(_PS_TMP_IMG_DIR_ . $name); } else { $pack_item['image_size'] = false; } } } $product['pack_items'] = $pack_items; } $gender = new Gender((int) $customer->id_gender, $this->context->language->id); $history = $order->getHistory($this->context->language->id); foreach ($history as &$order_state) { $order_state['text-color'] = Tools::getBrightness($order_state['color']) < 128 ? 'white' : 'black'; } // Smarty assign $this->tpl_view_vars = array('order' => $order, 'cart' => new Cart($order->id_cart), 'customer' => $customer, 'gender' => $gender, 'customer_addresses' => $customer->getAddresses($this->context->language->id), 'addresses' => array('delivery' => $addressDelivery, 'deliveryState' => isset($deliveryState) ? $deliveryState : null, 'invoice' => $addressInvoice, 'invoiceState' => isset($invoiceState) ? $invoiceState : null), 'customerStats' => $customer->getStats(), 'products' => $products, 'discounts' => $order->getCartRules(), 'orders_total_paid_tax_incl' => $order->getOrdersTotalPaid(), 'total_paid' => $order->getTotalPaid(), 'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id), 'customer_thread_message' => CustomerThread::getCustomerMessages($order->id_customer, null, $order->id), 'orderMessages' => OrderMessage::getOrderMessages($order->id_lang), 'messages' => Message::getMessagesByOrderId($order->id, true), 'carrier' => new Carrier($order->id_carrier), 'history' => $history, 'states' => OrderState::getOrderStates($this->context->language->id), 'warehouse_list' => $warehouse_list, 'sources' => ConnectionsSource::getOrderSources($order->id), 'currentState' => $order->getCurrentOrderState(), 'currency' => new Currency($order->id_currency), 'currencies' => Currency::getCurrenciesByIdShop($order->id_shop), 'previousOrder' => $order->getPreviousOrderId(), 'nextOrder' => $order->getNextOrderId(), 'current_index' => self::$currentIndex, 'carrierModuleCall' => $carrier_module_call, 'iso_code_lang' => $this->context->language->iso_code, 'id_lang' => $this->context->language->id, 'can_edit' => $this->access('edit'), 'current_id_lang' => $this->context->language->id, 'invoices_collection' => $order->getInvoicesCollection(), 'not_paid_invoices_collection' => $order->getNotPaidInvoicesCollection(), 'payment_methods' => $payment_methods, 'invoice_management_active' => Configuration::get('PS_INVOICE', null, null, $order->id_shop), 'display_warehouse' => (int) Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'), 'carrier_list' => $this->getCarrierList($order), 'recalculate_shipping_cost' => (int) Configuration::get('PS_ORDER_RECALCULATE_SHIPPING'), 'HOOK_CONTENT_ORDER' => Hook::exec('displayAdminOrderContentOrder', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_CONTENT_SHIP' => Hook::exec('displayAdminOrderContentShip', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_TAB_ORDER' => Hook::exec('displayAdminOrderTabOrder', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_TAB_SHIP' => Hook::exec('displayAdminOrderTabShip', array('order' => $order, 'products' => $products, 'customer' => $customer))); return parent::renderView(); }
public function customerImport() { $customer_exist = false; $this->receiveTab(); $handle = $this->openCsvFile(); $default_language_id = (int) Configuration::get('PS_LANG_DEFAULT'); $id_lang = Language::getIdByIso(Tools::getValue('iso_lang')); if (!Validate::isUnsignedId($id_lang)) { $id_lang = $default_language_id; } AdminImportController::setLocale(); for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) { if (Tools::getValue('convert')) { $line = $this->utf8EncodeArray($line); } $info = AdminImportController::getMaskedRow($line); AdminImportController::setDefaultValues($info); if (Tools::getValue('forceIDs') && isset($info['id']) && (int) $info['id']) { $customer = new Customer((int) $info['id']); } else { if (array_key_exists('id', $info) && (int) $info['id'] && Customer::customerIdExistsStatic((int) $info['id'])) { $customer = new Customer((int) $info['id']); } else { $customer = new Customer(); } } if (array_key_exists('id', $info) && (int) $info['id'] && Customer::customerIdExistsStatic((int) $info['id'])) { $current_id_customer = $customer->id; $current_id_shop = $customer->id_shop; $current_id_shop_group = $customer->id_shop_group; $customer_exist = true; $customer_groups = $customer->getGroups(); $addresses = $customer->getAddresses((int) Configuration::get('PS_LANG_DEFAULT')); } // Group Importation if (isset($info['group']) && !empty($info['group'])) { foreach (explode($this->multiple_value_separator, $info['group']) as $key => $group) { $group = trim($group); if (empty($group)) { continue; } $id_group = false; if (is_numeric($group) && $group) { $my_group = new Group((int) $group); if (Validate::isLoadedObject($my_group)) { $customer_groups[] = (int) $group; } continue; } $my_group = Group::searchByName($group); if (isset($my_group['id_group']) && $my_group['id_group']) { $id_group = (int) $my_group['id_group']; } if (!$id_group) { $my_group = new Group(); $my_group->name = array($id_lang => $group); if ($id_lang != $default_language_id) { $my_group->name = $my_group->name + array($default_language_id => $group); } $my_group->price_display_method = 1; $my_group->add(); if (Validate::isLoadedObject($my_group)) { $id_group = (int) $my_group->id; } } if ($id_group) { $customer_groups[] = (int) $id_group; } } } elseif (empty($info['group']) && isset($customer->id) && $customer->id) { $customer_groups = array(0 => Configuration::get('PS_CUSTOMER_GROUP')); } AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $customer); if ($customer->passwd) { $customer->passwd = Tools::encrypt($customer->passwd); } $id_shop_list = explode($this->multiple_value_separator, $customer->id_shop); $customers_shop = array(); $customers_shop['shared'] = array(); $default_shop = new Shop((int) Configuration::get('PS_SHOP_DEFAULT')); if (Shop::isFeatureActive() && $id_shop_list) { foreach ($id_shop_list as $id_shop) { if (empty($id_shop)) { continue; } $shop = new Shop((int) $id_shop); $group_shop = $shop->getGroup(); if ($group_shop->share_customer) { if (!in_array($group_shop->id, $customers_shop['shared'])) { $customers_shop['shared'][(int) $id_shop] = $group_shop->id; } } else { $customers_shop[(int) $id_shop] = $group_shop->id; } } } else { $default_shop = new Shop((int) Configuration::get('PS_SHOP_DEFAULT')); $default_shop->getGroup(); $customers_shop[$default_shop->id] = $default_shop->getGroup()->id; } //set temporally for validate field $customer->id_shop = $default_shop->id; $customer->id_shop_group = $default_shop->getGroup()->id; if (isset($info['id_default_group']) && !empty($info['id_default_group']) && !is_numeric($info['id_default_group'])) { $info['id_default_group'] = trim($info['id_default_group']); $my_group = Group::searchByName($info['id_default_group']); if (isset($my_group['id_group']) && $my_group['id_group']) { $info['id_default_group'] = (int) $my_group['id_group']; } } $my_group = new Group($customer->id_default_group); if (!Validate::isLoadedObject($my_group)) { $customer->id_default_group = (int) Configuration::get('PS_CUSTOMER_GROUP'); } $customer_groups[] = (int) $customer->id_default_group; $customer_groups = array_flip(array_flip($customer_groups)); $res = true; if (($field_error = $customer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $customer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { foreach ($customers_shop as $id_shop => $id_group) { $customer->force_id = (bool) Tools::getValue('forceIDs'); if ($id_shop == 'shared') { foreach ($id_group as $key => $id) { $customer->id_shop = (int) $key; $customer->id_shop_group = (int) $id; if ($customer_exist && ($current_id_shop_group == $id || in_array($current_id_shop, ShopGroup::getShopsFromGroup($id)))) { $customer->id = $current_id_customer; $res &= $customer->update(); } else { $res &= $customer->add(); if (isset($addresses)) { foreach ($addresses as $address) { $address['id_customer'] = $customer->id; unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']); Db::getInstance()->insert('address', $address); } } } if ($res && isset($customer_groups)) { $customer->updateGroup($customer_groups); } } } else { $customer->id_shop = $id_shop; $customer->id_shop_group = $id_group; if ($customer_exist && $id_shop == $current_id_shop) { $customer->id = $current_id_customer; $res &= $customer->update(); } else { $res &= $customer->add(); if (isset($addresses)) { foreach ($addresses as $address) { $address['id_customer'] = $customer->id; unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']); Db::getInstance()->insert('address', $address); } } } if ($res && isset($customer_groups)) { $customer->updateGroup($customer_groups); } } } } unset($customer_groups); $customer_exist = false; if (!$res) { $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $info['email'], isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null'); $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } $this->closeCsvFile($handle); }
private function getCustomersInfo() { $customer_orders = array(); $customer_addresses = array(); $query_limit = 0; $query_offset = 0; if ($this->page !== null && !empty($this->page) && $this->show !== null && !empty($this->show)) { $query_limit = ((int) $this->page - 1) * (int) $this->show; $query_offset = (int) $this->show; } $customer = new Customer((int) $this->user_id); // Get all cutomer addresses $addresses = $customer->getAddresses($this->def_lang); foreach ($addresses as $address) { $customer_addresses[] = array('dni' => $address['dni'], 'alias' => $address['alias'], 'first_name' => $address['firstname'], 'last_name' => $address['lastname'], 'company' => $address['company'], 'vat_number' => $address['vat_number'], 'address1' => $address['address1'], 'address2' => $address['address2'], 'postcode' => $address['postcode'], 'city' => $address['city'], 'country' => $address['country'], 'state' => $address['state'], 'phone' => $address['phone'], 'phone_mobile' => $address['phone_mobile'], 'other' => $address['other']); } // Get customer general information $customer_info = array('id_customer' => $customer->id, 'firstname' => $customer->firstname, 'lastname' => $customer->lastname, 'date_add' => $customer->date_add, 'email' => $customer->email); // Get customer orders $customer_orders_obj = new DbQuery(); $customer_orders_obj->select(' o.id_order, o.date_add, o.total_paid, o.id_currency, osl.name AS ord_status, c.iso_code, c.sign, c.format, SUM(od.product_quantity) AS pr_qty '); $customer_orders_obj->from('orders', 'o'); $customer_orders_obj->leftJoin('currency', 'c', 'o.id_currency = c.id_currency'); $customer_orders_obj->leftJoin('order_detail', 'od', 'od.id_order = o.id_order'); $customer_orders_obj->leftJoin('order_state_lang', 'osl', 'osl.id_order_state = o.current_state AND osl.id_lang = ' . (int) $this->def_lang); $customer_orders_obj->where('o.id_customer = ' . (int) $this->user_id); $customer_orders_obj->groupBy('o.id_order'); $customer_orders_obj->orderBy('o.id_order DESC'); $customer_orders_obj->limit($query_offset, $query_limit); $customer_orders_sql = $customer_orders_obj->build(); $customer_orders_res = Db::getInstance()->executeS($customer_orders_sql); foreach ($customer_orders_res as $customer_order) { if ($this->currency_code != $customer_order['id_currency']) { $customer_order['total_paid'] = $this->convertPrice($customer_order['total_paid'], $customer_order['id_currency']); } $customer_order['total_paid'] = $this->displayPrice($customer_order['total_paid'], $customer_order['id_currency']); unset($customer_order['id_currency']); $customer_orders[] = $customer_order; } // Get count of orders for customer $customer_orders_count_obj = new DbQuery(); $customer_orders_count_obj->select(' COUNT(o.id_order) AS count_ords, SUM(o.total_paid/o.conversion_rate) AS sum_ords '); $customer_orders_count_obj->from('orders', 'o'); $customer_orders_count_obj->where('o.id_customer = ' . (int) $this->user_id); $customer_orders_count_sql = $customer_orders_count_obj->build(); $customer_orders_count_res = Db::getInstance()->executeS($customer_orders_count_sql); $customer_orders_count = array_shift($customer_orders_count_res); if ($this->currency_code != $this->def_currency) { $customer_orders_count['sum_ords'] = $this->convertPrice($customer_orders_count['sum_ords'], $this->def_currency); } $customer_orders_count['sum_ords'] = $this->displayPrice($customer_orders_count['sum_ords'], $this->currency_code, true); return array('user_info' => $customer_info, 'addresses' => $customer_addresses, 'customer_orders' => $customer_orders, 'c_orders_count' => (int) $customer_orders_count['count_ords'], 'sum_ords' => $customer_orders_count['sum_ords']); }
public function hookPayment($params) { if (!$this->active) { return; } // Verify if customer has memorized tokens $cart = $this->context->cart; $tokens = HipayToken::getTokens($cart->id_customer); // Retrieve list of tokens if (isset($tokens['0'])) { $token_display = 'true'; } else { $token_display = 'false'; } if (_PS_VERSION_ >= '1.5') { // Get invoice Country $customer = new Customer((int) $cart->id_customer); $customerInfo = $customer->getAddresses((int) $cart->id_lang); foreach ($customerInfo as $key => $value) { if ($value['id_address'] == $cart->id_address_invoice) { $invoice_country = HipayClass::getCountryCode($value['country']); } } } // End Get invoice country // Verify if systems should display memorized tokens $allow_memorize = HipayClass::getShowMemorization(); // If both are true, activate additional info to allow payment via existing token if ($allow_memorize == 'true') { $currency_array = $this->getCurrency((int) $cart->id_currency); $currency = $currency_array[0]['iso_code']; foreach ($currency_array as $value) { if ($value['id_currency'] == $cart->id_currency) { $actual_currency = $value['iso_code']; } } if ($currency != $actual_currency) { $currency = $actual_currency; } $this->context->smarty->assign(array('cart_id' => $cart->id, 'currency' => $currency, 'amount' => $cart->getOrderTotal(true, Cart::BOTH))); } // Create dynamic payment button $card_str = Configuration::get('HIPAY_ALLOWED_CARDS'); // Cards filter by country if ($invoice_country != 'FR') { $card_str = str_replace('cb', '', $card_str); } if ($invoice_country != 'BE') { $card_str = str_replace('bcmc', '', $card_str); } $cart_arr = explode(',', $card_str); $card_currency = Configuration::get('HIPAY_CURRENCY_CARDS'); $card_curr_val = array(); if (Tools::strlen($card_currency) > 3) { $currency_array = $this->getCurrency((int) $cart->id_currency); $currency = $currency_array[0]['iso_code']; foreach ($currency_array as $value) { if ($value['id_currency'] == $cart->id_currency) { $actual_currency = $value['iso_code']; } } $card_currency_arr = explode(',', Tools::substr($card_currency, 1, -1)); foreach ($card_currency_arr as $value) { foreach ($cart_arr as $cardvalue) { if ($value == '"' . $actual_currency . '-' . $cardvalue . '"') { $card_curr_val[$cardvalue] = true; } } } } else { foreach ($cart_arr as $cardvalue) { $card_curr_val[$cardvalue] = true; } } $btn_image = ''; $card_currency_ok = '0'; $payment_product_list_upd = ''; $count_ccards = 0; foreach ($cart_arr as $value) { if ($value == 'visa' && $card_curr_val['visa']) { $btn_image .= '<img class= "hipay_method" src="' . _MODULE_DIR_ . $this->name . '/img/visa_small.png" alt="Visa" />'; $card_currency_ok = '1'; $payment_product_list_upd .= 'visa,'; $count_ccards++; } if ($value == 'mastercard' && $card_curr_val['mastercard']) { $btn_image .= '<img class= "hipay_method" src="' . _MODULE_DIR_ . $this->name . '/img/mc_small.png" alt="MasterCard" />'; $card_currency_ok = '1'; $payment_product_list_upd .= 'mastercard,'; $count_ccards++; } if ($value == 'american-express' && $card_curr_val['american-express']) { $btn_image .= '<img class= "hipay_method" src="' . _MODULE_DIR_ . $this->name . '/img/amex_small.png" alt="American Express" />'; $card_currency_ok = '1'; $payment_product_list_upd .= 'american-express,'; $count_ccards++; } if ($value == 'bcmc' && $card_curr_val['bcmc']) { $btn_image .= '<img class= "hipay_method" src="' . _MODULE_DIR_ . $this->name . '/img/bcmc_small.png" alt="Bancontact / Mister Cash" />'; $card_currency_ok = '1'; $payment_product_list_upd .= 'bcmc,'; $count_ccards++; } if ($value == 'cb' && $card_curr_val['cb']) { $btn_image .= '<img class= "hipay_method" src="' . _MODULE_DIR_ . $this->name . '/img/cb_small.png" alt="CB" />'; $card_currency_ok = '1'; $payment_product_list_upd .= 'cb,'; $count_ccards++; } if ($value == 'maestro' && $card_curr_val['maestro']) { $btn_image .= '<img class= "hipay_method" src="' . _MODULE_DIR_ . $this->name . '/img/maestro_small.png" alt="Maestro" />'; $card_currency_ok = '1'; $payment_product_list_upd .= 'maestro,'; $count_ccards++; } } // Assign smarty variables $this->context->smarty->assign(array('hipay_ssl' => Configuration::get('PS_SSL_ENABLED'), 'token_display' => $token_display, 'allow_memorize' => $allow_memorize, 'tokens' => $tokens, 'payment_mode' => Configuration::get('HIPAY_PAYMENT_MODE'), 'PS_VERSION' => _PS_VERSION_, 'btn_image' => $btn_image, 'card_currency_ok' => $card_currency_ok, 'payment_product_list_upd' => $payment_product_list_upd, 'count_ccards' => $count_ccards)); // Assign paths $this->smarty->assign(array('this_path' => $this->_path, 'this_path_bw' => $this->_path, 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/')); // Local cards variables $localPayments = Tools::jsonDecode(Configuration::get('HIPAY_LOCAL_PAYMENTS')); $local_cards = $this->checkLocalCards(); // Retrieving images and storing in any array associate to the card code. $local_cards_img = array(); $local_cards_name = array(); $show_cards = array(); if (count($local_cards)) { $currency_array = $this->getCurrency((int) $cart->id_currency); $currency = $currency_array[0]['iso_code']; foreach ($currency_array as $value) { if ($value['id_currency'] == $cart->id_currency) { $actual_currency = $value['iso_code']; } } foreach ($local_cards as $value) { $local_cards_img[(string) $value->code] = (string) $value->image; $local_cards_name[(string) $value->code] = (string) $value->name; // Get local card country $local_cards_countries[(string) $value->code] = (string) $value->countries; // End Get local card country $show_cards[(string) $value->code] = 'false'; // Initialize to false // Assigning temporary code to variable $card_code = (string) $value->code; foreach ($value->currencies as $value) { foreach ($value->iso_code as $value) { if (Tools::strtoupper($actual_currency) == Tools::strtoupper((string) $value)) { $show_cards[$card_code] = 'true'; // Update to true } } } // Check local card country if (strpos($local_cards_countries[$card_code], $invoice_country) === false && $local_cards_countries[$card_code] != 'ALL') { $show_cards[$card_code] = 'false'; } // End Check local card country } } if (count($localPayments)) { $allow_local_cards = 'true'; } else { $allow_local_cards = 'false'; } $this->smarty->assign(array('allow_local_cards' => $allow_local_cards, 'local_cards_list' => $localPayments, 'local_cards_img' => $local_cards_img, 'local_cards_name' => $local_cards_name, 'show_cards' => $show_cards)); // modif One Page Checkout // Check if cart is in OPC $is_opc = Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'true' : 'false'; $id_opc = ''; // Set id_opc to empty by default if ($is_opc == 'true') { $id_opc = 'OPC'; // This will update hidden field 'ioBB' to 'ioBBOPC' to prevent duplicate id } // Add generic smarty variables; $this->smarty->assign(array('id_opc' => $id_opc)); return $this->display(__FILE__, 'payment.tpl'); }
/** * Function DO HOOK */ public function doHook($params) { if ($this->_allowToWork == false) { return; } $customer = new Customer($params['cart']->id_customer); $currency = new Currency($params['cart']->id_currency); $address = $customer->getAddresses($params['cart']->id_lang); $address = $address[0]; // for 1.3 compatibility $type_both = 3; $type_only_shipping = 5; $tva = $params['cart']->getOrderTotal(true, $type_both) - $params['cart']->getOrderTotal(false, $type_both); $tax = $tva * 100 / $params['cart']->getOrderTotal(true, $type_both); $params_to_twenga = array(); $params_to_twenga['total_ht'] = $params['cart']->getOrderTotal(false, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING); $params_to_twenga['basket_id'] = $params['cart']->id; $params_to_twenga['currency'] = $currency->iso_code; $params_to_twenga['total_ttc'] = $params['cart']->getOrderTotal(true, Twenga::BOTH); $params_to_twenga['shipping'] = $params['cart']->getOrderTotal(true, Twenga::ONLY_SHIPPING); $params_to_twenga['tax'] = Tools::ps_round($tax, 2); $params_to_twenga['tva'] = $tva; $params_to_twenga['cli_firstname'] = $customer->firstname; $params_to_twenga['cli_lastname'] = $customer->lastname; $params_to_twenga['cli_city'] = $address['city']; $params_to_twenga['cli_state'] = $address['state']; $params_to_twenga['cli_country'] = $address['country']; $params_to_twenga['items'] = array(); foreach ($params['cart']->getProducts() as $product) { $arr_item = array(); if ($product['total'] != '') { $arr_item['total_ht'] = (double) $product['total']; } if ($product['cart_quantity'] != '') { $arr_item['quantity'] = (int) $product['cart_quantity']; } if ($product['reference'] != '') { $arr_item['sku'] = (string) $product['reference']; } if ($product['name'] != '') { $arr_item['name'] = (string) $product['name']; } if ($product['category']) { $arr_item['category_name'] = (string) $product['category']; } $params_to_twenga['items'][] = $arr_item; } $params_to_twenga = array_filter($params_to_twenga); try { // twenga don't saved double orders with the same id, // so don't need to use TwengaObj::orderExist() method. $tracking_code = self::$obj_twenga->getTrackingScript($params_to_twenga); return $tracking_code; } catch (TwengaFieldsException $e) { return $this->l('Error occurred when params passed in Twenga API') . ' : <br />' . $e->getMessage(); } catch (Exception $e) { return $e->getMessage(); } }
public function agilepaypal_subscribe() { global $cookie, $cart, $smarty, $defaultCountry; $error_msg = ''; $paypal = new AgilePaypal(); $cart = new Cart(intval($cookie->id_cart)); $expresscheckoutkey = md5(_PS_VERSION_ . $cookie->id_cart); $cycle_base = Tools::getValue('sl_agilepaypalexpress_cycle_base'); $cycle = Tools::getValue('sl_agilepaypalexpress_cycle'); $cycle_list = array('D', 'W', 'M', 'Y'); if (!in_array($cycle, $cycle_list)) { $error_msg .= $paypal->getL('Recurring cycle error: (invalid or recurring cycle)') . "<BR>"; } $cycle_num = Tools::getValue('sl_agilepaypalexpress_cycle_num'); $address_override = 0; $islogged = Context::getContext()->customer->isLogged(); if ($islogged) { $customer = new Customer(intval($cart->id_customer)); $addresses = $customer->getAddresses($cookie->id_lang); if (!empty($addresses)) { $id_address = 0; foreach ($addresses as $addr) { if (intval($cart->id_address_delivery) == intval($addr['id_address'])) { $id_address = intval($addr['id_address']); break; } } if ($id_address > 0) { $address = new Address($id_address); } else { $address = new Address($addresses[0]['id_address']); } } } if (!isset($address) or !$address->id_country) { $address = new Address(); $address->id_country = intval(Tools::getValue('sl_expresscheckout_id_country')); } if (!isset($address) or !$address->id_country) { $address = new Address(); $address->id_country = (int) Configuration::get('PS_COUNTRY_DEFAULT'); } $country = new Country(intval($address->id_country)); $zone = new Zone(intval($country->id_zone)); $doSubmit = ($country->active == 1 and $zone->active == 1 or $cart->isVirtualCart()); $state = NULL; if ($address->id_state) { $state = new State(intval($address->id_state)); } if ($islogged) { $customer = new Customer(intval($cart->id_customer)); } else { $customer = new Customer(); $customer->secure_key = md5(uniqid(rand(), true)); } $business = $paypal->getSellerPaypalEmailAddress(); $header = Configuration::get('AGILE_PAYPAL_HEADER'); $currency_order = new Currency(intval($cart->id_currency)); $currency_module = new Currency((int) Configuration::get('AGILE_PAYPAL_CURRENCY')); if (!Validate::isEmail($business)) { $error_msg .= $paypal->getL('Paypal error: (invalid or undefined business account email)') . "<BR>"; } if (!Validate::isLoadedObject($currency_module)) { $error_msg .= $paypal->getL('Currency Restriction: (Invalid currency restriction setting for this module)') . "<BR>"; } $customercurrency = $cookie->id_currency; $defaultCountryAgile = $defaultCountry; $defaultCountry = $country; $the_rate = $currency_order->conversion_rate / $currency_module->conversion_rate; $cartproducts = $cart->getProducts(); $product1st = $cartproducts[0]; $all_total = $cart->getOrderTotal(true, Cart::BOTH); $business2 = $paypal->getSellerPaypalMicroEmailAddress(); $micro_amount = floatval(Configuration::get('AGILE_PAYPAL_MICRO_AMOUNT')); if (isset($business2) and strlen(trim($business2)) > 0 and isset($micro_amount) and floatval($micro_amount) > 0 and floatval($all_total) <= $micro_amount) { $business = $business2; } if (_PS_VERSION_ > '1.5') { $shipping = Tools::ps_round(floatval($cart->getOrderTotal(true, Cart::ONLY_SHIPPING)), 2); } else { $shipping = Tools::ps_round(floatval($cart->getOrderShippingCost()) + floatval($cart->getOrderTotal(true, Cart::ONLY_WRAPPING)), 2); } if (!empty($error_msg)) { $doSubmit = 0; } $smarty->assign(array('redirect_text' => $paypal->getL($doSubmit == 1 ? 'Please wait, redirecting to Paypal... Thanks.' : 'Sorry, we do not ship to your country.'), 'cancel_text' => $paypal->getL('Cancel'), 'cart_text' => $paypal->getL('My cart'), 'return_text' => $paypal->getL('Return to shop'), 'paypal_url' => $paypal->getPaypalUrl(), 'address' => $address, 'country' => $country, 'state' => $state, 'doSubmit' => $doSubmit, 'baseUrl' => __PS_BASE_URI__, 'address_override' => $address_override, 'amount' => floatval($cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING)), 'customer' => $customer, 'all_total' => $all_total, 'shipping' => $shipping, 'discount' => abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS)), 'business' => $business, 'currency_module' => $currency_module, 'cart_id' => intval($cart->id), 'products' => $cartproducts, 'product1st' => $product1st, 'paypal_id' => intval($paypal->id), 'invoice' => intval(Configuration::get('AGILE_MS_PAYMENT_MODE')), 'header' => $header, 'cycle_base' => $cycle_base, 'cycle' => $cycle, 'cycle_num' => $cycle_num, 'expresscheckoutkey' => $expresscheckoutkey, 'PS_ALLOW_MOBILE_DEVICE' => 0, 'agile_url' => (_PS_VERSION_ > '1.4' ? Tools::getShopDomainSsl(true, true) : Tools::getHttpHost(true, true)) . __PS_BASE_URI__, 'agilepaypal_return_url' => $this->get_return_url(), 'error_msg' => $error_msg, 'the_rate' => $the_rate)); $cookie->id_currency = $customercurrency; $defaultCountry = $defaultCountryAgile; }
public function sendSMStoClient($id_customer, $id_order, $msg) { $mobile = ''; $error = $this->l('Error : SMS not send!'); $status = "erro"; $customer = new Customer($id_customer); $address = $customer->getAddresses($customer->id_lang); foreach ($address as $key => $addr) { if (!empty($addr['phone_mobile'])) { $mobile = $this->mobileProcess($addr['phone_mobile'], $addr['id_country']); break; } } if (!empty($mobile)) { if ($this->sendSMS($mobile, $msg)) { $status = "ok"; $error = ""; $this->updatemanualmsg($id_customer, $id_order, $msg); } } return Tools::jsonEncode(array('status' => $status, 'error' => $error)); }
public function hookDisplayProductButtons($params) { $productId = (int) Tools::getValue('id_product'); $indexval = Db::getInstance()->getValue("SELECT `id_customization_field` FROM `" . _DB_PREFIX_ . "customization_field` WHERE `id_product` = {$productId} AND `type` = 1"); $pp_values = (string) Tools::getValue('values'); if (Tools::getValue('clear') == true) { $this->context->cart->deleteCustomizationToProduct($productId, (int) $indexval); die; } if (!empty($pp_values)) { if (!$this->context->cart->id && isset($_COOKIE[$this->context->cookie->getName()])) { $this->context->cart->add(); $this->context->cookie->id_cart = (int) $this->context->cart->id; } $this->context->cart->addPictureToProduct($productId, (int) $indexval, 1, $pp_values); } else { $pp_values = $this->context->cart->getProductCustomization($productId, (int) $indexval, true); if (!empty($pp_values)) { $pp_values = $pp_values[0]['value']; } } $pp_previews = ''; $pp_mode = 'new'; $pp_project_id = ''; $opt_ = is_string($pp_values) ? json_decode(rawurldecode($pp_values), true) : $pp_values; if (!empty($opt_)) { if ($opt_['type'] === 'u') { $pp_previews = $opt_['previews']; $pp_upload_ready = true; $pp_mode = 'upload'; } else { if ($opt_['type'] === 'p') { $pp_mode = 'edit'; $pp_project_id = $opt_['projectId']; $pp_previews = $opt_['numPages']; } } } $pp_design_options = unserialize(Configuration::get(PITCHPRINT_P_DESIGNS)); $ppa_productValues = isset($pp_design_options[$productId]) ? $pp_design_options[$productId] : ''; $pp_apiKey = Configuration::get(PITCHPRINT_API_KEY); $pp_jscript = Configuration::get(PITCHPRINT_JSCRIPT); $pp_css = Configuration::get(PITCHPRINT_CSS); $pp_inline = Configuration::get(PITCHPRINT_INLINE); $pp_auto_show = Configuration::get(PITCHPRINT_AUTO_SHOW); $pp_show_images = Configuration::get(PITCHPRINT_SHOW_IMAGES); $ppa_designValuesArray = explode(':', $ppa_productValues); if (Tools::getValue('ajax') == true) { die; } if (!is_string($pp_values)) { $pp_values = json_encode($pp_values, true); } $userData = ''; if ($this->context->customer->isLogged()) { $fname = addslashes($this->context->cookie->customer_firstname); $lname = addslashes($this->context->cookie->customer_lastname); $cus = new Customer((int) $this->context->cookie->id_customer); $cusInfo = $cus->getAddresses((int) Configuration::get('PS_LANG_DEFAULT')); $cusInfo = $cusInfo[0]; $addr = "{$cusInfo['address1']}<br>"; if (!empty($cusInfo['address2'])) { $addr .= "{$cusInfo['address2']}<br>"; } $addr .= "{$cusInfo['city']} {$cusInfo['postcode']}<br>"; if (!empty($cusInfo['state'])) { $addr .= "{$cusInfo['state']}<br>"; } $addr .= "{$cusInfo['country']}"; $addr = trim($addr); $userData = ",\n\t\t\t\tuserData: {\n\t\t\t\t\temail: '{$this->context->cookie->email}',\n\t\t\t\t\tname: '{$fname} {$lname}',\n\t\t\t\t\tfirstname: '{$fname}',\n\t\t\t\t\tlastname: '{$lname}',\n\t\t\t\t\ttelephone: '{$cusInfo['phone']}',\n\t\t\t\t\tfax: '',\n\t\t\t\t\taddress: '" . addslashes($addr) . "'.split('<br>').join('\\n')\n\t\t\t\t}"; } return !empty($ppa_productValues) ? "\n <style>\n /*Custom CSS Style*/\n {$pp_css}\n </style>\n \n \n <script type=\"text/javascript\">\n\t\t\tajaxsearch = undefined;\n\t\t\t\n\t\t\tif (typeof PPCLIENT === 'undefined') {\n\t\t\t\tvar PPCLIENT = {};\n\t\t\t}\n \n\t\t\tPPCLIENT.vars = {\n\t\t\t\tclient: 'ps',\n\t\t\t\tuploadUrl: '" . _PS_BASE_URL_ . __PS_BASE_URI__ . "modules/pitchprint/uploads/',\n\t\t\t\tbaseUrl: '" . SERVER_URLPATH . "',\n\t\t\t\tappApiUrl: '" . SERVER_URLPATH . "/api/front/',\n\t\t\t\trscCdn: '" . SERVER_RSCCDN . "',\n\t\t\t\trscBase: '" . SERVER_RSCBASE . "',\n\t\t\t\tfunctions: { },\n\t\t\t\t\n\t\t\t\tcValues: '{$pp_values}',\n\t\t\t\tprojectId: '{$pp_project_id}',\n\t\t\t\tuserId: '{$this->context->cookie->id_customer}',\n\t\t\t\tpreviews: '{$pp_previews}',\n\t\t\t\tmode: '{$pp_mode}',\n\t\t\t\tlangCode: '{$this->context->language->iso_code}',\n\t\t\t\thideCartButton: {$ppa_designValuesArray[2]},\n\t\t\t\tenableUpload: {$ppa_designValuesArray[1]},\n\t\t\t\tdesignId: '{$ppa_designValuesArray[0]}',\n\t\t\t\tinline: '{$pp_inline}',\n\t\t\t\tmaintainImages: {$pp_show_images},\n\t\t\t\tautoShow: {$pp_auto_show},\n\t\t\t\tapiKey: '{$pp_apiKey}',\n\t\t\t\tpageName : '',\n\t\t\t\tproduct: {\n\t\t\t\t\tid: '{$productId}',\n\t\t\t\t\tname: '" . addslashes($params['product']->name) . "'\n\t\t\t\t}{$userData}\n\t\t\t}\n\t\t\t\n //Custom Javascript...\n \n\t\t\t{$pp_jscript}\n\t\t\t\n\t\t\twindow.onload = function() {\n\t\t\t\tif (typeof PPCLIENT.init === 'function') {\n\t\t\t\t\tPPCLIENT.start();\n\t\t\t\t\tPPCLIENT.init();\n\t\t\t\t}\n\t\t\t}\n </script>" : ""; }
protected function afterDelete($object, $old_id) { $customer = new Customer($old_id); $addresses = $customer->getAddresses($this->default_form_language); foreach ($addresses as $k => $v) { $address = new Address($v['id_address']); $address->id_customer = $object->id; $address->save(); } return true; }
private function getUserProfileData($cart) { $customer = new Customer((int) $cart->id_customer); $address = $customer->getAddresses((int) $this->context->language->id); $address = $address[0]; return array('customer[city]' => $address['city'], 'customer[state]' => $address['state'], 'customer[address]' => $address['address1'], 'customer[country]' => $address['country'], 'customer[zip]' => $address['postcode'], 'customer[firstname]' => $customer->firstname, 'customer[lastname]' => $customer->lastname, 'email' => $customer->email); }
public function hookPayment($params) { if ($this->_allowToWork == false) { return; } // One page Checkout cause problem with event and document.write use by twenga script // (page completely deleted if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { return; } $customer = new Customer($params['cart']->id_customer); $currency = new Currency($params['cart']->id_currency); $address = $customer->getAddresses($params['cart']->id_lang); $address = $address[0]; // for 1.3 compatibility $type_both = 3; $type_only_shipping = 5; /* const ONLY_PRODUCTS = 1; const ONLY_DISCOUNTS = 2; const BOTH = 3; const BOTH_WITHOUT_SHIPPING = 4; const ONLY_SHIPPING = 5; const ONLY_WRAPPING = 6; const ONLY_PRODUCTS_WITHOUT_SHIPPING = 7; */ $tva = $params['cart']->getOrderTotal(true, $type_both) - $params['cart']->getOrderTotal(false, $type_both); $tax = $tva * 100 / $params['cart']->getOrderTotal(true, $type_both); $params_to_twenga = array(); // @todo delete or not ?? // $params_to_twenga['user_id'] = $customer->id; // $params_to_twenga['cli_email'] = $customer->email; $params_to_twenga['total_ht'] = $params['cart']->getOrderTotal(false, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING); $params_to_twenga['basket_id'] = $params['cart']->id; $params_to_twenga['currency'] = $currency->iso_code; $params_to_twenga['total_ttc'] = $params['cart']->getOrderTotal(true, Twenga::BOTH); $params_to_twenga['shipping'] = $params['cart']->getOrderTotal(true, Twenga::ONLY_SHIPPING); $params_to_twenga['tax'] = Tools::ps_round($tax, 2); $params_to_twenga['tva'] = $tva; $params_to_twenga['cli_firstname'] = $customer->firstname; $params_to_twenga['cli_lastname'] = $customer->lastname; $params_to_twenga['cli_city'] = $address['city']; $params_to_twenga['cli_state'] = $address['state']; $params_to_twenga['cli_country'] = $address['country']; $params_to_twenga['items'] = array(); foreach ($params['cart']->getProducts() as $product) { $arr_item = array(); if ($product['total'] != '') { $arr_item['total_ht'] = (double) $product['total']; } if ($product['cart_quantity'] != '') { $arr_item['quantity'] = (int) $product['cart_quantity']; } if ($product['reference'] != '') { $arr_item['sku'] = (string) $product['reference']; } if ($product['name'] != '') { $arr_item['name'] = (string) $product['name']; } if ($product['category']) { $arr_item['category_name'] = (string) $product['category']; } $params_to_twenga['items'][] = $arr_item; } $params_to_twenga = array_filter($params_to_twenga); try { // twenga don't saved double orders with the same id, // so don't need to use TwengaObj::orderExist() method. $tracking_code = self::$obj_twenga->getTrackingScript($params_to_twenga); return $tracking_code; } catch (TwengaFieldsException $e) { return $this->l('Error occurred when params passed in Twenga API') . ' : <br />' . $e->getMessage(); } catch (Exception $e) { return $e->getMessage(); } }
/** * Manage address */ public function processAddress() { $customer = new Customer(); if (!Tools::getValue('email')) { return true; } if (!$customer->getByEmail(Tools::getValue('email'))) { $_POST['passwd'] = md5(time() . _COOKIE_KEY_); $this->errors += $customer->validateController(); $customer->active = 1; if (empty($this->errors) && !$customer->add()) { $this->errors[] = Tools::displayError('An error occurred while creating your account.'); } } $addresses = $customer->getAddresses($this->context->language->id); $id_address = null; foreach ($addresses as $address) { if ($address['firstname'] != $_POST['firstname']) { continue; } if ($address['lastname'] != $_POST['lastname']) { continue; } if (isset($_POST['city'])) { if ($address['city'] != $_POST['city']) { continue; } } if ($address['phone'] != $_POST['phone']) { continue; } $id_address = $address['id_address']; break; } if (!$id_address) { $address = new Address(); $address->id_customer = $customer->id; $_POST['id_country'] = 177; $_POST['alias'] = 'Address ' + count($addresses) + 1; $_POST['address1'] = 'some address'; $_POST['city'] = 'some city'; $this->errors += $address->validateController(); if (empty($this->errors) && !$address->add()) { $this->errors[] = Tools::displayError('An error occurred while creating your account.'); } else { $id_address = $address->id; $data = array(); $data['email'] = $customer->email; $data['firstname'] = $customer->firstname; $data['lastname'] = $customer->lastname; $data['ip_registration_newsletter'] = !empty($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : $_SERVER['REMOTE_ADDR']; $data['newsletter_date_add'] = date("d.m.y"); $data['phone'] = $address->phone; function charset($str) { if (!$str) { exit; } $charset = mb_detect_encoding($str, "auto"); if ($charset != "UTF-8") { $str = iconv($charset, 'utf-8', $str); } return $str; } //ключ доступа к API (из Личного Кабинета) $api_key = "58priw95sdjt7umw17ixbnkkkudtoq5u7nmfcacy"; // Список контактов $list = "4734062"; //dev-etagerca $POST = array('api_key' => $api_key, 'field_names[0]' => 'email', 'field_names[1]' => 'Name', 'field_names[2]' => 'email_request_ip', 'field_names[3]' => 'email_add_time', 'field_names[4]' => 'phone', 'field_names[5]' => 'email_list_ids'); for ($i = 0; $i < 1; $i++) { $POST['data[' . $i . '][0]'] = $data['email']; $POST['data[' . $i . '][1]'] = charset($data['firstname']) . ' ' . charset($data['lastname']); $POST['data[' . $i . '][2]'] = $data['ip_registration_newsletter']; $POST['data[' . $i . '][3]'] = $data['newsletter_date_add']; $POST['data[' . $i . '][4]'] = $data['phone']; $POST['data[' . $i . '][5]'] = $list; } $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $POST); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_URL, 'http://api.unisender.com/ru/api/importContacts?format=json'); $result = curl_exec($ch); // if ($result) { // // Раскодируем ответ API-сервера // $jsonObj = json_decode($result); // // if(null===$jsonObj) { // // Ошибка в полученном ответе // echo "Invalid JSON"; // // } // elseif(!empty($jsonObj->error)) { // // Ошибка импорта // echo("An error occured: " . $jsonObj->error . "(code: " . $jsonObj->code . ")"); // // } else { // // Новые подписчики успешно добавлены // echo("Success! Added " . $jsonObj->result->new_emails . " new e-mail addresses"); // // } // } else { // // Ошибка соединения с API-сервером // echo("API access error"); // } } } $this->context->cookie->id_customer = $customer->id; $this->context->cart->id_customer = $customer->id; $this->context->cart->id_address_delivery = $id_address; $this->context->cart->id_address_invoice = $id_address; /* if (!Tools::getValue('multi-shipping')) $this->context->cart->setNoMultishipping(); $same = Tools::isSubmit('same'); if(!Tools::getValue('id_address_invoice', false) && !$same) $same = true; if (!Customer::customerHasAddress($this->context->customer->id, (int)Tools::getValue('id_address_delivery')) || (!$same && Tools::getValue('id_address_delivery') != Tools::getValue('id_address_invoice') && !Customer::customerHasAddress($this->context->customer->id, (int)Tools::getValue('id_address_invoice')))) $this->errors[] = Tools::displayError('Invalid address', !Tools::getValue('ajax')); else { $this->context->cart->id_address_delivery = (int)Tools::getValue('id_address_delivery'); $this->context->cart->id_address_invoice = $same ? $this->context->cart->id_address_delivery : (int)Tools::getValue('id_address_invoice'); CartRule::autoRemoveFromCart($this->context); CartRule::autoAddToCart($this->context); if (!$this->context->cart->update()) $this->errors[] = Tools::displayError('An error occurred while updating your cart.', !Tools::getValue('ajax')); if (!$this->context->cart->isMultiAddressDelivery()) $this->context->cart->setNoMultishipping(); // If there is only one delivery address, set each delivery address lines with the main delivery address if (Tools::isSubmit('message')) $this->_updateMessage(Tools::getValue('message')); // Add checking for all addresses $address_without_carriers = $this->context->cart->getDeliveryAddressesWithoutCarriers(); if (count($address_without_carriers) && !$this->context->cart->isVirtualCart()) { if (count($address_without_carriers) > 1) $this->errors[] = sprintf(Tools::displayError('There are no carriers that deliver to some addresses you selected.', !Tools::getValue('ajax'))); elseif ($this->context->cart->isMultiAddressDelivery()) $this->errors[] = sprintf(Tools::displayError('There are no carriers that deliver to one of the address you selected.', !Tools::getValue('ajax'))); else $this->errors[] = sprintf(Tools::displayError('There are no carriers that deliver to the address you selected.', !Tools::getValue('ajax'))); } } */ if ($this->errors) { if (Tools::getValue('ajax')) { die('{"hasError" : true, "errors" : ["' . implode('\',\'', $this->errors) . '"]}'); } $this->step = 1; } if ($this->ajax) { die(true); } }
public function ajaxPreProcess() { if ($this->tabAccess['edit'] === '1') { $id_customer = (int) Tools::getValue('id_customer'); $customer = new Customer((int) $id_customer); $this->context->customer = $customer; $id_cart = (int) Tools::getValue('id_cart'); if (!$id_cart) { $id_cart = $customer->getLastCart(false); } $this->context->cart = new Cart((int) $id_cart); if (!$this->context->cart->id) { $this->context->cart->recyclable = 0; $this->context->cart->gift = 0; } if (!$this->context->cart->id_customer) { $this->context->cart->id_customer = $id_customer; } if (Validate::isLoadedObject($this->context->cart) && $this->context->cart->OrderExists()) { return; } if (!$this->context->cart->secure_key) { $this->context->cart->secure_key = $this->context->customer->secure_key; } if (!$this->context->cart->id_shop) { $this->context->cart->id_shop = (int) $this->context->shop->id; } if (!$this->context->cart->id_lang) { $this->context->cart->id_lang = ($id_lang = (int) Tools::getValue('id_lang')) ? $id_lang : Configuration::get('PS_LANG_DEFAULT'); } if (!$this->context->cart->id_currency) { $this->context->cart->id_currency = ($id_currency = (int) Tools::getValue('id_currency')) ? $id_currency : Configuration::get('PS_CURRENCY_DEFAULT'); } $addresses = $customer->getAddresses((int) $this->context->cart->id_lang); $id_address_delivery = (int) Tools::getValue('id_address_delivery'); $id_address_invoice = (int) Tools::getValue('id_address_delivery'); if (!$this->context->cart->id_address_invoice && isset($addresses[0])) { $this->context->cart->id_address_invoice = (int) $addresses[0]['id_address']; } elseif ($id_address_invoice) { $this->context->cart->id_address_invoice = (int) $id_address_invoice; } if (!$this->context->cart->id_address_delivery && isset($addresses[0])) { $this->context->cart->id_address_delivery = $addresses[0]['id_address']; } elseif ($id_address_delivery) { $this->context->cart->id_address_delivery = (int) $id_address_delivery; } $this->context->cart->setNoMultishipping(); $this->context->cart->save(); $currency = new Currency((int) $this->context->cart->id_currency); $this->context->currency = $currency; } }
public function renderView() { $order = new Order(Tools::getValue('id_order')); if (!Validate::isLoadedObject($order)) { $this->errors[] = Tools::displayError('The order cannot be found within your database.'); } $customer = new Customer($order->id_customer); $carrier = new Carrier($order->id_carrier); $products = $this->getProducts($order); $currency = new Currency((int) $order->id_currency); // Carrier module call $carrier_module_call = null; if ($carrier->is_module) { $module = Module::getInstanceByName($carrier->external_module_name); if (method_exists($module, 'displayInfoByCart')) { $carrier_module_call = call_user_func(array($module, 'displayInfoByCart'), $order->id_cart); } } // Retrieve addresses information $addressInvoice = new Address($order->id_address_invoice, $this->context->language->id); if (Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state) { $invoiceState = new State((int) $addressInvoice->id_state); } if ($order->id_address_invoice == $order->id_address_delivery) { $addressDelivery = $addressInvoice; if (isset($invoiceState)) { $deliveryState = $invoiceState; } } else { $addressDelivery = new Address($order->id_address_delivery, $this->context->language->id); if (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state) { $deliveryState = new State((int) $addressDelivery->id_state); } } $this->toolbar_title = sprintf($this->l('Order #%1$d (%2$s) - %3$s %4$s'), $order->id, $order->reference, $customer->firstname, $customer->lastname); if (Shop::isFeatureActive()) { $shop = new Shop((int) $order->id_shop); $this->toolbar_title .= ' - ' . sprintf($this->l('Shop: %s'), $shop->name); } // gets warehouses to ship products, if and only if advanced stock management is activated $warehouse_list = null; $order_details = $order->getOrderDetailList(); foreach ($order_details as $order_detail) { $product = new Product($order_detail['product_id']); if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management) { $warehouses = Warehouse::getWarehousesByProductId($order_detail['product_id'], $order_detail['product_attribute_id']); foreach ($warehouses as $warehouse) { if (!isset($warehouse_list[$warehouse['id_warehouse']])) { $warehouse_list[$warehouse['id_warehouse']] = $warehouse; } } } } $payment_methods = array(); foreach (PaymentModule::getInstalledPaymentModules() as $payment) { $module = Module::getInstanceByName($payment['name']); if (Validate::isLoadedObject($module) && $module->active) { $payment_methods[] = $module->displayName; } } // display warning if there are products out of stock $display_out_of_stock_warning = false; $current_order_state = $order->getCurrentOrderState(); if (Configuration::get('PS_STOCK_MANAGEMENT') && (!Validate::isLoadedObject($current_order_state) || $current_order_state->delivery != 1 && $current_order_state->shipped != 1)) { $display_out_of_stock_warning = true; } // products current stock (from stock_available) foreach ($products as &$product) { $product['current_stock'] = StockAvailable::getQuantityAvailableByProduct($product['product_id'], $product['product_attribute_id'], $product['id_shop']); $resume = OrderSlip::getProductSlipResume($product['id_order_detail']); $product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity']; $product['amount_refundable'] = $product['total_price_tax_incl'] - $resume['amount_tax_incl']; $product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl'], $currency); $product['refund_history'] = OrderSlip::getProductSlipDetail($product['id_order_detail']); $product['return_history'] = OrderReturn::getProductReturnDetail($product['id_order_detail']); // if the current stock requires a warning if ($product['current_stock'] == 0 && $display_out_of_stock_warning) { $this->displayWarning($this->l('This product is out of stock: ') . ' ' . $product['product_name']); } if ($product['id_warehouse'] != 0) { $warehouse = new Warehouse((int) $product['id_warehouse']); $product['warehouse_name'] = $warehouse->name; } else { $product['warehouse_name'] = '--'; } } $gender = new Gender((int) $customer->id_gender, $this->context->language->id); $history = $order->getHistory($this->context->language->id); foreach ($history as &$order_state) { $order_state['text-color'] = Tools::getBrightness($order_state['color']) < 128 ? 'white' : 'black'; } // Smarty assign $this->tpl_view_vars = array('order' => $order, 'cart' => new Cart($order->id_cart), 'customer' => $customer, 'gender' => $gender, 'customer_addresses' => $customer->getAddresses($this->context->language->id), 'addresses' => array('delivery' => $addressDelivery, 'deliveryState' => isset($deliveryState) ? $deliveryState : null, 'invoice' => $addressInvoice, 'invoiceState' => isset($invoiceState) ? $invoiceState : null), 'customerStats' => $customer->getStats(), 'products' => $products, 'discounts' => $order->getCartRules(), 'orders_total_paid_tax_incl' => $order->getOrdersTotalPaid(), 'total_paid' => $order->getTotalPaid(), 'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id), 'customer_thread_message' => CustomerThread::getCustomerMessages($order->id_customer), 'orderMessages' => OrderMessage::getOrderMessages($order->id_lang), 'messages' => Message::getMessagesByOrderId($order->id, true), 'carrier' => new Carrier($order->id_carrier), 'history' => $history, 'states' => OrderState::getOrderStates($this->context->language->id), 'warehouse_list' => $warehouse_list, 'sources' => ConnectionsSource::getOrderSources($order->id), 'currentState' => $order->getCurrentOrderState(), 'currency' => new Currency($order->id_currency), 'currencies' => Currency::getCurrenciesByIdShop($order->id_shop), 'previousOrder' => $order->getPreviousOrderId(), 'nextOrder' => $order->getNextOrderId(), 'current_index' => self::$currentIndex, 'carrierModuleCall' => $carrier_module_call, 'iso_code_lang' => $this->context->language->iso_code, 'id_lang' => $this->context->language->id, 'can_edit' => $this->tabAccess['edit'] == 1, 'current_id_lang' => $this->context->language->id, 'invoices_collection' => $order->getInvoicesCollection(), 'not_paid_invoices_collection' => $order->getNotPaidInvoicesCollection(), 'payment_methods' => $payment_methods, 'invoice_management_active' => Configuration::get('PS_INVOICE', null, null, $order->id_shop), 'display_warehouse' => (int) Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')); return parent::renderView(); }
/** * Init objects necessary for orders */ private function initObjects() { $invoice_address = false; $this->customer = $this->getCustomerByEmail($this->datas->customer->emailAddress, true, $this->datas->customer->lastName, $this->datas->customer->firstName, $this->datas->customer->emailAddress); $addresses = $this->customer->getAddresses((int) $this->context->language->id); $find = false; if (!isset($this->datas->customer->shippingAddress->friendlyName)) { $friendlyName = $this->module->l('My address'); } else { $friendlyName = $this->datas->customer->shippingAddress->friendlyName; } foreach ($addresses as $addr) { if ($addr['alias'] == $friendlyName) { $find = true; $address = new Address((int) $addr['id_address']); break; } } if (!$find) { $address = $this->createAddress($this->datas->customer->shippingAddress); } else { $address = $this->createAddress($this->datas->customer->shippingAddress, $address); } if (isset($this->datas->customer->billingAddress)) { $invoice_address = $this->createAddress($this->datas->customer->billingAddress); } if (Validate::isLoadedObject($address)) { $this->address = $address; $this->invoice_address = $address; } else { $this->address = false; return false; } if (Validate::isLoadedObject($invoice_address)) { $this->invoice_address = $invoice_address; } }