public function getTemplateVarOrders() { $orders = array(); $customer_orders = Order::getCustomerOrders($this->context->customer->id); foreach ($customer_orders as $customer_order) { $order = new Order((int) $customer_order['id_order']); $orders[$customer_order['id_order']] = $this->order_presenter->present($order); } return $orders; }
public function process() { parent::process(); if ($orders = Order::getCustomerOrders((int) self::$cookie->id_customer)) { foreach ($orders as &$order) { $myOrder = new Order((int) $order['id_order']); if (Validate::isLoadedObject($myOrder)) { $order['virtual'] = $myOrder->isVirtual(false); } } } self::$smarty->assign(array('orders' => $orders, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), 'slowValidation' => Tools::isSubmit('slowvalidation'))); }
/** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { parent::initContent(); if ($orders = Order::getCustomerOrders($this->context->customer->id)) { foreach ($orders as &$order) { $myOrder = new Order((int) $order['id_order']); if (Validate::isLoadedObject($myOrder)) { $order['virtual'] = $myOrder->isVirtual(false); } } } $this->context->smarty->assign(array('orders' => $orders, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), 'reorderingAllowed' => !(int) Configuration::get('PS_DISALLOW_HISTORY_REORDERING'), 'slowValidation' => Tools::isSubmit('slowvalidation'))); $this->setTemplate(_PS_THEME_DIR_ . 'history.tpl'); }
public function initContent() { parent::initContent(); if ($orders = Order::getCustomerOrders($this->context->customer->id)) { foreach ($orders as &$order) { $myOrder = new Order((int) $order['id_order']); if (Validate::isLoadedObject($myOrder)) { $order['virtual'] = $myOrder->isVirtual(false); } } } $has_address = $this->context->customer->getAddresses($this->context->language->id); $this->context->smarty->assign(array('orders' => $orders, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), 'reorderingAllowed' => !(bool) Configuration::get('PS_DISALLOW_HISTORY_REORDERING'), 'slowValidation' => Tools::isSubmit('slowvalidation'), 'has_customer_an_address' => empty($has_address), 'voucherAllowed' => (int) CartRule::isFeatureActive(), 'returnAllowed' => (int) Configuration::get('PS_ORDER_RETURN'))); $this->context->smarty->assign('HOOK_CUSTOMER_ACCOUNT', Hook::exec('displayCustomerAccount')); $this->setTemplate(_PS_THEME_DIR_ . 'my-account.tpl'); }
/** * @param int $customerId * @param int $limit * @param int $offset * @param string $orderDateFrom * @param string $sortOrder * * @return mixed */ public function getCustomerOrders($customerId, $limit = 10, $offset = 0, $orderDateFrom = '', $sortOrder = 'created_desc') { $orders = Order::getCustomerOrders($customerId); $orders = $this->sortCoreOrders($orders, $sortOrder); $orderCount = 0; $result = array(); if ($orderDateFrom != '') { $dateTime = new DateTime($orderDateFrom); $orderDateFrom = $dateTime->getTimestamp(); } else { $orderDateFrom = false; } foreach ($orders as $order) { /** * handle offset */ if ($orderCount < $offset) { $orderCount++; continue; } /** * handle date from */ if ($orderDateFrom) { $dateTime = new DateTime($order['date_add']); $orderDateFromCompare = $dateTime->getTimestamp(); if ($orderDateFromCompare < $orderDateFrom) { $orderCount++; continue; } } /** * handle limit */ if ($orderCount == $limit) { break; } $result[] = $order; $orderCount++; } return $result; }
public function delete() { if (!count(Order::getCustomerOrders((int) $this->id))) { $addresses = $this->getAddresses((int) Configuration::get('PS_LANG_DEFAULT')); foreach ($addresses as $address) { $obj = new Address((int) $address['id_address']); $obj->delete(); } } Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'customer_group` WHERE `id_customer` = ' . (int) $this->id); Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'message WHERE id_customer=' . (int) $this->id); Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'specific_price WHERE id_customer=' . (int) $this->id); Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'compare WHERE id_customer=' . (int) $this->id); $carts = Db::getInstance()->executes('SELECT id_cart FROM ' . _DB_PREFIX_ . 'cart WHERE id_customer=' . (int) $this->id); if ($carts) { foreach ($carts as $cart) { Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'cart WHERE id_cart=' . (int) $cart['id_cart']); Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'cart_product WHERE id_cart=' . (int) $cart['id_cart']); } } $cts = Db::getInstance()->executes('SELECT id_customer_thread FROM ' . _DB_PREFIX_ . 'customer_thread WHERE id_customer=' . (int) $this->id); if ($cts) { foreach ($cts as $ct) { Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'customer_thread WHERE id_customer_thread=' . (int) $ct['id_customer_thread']); Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'customer_message WHERE id_customer_thread=' . (int) $ct['id_customer_thread']); } } CartRule::deleteByIdCustomer((int) $this->id); // start of implementation of the module code - taxamo Taxamoeuvat::deleteCCPrefix($this->id); // end of code implementation module - taxamo return parent::delete(); }
private function buildXMLOrder($id_order) { CertissimLogger::insertLog(__METHOD__ . ' : ' . __LINE__, 'construction du flux pour order ' . $id_order); $order = new Order($id_order); //gets back the delivery address $address_delivery = new Address((int) $order->id_address_delivery); //gets back the invoice address $address_invoice = new Address((int) $order->id_address_invoice); //gets back the customer $customer = new Customer((int) $order->id_customer); //initializatino of the XML root: <control> $xml_element_control = new CertissimControl(); //gets the lang used in the order $id_lang = $order->id_lang; //sets the gender, depends on PS version if (_PS_VERSION_ < '1.5') { $gender = $customer->id_gender == 2 ? $this->l('Ms.') : $this->l('Mr.'); } else { $customer_gender = new Gender($customer->id_gender); $lang_id = Language::getIdByIso('en'); if (empty($lang_id)) { $lang_id = Language::getIdByIso('fr'); } CertissimLogger::insertLog(__METHOD__ . ' : ' . __LINE__, "id_gender = " . $customer->id_gender . ", gender name =" . $customer_gender->name[$lang_id]); $gender = $this->l($customer_gender->name[$lang_id]); } //initialization of the element <utilisateur type='facturation'...> $xml_element_invoice_customer = new CertissimUtilisateur('facturation', $gender, $address_invoice->lastname, $address_invoice->firstname, $address_invoice->company, $address_invoice->phone, $address_invoice->phone_mobile, null, $customer->email); //gets customer stats $customer_stats = $customer->getStats(); //gets already existing orders for the customer $all_orders = Order::getCustomerOrders((int) $customer->id); //initialization of the element <siteconso> $xml_element_invoice_customer_stats = new CertissimSiteconso($customer_stats['total_orders'], $customer_stats['nb_orders'], $all_orders[count($all_orders) - 1]['date_add'], count($all_orders) > 1 ? $all_orders[1]['date_add'] : null); //gets back the invoice country $country = new Country((int) $address_invoice->id_country); //initialization of the element <adresse type="facturation" ...> $xml_element_invoice_address = new CertissimAdresse('facturation', $address_invoice->address1, $address_invoice->address2, $address_invoice->postcode, $address_invoice->city, $country->name[$id_lang]); //gets back the carrier used for this order $carrier = new Carrier((int) $order->id_carrier); //gets the carrier certissim type if (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) { $carrier_type = Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_TYPE', null, null, $order->id_shop); } else { $carrier_type = Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_TYPE'); } //if the order is to be delivered at home: element <utilisateur type="livraison"...> has to be added if ($carrier_type == 4) { //initialization of the element <utilisateur type="livraison" ...> $xml_element_delivery_customer = new CertissimUtilisateur('livraison', $customer->id_gender == 2 ? $this->l('Miss') : $this->l('Mister'), $address_delivery->lastname, $address_delivery->firstname, $address_delivery->company, $address_delivery->phone, $address_delivery->phone_mobile, null, $customer->email); //gets back the delivery country $country = new Country((int) $address_delivery->id_country); //initialization of the element <adresse type="livraison" ...> $xml_element_delivery_address = new CertissimAdresse('livraison', $address_delivery->address1, $address_delivery->address2, $address_delivery->postcode, $address_delivery->city, $country->name[$id_lang], null); } //gets the used currency $currency = new Currency((int) $order->id_currency); if (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) { $siteid = Configuration::get('CERTISSIM_SITEID', null, null, $order->id_shop); } else { $siteid = Configuration::get('CERTISSIM_SITEID'); } //initialize the element <infocommande> $xml_element_order_details = new CertissimInfocommande($siteid, $order->id, (string) $order->total_paid, self::getIpByOrder((int) $order->id), date('Y-m-d H:i:s'), $currency->iso_code); //gets the order products $products = $order->getProducts(); //define the default product type (depends on PS version) if (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) { $default_product_type = Configuration::get('CERTISSIM_DEFAULT_PRODUCT_TYPE', null, null, $order->id_shop); } else { $default_product_type = Configuration::get('CERTISSIM_DEFAULT_PRODUCT_TYPE'); } //initialization of the element <list ...> $xml_element_products_list = new CertissimProductList(); //initialize the boolean that says if all the products in the order are downloadables $alldownloadables = true; foreach ($products as $product) { //check if the visited product is downloadable and update the boolean value $alldownloadables = $alldownloadables && strlen($product['download_hash']) > 0; //gets the main product category $product_categories = Product::getProductCategories((int) $product['product_id']); $product_category = array_pop($product_categories); //initilization of the element <produit ...> $xml_element_product = new CertissimXMLElement("<produit></produit>"); //gets the product certissim category (depends on PS version) if (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) { $product_type = Configuration::get('CERTISSIM' . $product_category . '_PRODUCT_TYPE', null, null, $order->id_shop); } else { $product_type = Configuration::get('CERTISSIM' . $product_category . '_PRODUCT_TYPE'); } //if a certissim category is set: the type attribute takes the product certissim type value if ($product_type) { $xml_element_product->addAttribute('type', Configuration::get('CERTISSIM' . $product_category . '_PRODUCT_TYPE', null, null, $order->id_shop)); } else { //if certissim category not set: the type attribute takes the default value $xml_element_product->addAttribute('type', $default_product_type); } //sets the product reference that will be inserted into the XML stream //uses the product name by default $product_ref = $product['product_name']; //prefers ean13 if defined if (!empty($product['product_ean13'])) { $product_ref = $product['product_ean13']; } //prefers local reference if defined if (!empty($product['product_reference'])) { $product_ref = $product['product_reference']; } //adds attributes ref, nb, prixunit, and sets the value of the element <product> with the product name $xml_element_product->addAttribute('ref', CertissimTools::normalizeString($product_ref)); $xml_element_product->addAttribute('nb', $product['product_quantity']); $xml_element_product->addAttribute('prixunit', $product['total_price']); $xml_element_product->setValue($product['product_name']); //adds the element <product> to the element <list> $xml_element_products_list->addProduit($xml_element_product); } if ($alldownloadables) { $real_carrier_type = '5'; } elseif (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) { //if selected carrier fianet type is defined, the type used will be the one got in the Configuration if (in_array(Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_TYPE', null, null, $order->id_shop), array_keys($this->_carrier_types))) { $real_carrier_type = Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_TYPE', null, null, $order->id_shop); $real_carrier_speed = Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_SPEED', null, null, $order->id_shop); } else { $real_carrier_type = Configuration::get('CERTISSIM_DEFAULT_CARRIER_TYPE', null, null, $order->id_shop); $real_carrier_speed = Configuration::get('CERTISSIM_DEFAULT_CARRIER_SPEED', null, null, $order->id_shop); } } elseif (in_array(Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_TYPE'), array_keys($this->_carrier_types))) { $real_carrier_type = Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_TYPE'); $real_carrier_speed = Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_SPEED'); } else { $real_carrier_type = Configuration::get('CERTISSIM_DEFAULT_CARRIER_TYPE'); $real_carrier_speed = Configuration::get('CERTISSIM_DEFAULT_CARRIER_SPEED'); } //initialization of the element <transport> $xml_element_carrier = new CertissimTransport($real_carrier_type, $alldownloadables ? 'Téléchargement' : Tools::htmlentitiesUTF8($carrier->name), $alldownloadables ? '1' : $real_carrier_speed, null); //find the id of the payment module used (depends on the PS version) if (_PS_VERSION_ >= '1.5') { $id_payment_module = PaymentModule::getModuleIdByName($order->module); } else { $payment_module = Module::getInstanceByName($order->module); $id_payment_module = $payment_module->id; } //initialization of the element <paiement> if (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) { $payment_type = $this->_payment_types[Configuration::get('CERTISSIM_' . $id_payment_module . '_PAYMENT_TYPE', null, null, $order->id_shop)]; } else { $payment_type = $this->_payment_types[Configuration::get('CERTISSIM_' . $id_payment_module . '_PAYMENT_TYPE')]; } $xml_element_payment = new CertissimPaiement($payment_type); //initialization of the element <stack> $stack = new CertissimXMLElement("<stack></stack>"); //agregates each elements in a main stream $xml_element_invoice_customer->childSiteconso($xml_element_invoice_customer_stats); $xml_element_control->childUtilisateur($xml_element_invoice_customer); $xml_element_control->childAdresse($xml_element_invoice_address); if (isset($xml_element_delivery_customer)) { $xml_element_control->childUtilisateur($xml_element_delivery_customer); } if (isset($xml_element_delivery_address)) { $xml_element_control->childAdresse($xml_element_delivery_address); } $xml_element_order_details->childTransport($xml_element_carrier); $xml_element_order_details->childList($xml_element_products_list); $xml_element_control->childInfocommande($xml_element_order_details); $xml_element_control->childPaiement($xml_element_payment); //add CDATA sections to protect against encoding issues $xml_element_control->addCdataSections(); //add the <control> element into <stack> $stack->childControl($xml_element_control); CertissimLogger::insertLog(__METHOD__ . ' : ' . __LINE__, "---- flux généré pour commande {$id_order} ----"); CertissimLogger::insertLog(__METHOD__ . ' : ' . __LINE__, $xml_element_control->getXML()); CertissimLogger::insertLog(__METHOD__ . ' : ' . __LINE__, "---------------------------------------"); return $stack; }
public function hookNewOrder($params) { if ($params['order']->total_paid <= 0) { return; } if (!$this->needCheck($params['order']->module, $params['order']->total_paid)) { return false; } $address_delivery = new Address((int) $params['order']->id_address_delivery); $address_invoice = new Address((int) $params['order']->id_address_invoice); $customer = new Customer((int) $params['order']->id_customer); $orderFianet = new fianet_order_xml(); $id_lang = Configuration::get('PS_LANG_DEFAULT'); if ($address_invoice->company == '') { $orderFianet->billing_user->set_quality_nonprofessional(); } else { $orderFianet->billing_user->set_quality_professional(); } $orderFianet->billing_user->titre = $customer->id_gender == 1 ? $this->l('Mr.') : ($customer->id_gender == 2 ? $this->l('Mrs') : $this->l('Mr.')); $orderFianet->billing_user->nom = utf8_decode($address_invoice->lastname); $orderFianet->billing_user->prenom = utf8_decode($address_invoice->firstname); $orderFianet->billing_user->societe = utf8_decode($address_invoice->company); $orderFianet->billing_user->telhome = utf8_decode($address_invoice->phone); $orderFianet->billing_user->office = ''; $orderFianet->billing_user->telmobile = utf8_decode($address_invoice->phone_mobile); $orderFianet->billing_user->telfax = ''; $orderFianet->billing_user->email = $customer->email; $customer_stats = $customer->getStats(); $all_orders = Order::getCustomerOrders((int) $customer->id); $orderFianet->billing_user->site_conso = new fianet_user_siteconso_xml(); $orderFianet->billing_user->site_conso->ca = $customer_stats['total_orders']; $orderFianet->billing_user->site_conso->nb = $customer_stats['nb_orders']; $orderFianet->billing_user->site_conso->datepremcmd = $all_orders[count($all_orders) - 1]['date_add']; if (count($all_orders) > 1) { $orderFianet->billing_user->site_conso->datederncmd = $all_orders[1]['date_add']; } $orderFianet->billing_adress->rue1 = utf8_decode($address_invoice->address1); $orderFianet->billing_adress->rue2 = utf8_decode($address_invoice->address2); $orderFianet->billing_adress->cpostal = utf8_decode($address_invoice->postcode); $orderFianet->billing_adress->ville = utf8_decode($address_invoice->city); $country = new Country((int) $address_invoice->id_country); $orderFianet->billing_adress->pays = utf8_decode($country->name[$id_lang]); //delivery adresse not send if carrier id is 1 or 2 $carrier_id = array(1, 2); if (!in_array(Configuration::get('SAC_CARRIER_TYPE_' . (int) $params['cart']->id_carrier), $carrier_id)) { $orderFianet->delivery_user = new fianet_delivery_user_xml(); $orderFianet->delivery_adress = new fianet_delivery_adress_xml(); if ($address_delivery->company == '') { $orderFianet->delivery_user->set_quality_nonprofessional(); } else { $orderFianet->delivery_user->set_quality_professional(); } $orderFianet->delivery_user->titre = $customer->id_gender == 1 ? $this->l('Mr.') : ($customer->id_gender == 2 ? $this->l('Mrs') : $this->l('Unknown')); $orderFianet->delivery_user->nom = utf8_decode($address_delivery->lastname); $orderFianet->delivery_user->prenom = utf8_decode($address_delivery->firstname); $orderFianet->delivery_user->societe = utf8_decode($address_delivery->company); $orderFianet->delivery_user->telhome = utf8_decode($address_delivery->phone); $orderFianet->delivery_user->office = ''; $orderFianet->delivery_user->telmobile = utf8_decode($address_delivery->phone_mobile); $orderFianet->delivery_user->telfax = ''; $orderFianet->delivery_user->email = $customer->email; $orderFianet->delivery_adress->rue1 = utf8_decode($address_delivery->address1); $orderFianet->delivery_adress->rue2 = utf8_decode($address_delivery->address2); $orderFianet->delivery_adress->cpostal = utf8_decode($address_delivery->postcode); $orderFianet->delivery_adress->ville = utf8_decode($address_delivery->city); $country = new Country((int) $address_delivery->id_country); $orderFianet->delivery_adress->pays = utf8_decode($country->name[$id_lang]); } $orderFianet->info_commande->refid = $params['order']->id; $orderFianet->info_commande->montant = $params['order']->total_paid; $currency = new Currency((int) $params['order']->id_currency); $orderFianet->info_commande->devise = $currency->iso_code; $orderFianet->info_commande->ip = self::getIpByCart((int) $params['cart']->id); $orderFianet->info_commande->timestamp = date('Y-m-d H:i:s'); $products = $params['cart']->getProducts(); $default_product_type = Configuration::get('SAC_DEFAULT_PRODUCT_TYPE'); foreach ($products as $product) { $product_categories = Product::getIndexedCategories((int) $product['id_product']); $have_sac_cat = false; $produit = new fianet_product_xml(); if (Configuration::get('SAC_CATEGORY_TYPE_' . $product['id_category_default'])) { $produit->type = Configuration::get('SAC_CATEGORY_TYPE_' . $product['id_category_default']); } else { $produit->type = $default_product_type; } $produit->ref = utf8_decode((isset($product['reference']) and !empty($product['reference'])) ? $product['reference'] : ((isset($product['ean13']) and !empty($product['ean13'])) ? $product['ean13'] : $product['name'])); $produit->nb = $product['cart_quantity']; $produit->prixunit = $product['price']; $produit->name = utf8_decode($product['name']); $orderFianet->info_commande->list->add_product($produit); } $carrier = new Carrier((int) $params['order']->id_carrier); $orderFianet->info_commande->transport->type = Configuration::get('SAC_CARRIER_TYPE_' . (int) $carrier->id); $orderFianet->info_commande->transport->nom = $carrier->name; $orderFianet->info_commande->transport->rapidite = self::getCarrierFastById((int) $carrier->id); $orderFianet->payment->type = Configuration::get('SAC_PAYMENT_TYPE_' . substr($params['order']->module, 0, 15)); $xml = $orderFianet->get_xml(); $sender = new fianet_sender(); if (Configuration::get('SAC_PRODUCTION')) { $sender->mode = 'production'; } else { $sender->mode = 'test'; } $sender->add_order($orderFianet); $res = $sender->send_orders_stacking(); Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'fianet_fraud_orders(id_order, date_add) VALUES(' . (int) $params['order']->id . ', \'' . pSQL(date('Y-m-d H:i:s')) . '\')'); return true; }
/** * Hook display in tab AdminCustomers on BO * Data table with all sponsors informations for a customer */ public function hookAdminCustomers($params) { $customer = new Customer(intval($params['id_customer'])); if (!Validate::isLoadedObject($customer)) { die(Tools::displayError('Incorrect object Customer.')); } global $cookie; $friends = ReferralProgramModule::getSponsorFriend($customer->id); if ($id_referralprogram = ReferralProgramModule::isSponsorised(intval($customer->id), true)) { $referralprogram = new ReferralProgramModule($id_referralprogram); $sponsor = new Customer($referralprogram->id_sponsor); } $html = '<h2>' . $this->l('Referral program') . '</h2>'; // link to the detail of the sponsor $html .= '<h3>' . (isset($sponsor) ? $this->l('Customer\'s sponsor:') . ' <a href="index.php?tab=AdminCustomers&id_customer=' . $sponsor->id . '&viewcustomer&token=' . Tools::getAdminToken('AdminCustomers' . intval(Tab::getIdFromClassName('AdminCustomers')) . intval($cookie->id_employee)) . '">' . $sponsor->firstname . ' ' . $sponsor->lastname . '</a>' : $this->l('No one has sponsored this customer.')) . '</h3>'; if ($friends and sizeof($friends)) { $html .= '<h3>' . sizeof($friends) . ' ' . (sizeof($friends) > 1 ? $this->l('sponsored customers:') : $this->l('sponsored customer:')) . '</h3>'; $html .= ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th class="center">' . $this->l('ID') . '</th> <th class="center">' . $this->l('Name') . '</th> <th class="center">' . $this->l('Email') . '</th> <th class="center">' . $this->l('Registration date') . '</th> <th class="center">' . $this->l('Sponsored customers') . '</th> <th class="center">' . $this->l('Placed orders') . '</th> <th class="center">' . $this->l('Inscribed') . '</th> </tr>'; foreach ($friends as $key => $friend) { $orders = Order::getCustomerOrders($friend['id_customer']); $html .= ' <tr ' . ($key++ % 2 ? 'class="alt_row"' : '') . ' ' . (intval($friend['id_customer']) ? 'style="cursor: pointer" onclick="document.location = \'?tab=AdminCustomers&id_customer=' . $friend['id_customer'] . '&viewcustomer&token=' . Tools::getAdminToken('AdminCustomers' . intval(Tab::getIdFromClassName('AdminCustomers')) . intval($cookie->id_employee)) . '\'"' : '') . '> <td class="center">' . (intval($friend['id_customer']) ? $friend['id_customer'] : '--') . '</td> <td>' . $friend['firstname'] . ' ' . $friend['lastname'] . '</td> <td>' . $friend['email'] . '</td> <td>' . Tools::displayDate($friend['date_add'], intval($cookie->id_lang), true) . '</td> <td align="right">' . sizeof(ReferralProgramModule::getSponsorFriend($friend['id_customer'])) . '</td> <td align="right">' . ($orders ? sizeof($orders) : 0) . '</td> <td align="center">' . (intval($friend['id_customer']) ? '<img src="' . _PS_ADMIN_IMG_ . 'enabled.gif" />' : '<img src="' . _PS_ADMIN_IMG_ . 'disabled.gif" />') . '</td> </tr>'; } $html .= ' </table>'; } else { $html .= $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has not sponsored any friends yet.'); } return $html . '<br/><br/>'; }
die('Error: Invalid Token'); } $id_shop_group = Tools::getValue('id_shop_group', 'NULL'); $id_shop = Tools::getValue('id_shop', 'NULL'); $sendin = new Sendinblue(); $sendin_order_track_status = Configuration::get('Sendin_order_tracking_Status', '', $id_shop_group, $id_shop); if ($sendin_order_track_status == 0) { $handle = fopen(_PS_MODULE_DIR_ . 'sendinblue/csv/ImportOldOrdersToSendinblue.csv', 'w+'); $key_value = array(); $key_value[] = 'EMAIL,ORDER_ID,ORDER_PRICE,ORDER_DATE'; foreach ($key_value as $linedata) { fwrite($handle, $linedata . "\n"); } $customer_detail = $sendin->getAllCustomers($id_shop_group, $id_shop); foreach ($customer_detail as $customer_value) { $orders = Order::getCustomerOrders($customer_value['id_customer']); if (count($orders) > 0) { $data = array(); $data['key'] = Configuration::get('Sendin_Api_Key', '', $id_shop_group, $id_shop); $data['webaction'] = 'USERS-STATUS'; $data['email'] = $customer_value['email']; $sendin->curlRequest($data); $user_status = Tools::jsonDecode($sendin->curlRequest($data), true); if ($user_status['result'] != '') { foreach ($orders as $orders_data) { if (version_compare(_PS_VERSION_, '1.5', '>=')) { $order_id = $orders_data['reference']; } else { $order_id = $orders_data['id_order']; } $order_price = Tools::safeOutput($orders_data['total_paid']);
public function renderView() { if (!($id_customer_thread = (int) Tools::getValue('id_customer_thread'))) { return; } $this->context = Context::getContext(); if (!($thread = $this->loadObject())) { return; } $this->context->cookie->{'customer_threadFilter_cl!id_contact'} = $thread->id_contact; $employees = Employee::getEmployees(); $messages = CustomerThread::getMessageCustomerThreads($id_customer_thread); foreach ($messages as $key => $mess) { if ($mess['id_employee']) { $employee = new Employee($mess['id_employee']); $messages[$key]['employee_image'] = $employee->getImage(); } if (isset($mess['file_name']) && $mess['file_name'] != '') { $messages[$key]['file_name'] = _THEME_PROD_PIC_DIR_ . $mess['file_name']; } else { unset($messages[$key]['file_name']); } if ($mess['id_product']) { $product = new Product((int) $mess['id_product'], false, $this->context->language->id); if (Validate::isLoadedObject($product)) { $messages[$key]['product_name'] = $product->name; $messages[$key]['product_link'] = $this->context->link->getAdminLink('AdminProducts') . '&updateproduct&id_product=' . (int) $product->id; } } } $next_thread = CustomerThread::getNextThread((int) $thread->id); $contacts = Contact::getContacts($this->context->language->id); $actions = array(); if ($next_thread) { $next_thread = array('href' => self::$currentIndex . '&id_customer_thread=' . (int) $next_thread . '&viewcustomer_thread&token=' . $this->token, 'name' => $this->l('Reply to the next unanswered message in this thread')); } if ($thread->status != 'closed') { $actions['closed'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=2&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'label' => $this->l('Mark as "handled"'), 'name' => 'setstatus', 'value' => 2); } else { $actions['open'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=1&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'label' => $this->l('Re-open'), 'name' => 'setstatus', 'value' => 1); } if ($thread->status != 'pending1') { $actions['pending1'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=3&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'label' => $this->l('Mark as "pending 1" (will be answered later)'), 'name' => 'setstatus', 'value' => 3); } else { $actions['pending1'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=1&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'label' => $this->l('Disable pending status'), 'name' => 'setstatus', 'value' => 1); } if ($thread->status != 'pending2') { $actions['pending2'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=4&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'label' => $this->l('Mark as "pending 2" (will be answered later)'), 'name' => 'setstatus', 'value' => 4); } else { $actions['pending2'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=1&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'label' => $this->l('Disable pending status'), 'name' => 'setstatus', 'value' => 1); } if ($thread->id_customer) { $customer = new Customer($thread->id_customer); $orders = Order::getCustomerOrders($customer->id); if ($orders && count($orders)) { $total_ok = 0; $orders_ok = array(); foreach ($orders as $key => $order) { if ($order['valid']) { $orders_ok[] = $order; $total_ok += $order['total_paid_real']; } $orders[$key]['date_add'] = Tools::displayDate($order['date_add']); $orders[$key]['total_paid_real'] = Tools::displayPrice($order['total_paid_real'], new Currency((int) $order['id_currency'])); } } $products = $customer->getBoughtProducts(); if ($products && count($products)) { foreach ($products as $key => $product) { $products[$key]['date_add'] = Tools::displayDate($product['date_add'], null, true); } } } $timeline_items = $this->getTimeline($messages, $thread->id_order); $first_message = $messages[0]; if (!$messages[0]['id_employee']) { unset($messages[0]); } $contact = ''; foreach ($contacts as $c) { if ($c['id_contact'] == $thread->id_contact) { $contact = $c['name']; } } $this->tpl_view_vars = array('id_customer_thread' => $id_customer_thread, 'thread' => $thread, 'actions' => $actions, 'employees' => $employees, 'current_employee' => $this->context->employee, 'messages' => $messages, 'first_message' => $first_message, 'contact' => $contact, 'next_thread' => $next_thread, 'orders' => isset($orders) ? $orders : false, 'customer' => isset($customer) ? $customer : false, 'products' => isset($products) ? $products : false, 'total_ok' => isset($total_ok) ? Tools::displayPrice($total_ok, $this->context->currency) : false, 'orders_ok' => isset($orders_ok) ? $orders_ok : false, 'count_ok' => isset($orders_ok) ? count($orders_ok) : false, 'PS_CUSTOMER_SERVICE_SIGNATURE' => str_replace('\\r\\n', "\n", Configuration::get('PS_CUSTOMER_SERVICE_SIGNATURE', (int) $thread->id_lang)), 'timeline_items' => $timeline_items); if ($next_thread) { $this->tpl_view_vars['next_thread'] = $next_thread; } return parent::renderView(); }
public function viewcustomer() { global $currentIndex, $cookie, $link; $irow = 0; $configurations = Configuration::getMultiple(array('PS_LANG_DEFAULT', 'PS_CURRENCY_DEFAULT')); $defaultLanguage = (int) $configurations['PS_LANG_DEFAULT']; $defaultCurrency = (int) $configurations['PS_CURRENCY_DEFAULT']; if (!($customer = $this->loadObject())) { return; } $customerStats = $customer->getStats(); $addresses = $customer->getAddresses($defaultLanguage); $products = $customer->getBoughtProducts(); $discounts = Discount::getCustomerDiscounts($defaultLanguage, (int) $customer->id, false, false); $orders = Order::getCustomerOrders((int) $customer->id, true); $carts = Cart::getCustomerCarts((int) $customer->id); $groups = $customer->getGroups(); $messages = CustomerThread::getCustomerMessages((int) $customer->id); $referrers = Referrer::getReferrers((int) $customer->id); if ($totalCustomer = Db::getInstance()->getValue('SELECT SUM(total_paid_real) FROM ' . _DB_PREFIX_ . 'orders WHERE id_customer = ' . $customer->id . ' AND valid = 1')) { Db::getInstance()->getValue('SELECT SQL_CALC_FOUND_ROWS COUNT(*) FROM ' . _DB_PREFIX_ . 'orders WHERE valid = 1 GROUP BY id_customer HAVING SUM(total_paid_real) > ' . $totalCustomer); $countBetterCustomers = (int) Db::getInstance()->getValue('SELECT FOUND_ROWS()') + 1; } else { $countBetterCustomers = '-'; } echo ' <fieldset style="width:400px;float: left"><div style="float: right"><a href="' . $currentIndex . '&addcustomer&id_customer=' . $customer->id . '&token=' . $this->token . '"><img src="../img/admin/edit.gif" /></a></div> <span style="font-weight: bold; font-size: 14px;">' . $customer->firstname . ' ' . $customer->lastname . '</span> <img src="../img/admin/' . ($customer->id_gender == 2 ? 'female' : ($customer->id_gender == 1 ? 'male' : 'unknown')) . '.gif" style="margin-bottom: 5px" /><br /> <a href="mailto:' . $customer->email . '" style="text-decoration: underline; color: blue">' . $customer->email . '</a><br /><br /> ' . $this->l('ID:') . ' ' . sprintf('%06d', $customer->id) . '<br /> ' . $this->l('Registration date:') . ' ' . Tools::displayDate($customer->date_add, (int) $cookie->id_lang, true) . '<br /> ' . $this->l('Last visit:') . ' ' . ($customerStats['last_visit'] ? Tools::displayDate($customerStats['last_visit'], (int) $cookie->id_lang, true) : $this->l('never')) . '<br /> ' . ($countBetterCustomers != '-' ? $this->l('Rank: #') . ' ' . (int) $countBetterCustomers . '<br />' : '') . ' </fieldset> <fieldset style="width:300px;float:left;margin-left:50px"> <div style="float: right"> <a href="' . $currentIndex . '&addcustomer&id_customer=' . $customer->id . '&token=' . $this->token . '"><img src="../img/admin/edit.gif" /></a> </div> ' . $this->l('Newsletter:') . ' ' . ($customer->newsletter ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />') . '<br /> ' . $this->l('Opt-in:') . ' ' . ($customer->optin ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />') . '<br /> ' . $this->l('Age:') . ' ' . $customerStats['age'] . ' ' . (!empty($customer->birthday['age']) ? '(' . Tools::displayDate($customer->birthday, (int) $cookie->id_lang) . ')' : $this->l('unknown')) . '<br /><br /> ' . $this->l('Last update:') . ' ' . Tools::displayDate($customer->date_upd, (int) $cookie->id_lang, true) . '<br /> ' . $this->l('Status:') . ' ' . ($customer->active ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />'); if ($customer->isGuest()) { echo ' <div> ' . $this->l('This customer is registered as') . ' <b>' . $this->l('guest') . '</b>'; if (!Customer::customerExists($customer->email)) { echo ' <form method="POST" action="index.php?tab=AdminCustomers&id_customer=' . (int) $customer->id . '&token=' . Tools::getAdminTokenLite('AdminCustomers') . '"> <input type="hidden" name="id_lang" value="' . (int) (sizeof($orders) ? $orders[0]['id_lang'] : Configuration::get('PS_LANG_DEFAULT')) . '" /> <p class="center"><input class="button" type="submit" name="submitGuestToCustomer" value="' . $this->l('Transform to customer') . '" /></p> ' . $this->l('This feature generates a random password and sends an e-mail to the customer') . '</form>'; } else { echo '</div><div><b style="color:red;">' . $this->l('A registered customer account exists with the same email address') . '</b>'; } echo ' </div> '; } echo ' </fieldset> <div class="clear"> </div>'; echo '<fieldset style="height:190px"><legend><img src="../img/admin/cms.gif" /> ' . $this->l('Add a private note') . '</legend> <p>' . $this->l('This note will be displayed to all the employees but not to the customer.') . '</p> <form action="ajax.php" method="post" onsubmit="saveCustomerNote();return false;" id="customer_note"> <textarea name="note" id="noteContent" style="width:600px;height:100px" onkeydown="$(\'#submitCustomerNote\').removeAttr(\'disabled\');">' . Tools::htmlentitiesUTF8($customer->note) . '</textarea><br /> <input type="submit" id="submitCustomerNote" class="button" value="' . $this->l(' Save ') . '" style="float:left;margin-top:5px" disabled="disabled" /> <span id="note_feedback" style="float:left;margin:10px 0 0 10px"></span> </form> </fieldset> <div class="clear"> </div> <script type="text/javascript"> function saveCustomerNote() { $("#note_feedback").html("<img src=\\"../img/loader.gif\\" />").show(); var noteContent = $("#noteContent").val(); $.post("ajax.php", {submitCustomerNote:1,id_customer:' . (int) $customer->id . ',note:noteContent}, function (r) { $("#note_feedback").html("").hide(); if (r == "ok") { $("#note_feedback").html("<b style=\\"color:green\\">' . addslashes($this->l('Your note has been saved')) . '</b>").fadeIn(400); $("#submitCustomerNote").attr("disabled", "disabled"); } else if (r == "error:validation") $("#note_feedback").html("<b style=\\"color:red\\">' . addslashes($this->l('Error: your note is not valid')) . '</b>").fadeIn(400); else if (r == "error:update") $("#note_feedback").html("<b style=\\"color:red\\">' . addslashes($this->l('Error: cannot save your note')) . '</b>").fadeIn(400); $("#note_feedback").fadeOut(3000); }); } </script>'; echo '<h2>' . $this->l('Messages') . ' (' . sizeof($messages) . ')</h2>'; if (sizeof($messages)) { echo ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th class="center">' . $this->l('Status') . '</th> <th class="center">' . $this->l('Message') . '</th> <th class="center">' . $this->l('Sent on') . '</th> </tr>'; foreach ($messages as $message) { echo '<tr> <td>' . $message['status'] . '</td> <td><a href="index.php?tab=AdminCustomerThreads&id_customer_thread=' . (int) $message['id_customer_thread'] . '&viewcustomer_thread&token=' . Tools::getAdminTokenLite('AdminCustomerThreads') . '">' . substr(strip_tags(html_entity_decode($message['message'], ENT_NOQUOTES, 'UTF-8')), 0, 75) . '...</a></td> <td>' . Tools::displayDate($message['date_add'], (int) $cookie->id_lang, true) . '</td> </tr>'; } echo '</table> <div class="clear"> </div>'; } else { echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has never contacted you.'); } // display hook specified to this page : AdminCustomers if (($hook = Module::hookExec('adminCustomers', array('id_customer' => $customer->id))) !== false) { echo '<div>' . $hook . '</div>'; } echo '<div class="clear"> </div>'; echo '<h2>' . $this->l('Groups') . ' (' . sizeof($groups) . ')</h2>'; if ($groups and sizeof($groups)) { echo ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th class="center">' . $this->l('ID') . '</th> <th class="center">' . $this->l('Name') . '</th> <th class="center">' . $this->l('Actions') . '</th> </tr>'; $tokenGroups = Tools::getAdminToken('AdminGroups' . (int) Tab::getIdFromClassName('AdminGroups') . (int) $cookie->id_employee); foreach ($groups as $group) { $objGroup = new Group($group); echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminGroups&id_group=' . $objGroup->id . '&viewgroup&token=' . $tokenGroups . '\'"> <td class="center">' . $objGroup->id . '</td> <td>' . $objGroup->name[$defaultLanguage] . '</td> <td align="center"><a href="?tab=AdminGroups&id_group=' . $objGroup->id . '&viewgroup&token=' . $tokenGroups . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo ' </table>'; } echo '<div class="clear"> </div>'; echo '<h2>' . $this->l('Orders') . ' (' . sizeof($orders) . ')</h2>'; if ($orders and sizeof($orders)) { $totalOK = 0; $ordersOK = array(); $ordersKO = array(); $tokenOrders = Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $cookie->id_employee); foreach ($orders as $order) { if ($order['valid']) { $ordersOK[] = $order; $totalOK += $order['total_paid_real']; } else { $ordersKO[] = $order; } } $orderHead = ' <table cellspacing="0" cellpadding="0" class="table float"> <tr> <th class="center">' . $this->l('ID') . '</th> <th class="center">' . $this->l('Date') . '</th> <th class="center">' . $this->l('Products') . '</th> <th class="center">' . $this->l('Total paid') . '</th> <th class="center">' . $this->l('Payment') . '</th> <th class="center">' . $this->l('State') . '</th> <th class="center">' . $this->l('Actions') . '</th> </tr>'; $orderFoot = '</table>'; if ($countOK = sizeof($ordersOK)) { echo '<div style="float:left;margin-right:20px"><h3 style="color:green;font-weight:700">' . $this->l('Valid orders:') . ' ' . $countOK . ' ' . $this->l('for') . ' ' . Tools::displayPrice($totalOK, new Currency($defaultCurrency)) . '</h3>' . $orderHead; foreach ($ordersOK as $order) { echo '<tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '\'"> <td class="center">' . $order['id_order'] . '</td> <td>' . Tools::displayDate($order['date_add'], (int) $cookie->id_lang) . '</td> <td align="right">' . $order['nb_products'] . '</td> <td align="right">' . Tools::displayPrice($order['total_paid_real'], new Currency((int) $order['id_currency'])) . '</td> <td>' . $order['payment'] . '</td> <td>' . $order['order_state'] . '</td> <td align="center"><a href="?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo $orderFoot . '</div>'; } if ($countKO = sizeof($ordersKO)) { echo '<div style="float:left;margin-right:20px"><h3 style="color:red;font-weight:700">' . $this->l('Invalid orders:') . ' ' . $countKO . '</h3>' . $orderHead; foreach ($ordersKO as $order) { echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '\'"> <td class="center">' . $order['id_order'] . '</td> <td>' . Tools::displayDate($order['date_add'], (int) $cookie->id_lang) . '</td> <td align="right">' . $order['nb_products'] . '</td> <td align="right">' . Tools::displayPrice($order['total_paid_real'], new Currency((int) $order['id_currency'])) . '</td> <td>' . $order['payment'] . '</td> <td>' . $order['order_state'] . '</td> <td align="center"><a href="?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo $orderFoot . '</div><div class="clear"> </div>'; } } else { echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has not placed any orders yet'); } if ($products and sizeof($products)) { echo '<div class="clear"> </div> <h2>' . $this->l('Products') . ' (' . sizeof($products) . ')</h2> <table cellspacing="0" cellpadding="0" class="table"> <tr> <th class="center">' . $this->l('Date') . '</th> <th class="center">' . $this->l('Name') . '</th> <th class="center">' . $this->l('Quantity') . '</th> <th class="center">' . $this->l('Actions') . '</th> </tr>'; $tokenOrders = Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $cookie->id_employee); foreach ($products as $product) { echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminOrders&id_order=' . $product['id_order'] . '&vieworder&token=' . $tokenOrders . '\'"> <td>' . Tools::displayDate($product['date_add'], (int) $cookie->id_lang, true) . '</td> <td>' . $product['product_name'] . '</td> <td align="right">' . $product['product_quantity'] . '</td> <td align="center"><a href="?tab=AdminOrders&id_order=' . $product['id_order'] . '&vieworder&token=' . $tokenOrders . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo ' </table>'; } echo '<div class="clear"> </div> <h2>' . $this->l('Addresses') . ' (' . sizeof($addresses) . ')</h2>'; if (sizeof($addresses)) { echo ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th>' . $this->l('Company') . '</th> <th>' . $this->l('Name') . '</th> <th>' . $this->l('Address') . '</th> <th>' . $this->l('Country') . '</th> <th>' . $this->l('Phone number(s)') . '</th> <th>' . $this->l('Actions') . '</th> </tr>'; $tokenAddresses = Tools::getAdminToken('AdminAddresses' . (int) Tab::getIdFromClassName('AdminAddresses') . (int) $cookie->id_employee); foreach ($addresses as $address) { echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . '> <td>' . ($address['company'] ? $address['company'] : '--') . '</td> <td>' . $address['firstname'] . ' ' . $address['lastname'] . '</td> <td>' . $address['address1'] . ($address['address2'] ? ' ' . $address['address2'] : '') . ' ' . $address['postcode'] . ' ' . $address['city'] . '</td> <td>' . $address['country'] . '</td> <td>' . ($address['phone'] ? $address['phone'] . ($address['phone_mobile'] ? '<br />' . $address['phone_mobile'] : '') : ($address['phone_mobile'] ? '<br />' . $address['phone_mobile'] : '--')) . '</td> <td align="center"> <a href="?tab=AdminAddresses&id_address=' . $address['id_address'] . '&addaddress&token=' . $tokenAddresses . '"><img src="../img/admin/edit.gif" /></a> <a href="?tab=AdminAddresses&id_address=' . $address['id_address'] . '&deleteaddress&token=' . $tokenAddresses . '"><img src="../img/admin/delete.gif" /></a> </td> </tr>'; } echo ' </table>'; } else { echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has not registered any addresses yet') . '.'; } echo '<div class="clear"> </div> <h2>' . $this->l('Discounts') . ' (' . sizeof($discounts) . ')</h2>'; if (sizeof($discounts)) { echo ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th>' . $this->l('ID') . '</th> <th>' . $this->l('Code') . '</th> <th>' . $this->l('Type') . '</th> <th>' . $this->l('Value') . '</th> <th>' . $this->l('Qty available') . '</th> <th>' . $this->l('Status') . '</th> <th>' . $this->l('Actions') . '</th> </tr>'; $tokenDiscounts = Tools::getAdminToken('AdminDiscounts' . (int) Tab::getIdFromClassName('AdminDiscounts') . (int) $cookie->id_employee); foreach ($discounts as $discount) { echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . '> <td align="center">' . $discount['id_discount'] . '</td> <td>' . $discount['name'] . '</td> <td>' . $discount['type'] . '</td> <td align="right">' . $discount['value'] . '</td> <td align="center">' . $discount['quantity_for_user'] . '</td> <td align="center"><img src="../img/admin/' . ($discount['active'] ? 'enabled.gif' : 'disabled.gif') . '" alt="' . $this->l('Status') . '" title="' . $this->l('Status') . '" /></td> <td align="center"> <a href="?tab=AdminDiscounts&id_discount=' . $discount['id_discount'] . '&adddiscount&token=' . $tokenDiscounts . '"><img src="../img/admin/edit.gif" /></a> <a href="?tab=AdminDiscounts&id_discount=' . $discount['id_discount'] . '&deletediscount&token=' . $tokenDiscounts . '"><img src="../img/admin/delete.gif" /></a> </td> </tr>'; } echo ' </table>'; } else { echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has no discount vouchers') . '.'; } echo '<div class="clear"> </div>'; echo '<div style="float:left"> <h2>' . $this->l('Carts') . ' (' . sizeof($carts) . ')</h2>'; if ($carts and sizeof($carts)) { echo ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th class="center">' . $this->l('ID') . '</th> <th class="center">' . $this->l('Date') . '</th> <th class="center">' . $this->l('Total') . '</th> <th class="center">' . $this->l('Carrier') . '</th> <th class="center">' . $this->l('Actions') . '</th> </tr>'; $tokenCarts = Tools::getAdminToken('AdminCarts' . (int) Tab::getIdFromClassName('AdminCarts') . (int) $cookie->id_employee); foreach ($carts as $cart) { $cartI = new Cart((int) $cart['id_cart']); $summary = $cartI->getSummaryDetails(); $currency = new Currency((int) $cart['id_currency']); $carrier = new Carrier((int) $cart['id_carrier']); echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminCarts&id_cart=' . $cart['id_cart'] . '&viewcart&token=' . $tokenCarts . '\'"> <td class="center">' . sprintf('%06d', $cart['id_cart']) . '</td> <td>' . Tools::displayDate($cart['date_add'], (int) $cookie->id_lang, true) . '</td> <td align="right">' . Tools::displayPrice($summary['total_price'], $currency) . '</td> <td>' . $carrier->name . '</td> <td align="center"><a href="index.php?tab=AdminCarts&id_cart=' . $cart['id_cart'] . '&viewcart&token=' . $tokenCarts . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo ' </table>'; } else { echo $this->l('No cart available') . '.'; } echo '</div>'; $interested = Db::getInstance()->ExecuteS('SELECT DISTINCT id_product FROM ' . _DB_PREFIX_ . 'cart_product cp INNER JOIN ' . _DB_PREFIX_ . 'cart c on c.id_cart = cp.id_cart WHERE c.id_customer = ' . (int) $customer->id . ' AND cp.id_product NOT IN ( SELECT product_id FROM ' . _DB_PREFIX_ . 'orders o inner join ' . _DB_PREFIX_ . 'order_detail od ON o.id_order = od.id_order WHERE o.valid = 1 AND o.id_customer = ' . (int) $customer->id . ')'); if (count($interested)) { echo '<div style="float:left;margin-left:20px"> <h2>' . $this->l('Products') . ' (' . count($interested) . ')</h2> <table cellspacing="0" cellpadding="0" class="table">'; foreach ($interested as $p) { $product = new Product((int) $p['id_product'], false, $cookie->id_lang); echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'' . $link->getProductLink((int) $product->id, $product->link_rewrite, Category::getLinkRewrite($product->id_category_default, (int) $cookie->id_lang)) . '\'"> <td>' . (int) $product->id . '</td> <td>' . Tools::htmlentitiesUTF8($product->name) . '</td> <td align="center"><a href="' . $link->getProductLink((int) $product->id, $product->link_rewrite, Category::getLinkRewrite($product->id_category_default, (int) $cookie->id_lang)) . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo '</table></div>'; } echo '<div class="clear"> </div>'; /* Last connections */ $connections = $customer->getLastConnections(); if (sizeof($connections)) { echo '<h2>' . $this->l('Last connections') . '</h2> <table cellspacing="0" cellpadding="0" class="table"> <tr> <th style="width: 200px">' . $this->l('Date') . '</th> <th style="width: 100px">' . $this->l('Pages viewed') . '</th> <th style="width: 100px">' . $this->l('Total time') . '</th> <th style="width: 100px">' . $this->l('Origin') . '</th> <th style="width: 100px">' . $this->l('IP Address') . '</th> </tr>'; foreach ($connections as $connection) { echo '<tr> <td>' . Tools::displayDate($connection['date_add'], (int) $cookie->id_lang, true) . '</td> <td>' . (int) $connection['pages'] . '</td> <td>' . $connection['time'] . '</td> <td>' . ($connection['http_referer'] ? preg_replace('/^www./', '', parse_url($connection['http_referer'], PHP_URL_HOST)) : $this->l('Direct link')) . '</td> <td>' . $connection['ipaddress'] . '</td> </tr>'; } echo '</table><div class="clear"> </div>'; } if (sizeof($referrers)) { echo '<h2>' . $this->l('Referrers') . '</h2> <table cellspacing="0" cellpadding="0" class="table"> <tr> <th style="width: 200px">' . $this->l('Date') . '</th> <th style="width: 200px">' . $this->l('Name') . '</th> </tr>'; foreach ($referrers as $referrer) { echo '<tr> <td>' . Tools::displayDate($referrer['date_add'], (int) $cookie->id_lang, true) . '</td> <td>' . $referrer['name'] . '</td> </tr>'; } echo '</table><div class="clear"> </div>'; } echo '<a href="' . $currentIndex . '&token=' . $this->token . '"><img src="../img/admin/arrow2.gif" /> ' . $this->l('Back to customer list') . '</a><br />'; }
public function viewcustomer_thread() { global $cookie, $currentIndex; if (!($thread = $this->loadObject())) { return; } $cookie->{'customer_threadFilter_cl!id_contact'} = $thread->id_contact; $employees = Db::getInstance()->ExecuteS(' SELECT e.id_employee, e.firstname, e.lastname FROM ' . _DB_PREFIX_ . 'employee e WHERE e.active = 1 ORDER BY e.lastname ASC'); echo ' <h2>' . $this->l('Messages') . '</h2> <form action="' . Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']) . '" method="post" enctype="multipart/form-data"> <p> <img src="../img/admin/msg-forward.png" alt="" style="vertical-align: middle;" /> ' . $this->l('Forward this discussion to an employee:') . ' <select name="id_employee_forward" style="vertical-align: middle;" onchange=" if ($(this).val() >= 0) $(\'#message_forward\').show(400); else $(\'#message_forward\').hide(200); if ($(this).val() == 0) $(\'#message_forward_email\').show(200); else $(\'#message_forward_email\').hide(200); "> <option value="-1">' . $this->l('-- Choose --') . '</option> <option value="0">' . $this->l('Someone else') . '</option>'; foreach ($employees as $employee) { echo ' <option value="' . (int) $employee['id_employee'] . '">' . substr($employee['firstname'], 0, 1) . '. ' . $employee['lastname'] . '</option>'; } echo ' </select> <div id="message_forward_email" style="display:none"> <b>' . $this->l('E-mail') . '</b> <input type="text" name="email" /> </div> <div id="message_forward" style="display:none;margin-bottom:10px"> <textarea name="message_forward" style="width: 500px; height: 80px; margin-top: 15px;" onclick="if ($(this).val() == \'' . addslashes($this->l('You can add a comment here.')) . '\') { $(this).val(\'\'); }">' . $this->l('You can add a comment here.') . '</textarea><br /> <input type="Submit" name="submitForward" class="button" value="' . $this->l('Forward this discussion') . '" style="margin-top: 10px;" /> </div> </p> </form> <div class="clear"> </div>'; $messages = Db::getInstance()->ExecuteS(' SELECT ct.*, cm.*, cl.name subject, CONCAT(e.firstname, \' \', e.lastname) employee_name, CONCAT(c.firstname, \' \', c.lastname) customer_name, c.firstname FROM ' . _DB_PREFIX_ . 'customer_thread ct LEFT JOIN ' . _DB_PREFIX_ . 'customer_message cm ON (ct.id_customer_thread = cm.id_customer_thread) LEFT JOIN ' . _DB_PREFIX_ . 'contact_lang cl ON (cl.id_contact = ct.id_contact AND cl.id_lang = ' . (int) $cookie->id_lang . ') LEFT JOIN ' . _DB_PREFIX_ . 'employee e ON e.id_employee = cm.id_employee LEFT JOIN ' . _DB_PREFIX_ . 'customer c ON (IFNULL(ct.id_customer, ct.email) = IFNULL(c.id_customer, c.email)) WHERE ct.id_customer_thread = ' . (int) Tools::getValue('id_customer_thread') . ' ORDER BY cm.date_add DESC'); echo '<div style="float:right">'; $nextThread = Db::getInstance()->getValue(' SELECT id_customer_thread FROM ' . _DB_PREFIX_ . 'customer_thread ct WHERE ct.status = "open" AND ct.date_upd = ( SELECT date_add FROM ' . _DB_PREFIX_ . 'customer_message WHERE (id_employee IS NULL OR id_employee = 0) AND id_customer_thread = ' . (int) $thread->id . ' ORDER BY date_add DESC LIMIT 1 ) ' . ($cookie->{'customer_threadFilter_cl!id_contact'} ? 'AND ct.id_contact = ' . (int) $cookie->{'customer_threadFilter_cl!id_contact'} : '') . ' ' . ($cookie->{'customer_threadFilter_l!id_lang'} ? 'AND ct.id_lang = ' . (int) $cookie->{'customer_threadFilter_l!id_lang'} : '') . ' ORDER BY ct.date_upd ASC'); if ($nextThread) { echo $this->displayButton(' <a href="' . $currentIndex . '&id_customer_thread=' . (int) $nextThread . '&viewcustomer_thread&token=' . $this->token . '"> <img src="../img/admin/next-msg.png" title="' . $this->l('Go to the oldest next unanswered message') . '" style="margin-bottom: 10px;" /> <br />' . $this->l('Answer to the next unanswered message in this category') . ' > </a>'); } else { echo $this->displayButton(' <img src="../img/admin/msg-ok.png" title="' . $this->l('Go to the oldest next unanswered message') . '" style="margin-bottom: 10px;" /> <br />' . $this->l('The other messages in this category have been answered')); } if ($thread->status != "closed") { echo $this->displayButton(' <a href="' . $currentIndex . '&viewcustomer_thread&setstatus=2&id_customer_thread=' . Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token . '"> <img src="../img/admin/msg-ok.png" style="margin-bottom:10px" /> <br />' . $this->l('Set this message as handled') . ' </a>'); } if ($thread->status != "pending1") { echo $this->displayButton(' <a href="' . $currentIndex . '&viewcustomer_thread&setstatus=3&id_customer_thread=' . Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token . '"> <img src="../img/admin/msg-pending.png" style="margin-bottom:10px" /> <br />' . $this->l('Declare this message') . '<br />' . $this->l('as "pending 1"') . '<br />' . $this->l('(will be answered later)') . ' </a>'); } else { echo $this->displayButton(' <a href="' . $currentIndex . '&viewcustomer_thread&setstatus=1&id_customer_thread=' . Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token . '"> <img src="../img/admin/msg-is-pending.png" style="margin-bottom:10px" /> <br />' . $this->l('Click here to disable pending status') . ' </a>'); } if ($thread->status != "pending2") { echo $this->displayButton(' <a href="' . $currentIndex . '&viewcustomer_thread&setstatus=4&id_customer_thread=' . Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token . '"> <img src="../img/admin/msg-pending.png" style="margin-bottom:10px" /> <br />' . $this->l('Declare this message') . '<br />' . $this->l('as "pending 2"') . '<br />' . $this->l('(will be answered later)') . ' </a>'); } else { echo $this->displayButton(' <a href="' . $currentIndex . '&viewcustomer_thread&setstatus=1&id_customer_thread=' . Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token . '"> <img src="../img/admin/msg-is-pending.png" style="margin-bottom:10px" /> <br />' . $this->l('Click here to disable pending status') . ' </a>'); } echo '</div>'; if ($thread->id_customer) { $customer = new Customer($thread->id_customer); $products = $customer->getBoughtProducts(); $orders = Order::getCustomerOrders($customer->id); echo '<div style="float:left;width:600px">'; if ($orders and sizeof($orders)) { $totalOK = 0; $ordersOK = array(); $tokenOrders = Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $cookie->id_employee); foreach ($orders as $order) { if ($order['valid']) { $ordersOK[] = $order; $totalOK += $order['total_paid_real']; } } if ($countOK = sizeof($ordersOK)) { echo '<div style="float:left;margin-right:20px;"> <h2>' . $this->l('Orders') . '</h2> <table cellspacing="0" cellpadding="0" class="table float"> <tr> <th class="center">' . $this->l('ID') . '</th> <th class="center">' . $this->l('Date') . '</th> <th class="center">' . $this->l('Products') . '</th> <th class="center">' . $this->l('Total paid') . '</th> <th class="center">' . $this->l('Payment') . '</th> <th class="center">' . $this->l('State') . '</th> <th class="center">' . $this->l('Actions') . '</th> </tr>'; $irow = 0; foreach ($ordersOK as $order) { echo '<tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '\'"> <td class="center">' . $order['id_order'] . '</td> <td>' . Tools::displayDate($order['date_add'], (int) $cookie->id_lang) . '</td> <td align="right">' . $order['nb_products'] . '</td> <td align="right">' . Tools::displayPrice($order['total_paid_real'], new Currency((int) $order['id_currency'])) . '</td> <td>' . $order['payment'] . '</td> <td>' . $order['order_state'] . '</td> <td align="center"><a href="?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo '</table> <h3 style="color:green;font-weight:700;margin-top:10px">' . $this->l('Validated Orders:') . ' ' . $countOK . ' ' . $this->l('for') . ' ' . Tools::displayPrice($totalOK, new Currency(Configuration::get('PS_CURRENCY_DEFAULT'))) . '</h3> </div>'; } } if ($products and sizeof($products)) { echo '<div style="float:left;margin-right:20px"> <h2>' . $this->l('Products') . '</h2> <table cellspacing="0" cellpadding="0" class="table"> <tr> <th class="center">' . $this->l('Date') . '</th> <th class="center">' . $this->l('ID') . '</th> <th class="center">' . $this->l('Name') . '</th> <th class="center">' . $this->l('Quantity') . '</th> <th class="center">' . $this->l('Actions') . '</th> </tr>'; $irow = 0; $tokenOrders = Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $cookie->id_employee); foreach ($products as $product) { echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminOrders&id_order=' . $product['id_order'] . '&vieworder&token=' . $tokenOrders . '\'"> <td>' . Tools::displayDate($product['date_add'], (int) $cookie->id_lang, true) . '</td> <td>' . $product['product_id'] . '</td> <td>' . $product['product_name'] . '</td> <td align="right">' . $product['product_quantity'] . '</td> <td align="center"><a href="?tab=AdminOrders&id_order=' . $product['id_order'] . '&vieworder&token=' . $tokenOrders . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo '</table></div>'; } echo '</div>'; } echo '<div style="float:left;margin-top:10px">'; foreach ($messages as $message) { echo $this->displayMsg($message); } echo '</div><div class="clear"> </div>'; }
public function hookPayment($params) { if ($this->context->cart->getOrderTotal() < Configuration::get('PAYLATER_MIN_AMOUNT')) { return; } $currency_id = $params['cart']->id_currency; $currency = new Currency((int) $currency_id); if (in_array($currency->iso_code, $this->limited_currencies) == false) { return false; } $customer = new Customer((int) $params['cart']->id_customer); //prevent opening payment method if no credentials introduced if (Configuration::get('PAYLATER_ENVIRONMENT') == 0) { if (trim(Configuration::get('PAYLATER_ACCOUNT_ID_TEST')) == false || trim(Configuration::get('PAYLATER_ACCOUNT_KEY_TEST')) == false) { return false; } } else { if (trim(Configuration::get('PAYLATER_ACCOUNT_ID_LIVE')) == false || trim(Configuration::get('PAYLATER_ACCOUNT_KEY_LIVE')) == false) { return false; } } $cart_products = $this->context->cart->getProducts(); $items = array(); $desciption = array(); $discount = Configuration::get('PAYLATER_DISCOUNT'); $discount_boolean = $discount == 'true' ? 1 : 0; foreach ($cart_products as $p) { $items[] = array('description' => $p['name'] . " (" . $p['cart_quantity'] . ")", 'quantity' => $p['cart_quantity'], 'amount' => number_format($p['total_wt'], 2, '.', '')); $desciption[] = $p['name'] . " (" . $p['cart_quantity'] . ")"; } //Shipping address $saddress = new Address($this->context->cart->id_address_delivery); $sstreet = $saddress->address1 . ' ' . $saddress->address2; $scity = $saddress->city; $suser_state = new State($saddress->id_state); $sprovince = $suser_state->name; $szipcode = $saddress->postcode; $sphone = $saddress->phone; $smobile_phone = $saddress->phone_mobile; //shippingAddress $address2 = new Address($this->context->cart->id_address_invoice); $street = $address2->address1 . ' ' . $address2->address2; $city = $address2->city; $user_state2 = new State($address2->id_state); $province = $user_state2->name; $zipcode = $address2->postcode; $phone = $address2->phone; $mobile_phone = $address2->phone_mobile; //dni if (property_exists($address2, 'dni') == false) { $dni = ''; } else { $dni = $address2->dni; } //dynamic CallbackFilterIterator $callback_url = $this->getPagantisCallbackUrl('validation.php', array()); if (version_compare(_PS_VERSION_, "1.5", "<")) { $shippingCost = $this->context->cart->getOrderShippingCost(); } else { $shippingCost = $this->context->cart->getTotalShippingCost(null, true, null); } $url_OK = $this->getPagantisLink('confirmation.php', array('status' => 'ok', 'c' => $this->context->cart->id)); $url_NOK = $this->getPagantisLink('confirmation.php', array('status' => 'ko')); if (version_compare(_PS_VERSION_, "1.5", "<")) { $cancelled_url = $url_NOK; } else { $cancelled_url = _PS_BASE_URL_ . '/' . __PS_BASE_URI__ . 'index.php?controller=order'; } if ($shippingCost > 0) { $items[] = array('description' => $this->l('Shipping cost'), 'quantity' => 1, 'amount' => number_format($shippingCost, 2, '.', '')); $desciption[] = $this->l('Shipping cost'); } if (Configuration::get('PAYLATER_ENVIRONMENT') == 1) { //mode live $account_id = Configuration::get('PAYLATER_ACCOUNT_ID_LIVE'); } else { //mode test $account_id = Configuration::get('PAYLATER_ACCOUNT_ID_TEST'); } //discount $discount = Configuration::get('PAYLATER_DISCOUNT'); //1.4 fix if ($discount == '0') { $discount = 'false'; } if ($discount == '1') { $discount = 'true'; } $discount_boolean = $discount == 'true' ? 1 : 0; $iframe = Configuration::get('PAYLATER_IFRAME'); if ($iframe == 1) { $iframe = 'true'; } $endpoint = $this->url; $order_id = $this->context->cart->id; //description $description = implode(',', $desciption); $convert_price = Tools::convertPrice($this->context->cart->getOrderTotal(true, 3), $this->context->currency); $amount = number_format($convert_price, 2, '.', ''); $amount = str_replace('.', '', $amount); if (Configuration::get('PAYLATER_ENVIRONMENT') == 1) { $key_to_use = Configuration::get('PAYLATER_ACCOUNT_KEY_LIVE'); } else { $key_to_use = Configuration::get('PAYLATER_ACCOUNT_KEY_TEST'); } $widget_type = Configuration::get('PAYLATER_TYPE') == 'false' ? '0' : '1'; $total_paid = 0; $num_prev_orders = 0; $sign_up_date = ''; $num_partial_refunds = 0; $amount_refunded = 0; $num_full_refunds = 0; $super_checkout_enabled = false; $onepagecheckoutps_enabled = false; $onepagecheckout_enabled = false; if (version_compare(_PS_VERSION_, "1.5", "<")) { if ($this->context->cookie->logged) { $orders = Order::getCustomerOrders($this->context->customer->id); foreach ($orders as $o) { $total_paid += $o['total_paid']; $num_prev_orders++; } $sign_up_date = Tools::substr($this->context->customer->date_add, 0, 10); $order_slips = OrderSlip::getOrdersSlip((int) $this->context->cookie->id_customer); foreach ($order_slips as $o) { $num_full_refunds++; $amount_refunded += $o['amount']; } } } else { //query for paid statuses $sql = new DbQuery(); $sql->select('id_order_state'); $sql->from('order_state', 'c'); $sql->where('c.paid = 1'); $db_paid_statuses = Db::getInstance()->executeS($sql); $paid_statuses = []; foreach ($db_paid_statuses as $p) { $paid_statuses[] = $p['id_order_state']; } if ($this->context->cookie->logged) { $orders = Order::getCustomerOrders($this->context->customer->id); foreach ($orders as $o) { if (array_key_exists('id_order_state', $o) && in_array($o['id_order_state'], $paid_statuses)) { $total_paid += $o['total_paid']; $num_prev_orders++; } } $sign_up_date = Tools::substr($this->context->customer->date_add, 0, 10); $order_slips = OrderSlip::getOrdersSlip((int) $this->context->cookie->id_customer); foreach ($order_slips as $o) { $sql = new DbQuery(); $sql->select('total_paid'); $sql->from('orders', 'c'); $sql->where('c.id_order = ' . $o['id_order']); $db_total_paid = Db::getInstance()->executeS($sql); if ($db_total_paid[0]['total_paid'] <= $o['amount']) { $num_full_refunds++; } else { $num_partial_refunds++; } $amount_refunded += $o['amount']; } } $super_checkout_enabled = Module::isEnabled('supercheckout'); $onepagecheckoutps_enabled = Module::isEnabled('onepagecheckoutps'); $onepagecheckout_enabled = Module::isEnabled('onepagecheckout'); } //d($key_to_use.$account_id.$order_id.$amount.$this->context->currency->iso_code.$url_OK.$url_NOK); $text = $key_to_use . $account_id . $order_id . $amount . $this->context->currency->iso_code . $url_OK . $url_NOK . $callback_url . $discount . $cancelled_url; $signature = hash('sha512', $text); $this->smarty->assign(array('endpoint' => $endpoint, 'account_id' => $account_id, 'currency' => $this->context->currency->iso_code, 'ok_url' => $url_OK, 'nok_url' => $url_NOK, 'cancelled_url' => $cancelled_url, 'order_id' => $order_id, 'amount' => $amount, 'description' => $description, 'items' => $items, 'signature' => $signature, 'customer_name' => $this->context->cookie->logged ? $this->context->cookie->customer_firstname . ' ' . $this->context->cookie->customer_lastname : $customer->firstname . " " . $customer->lastname, 'customer_email' => $this->context->cookie->logged ? $this->context->cookie->email : $customer->email, 'locale' => $this->context->language->iso_code, 'cart_products' => $cart_products, 'street' => $street, 'city' => $city, 'province' => $province, 'zipcode' => $zipcode, 'sstreet' => $sstreet, 'scity' => $scity, 'sprovince' => $sprovince, 'szipcode' => $szipcode, 'phone' => $phone, 'mobile_phone' => $mobile_phone, 'dni' => $dni, 'callback_url' => $callback_url, 'discount' => $discount, 'discount_boolean' => $discount_boolean, 'dob' => $this->context->customer->birthday ? $this->context->customer->birthday : $customer->birthday, 'iframe' => $iframe, 'total_paid' => $total_paid, 'num_prev_orders' => $num_prev_orders, 'sign_up_date' => $sign_up_date, 'amount_refunded' => $amount_refunded, 'num_full_refunds' => $num_full_refunds, 'num_partial_refunds' => $num_partial_refunds, 'version4' => version_compare(_PS_VERSION_, "1.5", "<"), 'version3' => version_compare(_PS_VERSION_, "1.4", "<"), 'content' => "javascript:\$('#paylater_form').submit();")); if ($super_checkout_enabled) { return $this->display(__FILE__, 'views/templates/front/payment_supercheckout.tpl'); } elseif ($onepagecheckoutps_enabled || $onepagecheckout_enabled) { return $this->display(__FILE__, 'views/templates/front/payment.tpl'); } elseif ($widget_type) { return $this->display(__FILE__, 'views/templates/front/payment_widget.tpl'); } else { return $this->display(__FILE__, 'views/templates/front/payment.tpl'); } }
public function getTemplateVarOrders() { $orders = array(); if (!isset($this->customer_thread['id_order']) && $this->context->customer->isLogged()) { $customer_orders = Order::getCustomerOrders($this->context->customer->id); foreach ($customer_orders as $customer_order) { $myOrder = new Order((int) $customer_order['id_order']); if (Validate::isLoadedObject($myOrder)) { $orders[$customer_order['id_order']] = $customer_order; $orders[$customer_order['id_order']]['products'] = $myOrder->getProducts(); } } } elseif ((int) $this->customer_thread['id_order'] > 0) { $myOrder = new Order($this->customer_thread['id_order']); if (Validate::isLoadedObject($myOrder)) { $orders[$myOrder->id] = $this->context->controller->objectPresenter->present($myOrder); $orders[$myOrder->id]['id_order'] = $myOrder->id; $orders[$myOrder->id]['products'] = $myOrder->getProducts(); } } if ($this->customer_thread['id_product']) { $id_order = 0; if (isset($this->customer_thread['id_order'])) { $id_order = (int) $this->customer_thread['id_order']; } $orders[$id_order]['products'][(int) $this->customer_thread['id_product']] = $this->context->controller->objectPresenter->present(new Product((int) $this->customer_thread['id_product'])); } return $orders; }
public function renderView() { /** @var Customer $customer */ if (!($customer = $this->loadObject())) { return; } $this->context->customer = $customer; $gender = new Gender($customer->id_gender, $this->context->language->id); $gender_image = $gender->getImage(); $customer_stats = $customer->getStats(); $sql = 'SELECT SUM(total_paid_real) FROM ' . _DB_PREFIX_ . 'orders WHERE id_customer = %d AND valid = 1'; if ($total_customer = Db::getInstance()->getValue(sprintf($sql, $customer->id))) { $sql = 'SELECT SQL_CALC_FOUND_ROWS COUNT(*) FROM ' . _DB_PREFIX_ . 'orders WHERE valid = 1 AND id_customer != ' . (int) $customer->id . ' GROUP BY id_customer HAVING SUM(total_paid_real) > %d'; Db::getInstance()->getValue(sprintf($sql, (int) $total_customer)); $count_better_customers = (int) Db::getInstance()->getValue('SELECT FOUND_ROWS()') + 1; } else { $count_better_customers = '-'; } $orders = Order::getCustomerOrders($customer->id, true); $total_orders = count($orders); for ($i = 0; $i < $total_orders; $i++) { $orders[$i]['total_paid_real_not_formated'] = $orders[$i]['total_paid_real']; $orders[$i]['total_paid_real'] = Tools::displayPrice($orders[$i]['total_paid_real'], new Currency((int) $orders[$i]['id_currency'])); } $messages = CustomerThread::getCustomerMessages((int) $customer->id); $total_messages = count($messages); for ($i = 0; $i < $total_messages; $i++) { $messages[$i]['message'] = substr(strip_tags(html_entity_decode($messages[$i]['message'], ENT_NOQUOTES, 'UTF-8')), 0, 75); $messages[$i]['date_add'] = Tools::displayDate($messages[$i]['date_add'], null, true); if (isset(self::$meaning_status[$messages[$i]['status']])) { $messages[$i]['status'] = self::$meaning_status[$messages[$i]['status']]; } } $groups = $customer->getGroups(); $total_groups = count($groups); for ($i = 0; $i < $total_groups; $i++) { $group = new Group($groups[$i]); $groups[$i] = array(); $groups[$i]['id_group'] = $group->id; $groups[$i]['name'] = $group->name[$this->default_form_language]; } $total_ok = 0; $orders_ok = array(); $orders_ko = array(); foreach ($orders as $order) { if (!isset($order['order_state'])) { $order['order_state'] = $this->l('There is no status defined for this order.'); } if ($order['valid']) { $orders_ok[] = $order; $total_ok += $order['total_paid_real_not_formated']; } else { $orders_ko[] = $order; } } $products = $customer->getBoughtProducts(); $carts = Cart::getCustomerCarts($customer->id); $total_carts = count($carts); for ($i = 0; $i < $total_carts; $i++) { $cart = new Cart((int) $carts[$i]['id_cart']); $this->context->cart = $cart; $summary = $cart->getSummaryDetails(); $currency = new Currency((int) $carts[$i]['id_currency']); $carrier = new Carrier((int) $carts[$i]['id_carrier']); $carts[$i]['id_cart'] = sprintf('%06d', $carts[$i]['id_cart']); $carts[$i]['date_add'] = Tools::displayDate($carts[$i]['date_add'], null, true); $carts[$i]['total_price'] = Tools::displayPrice($summary['total_price'], $currency); $carts[$i]['name'] = $carrier->name; } $sql = 'SELECT DISTINCT cp.id_product, c.id_cart, c.id_shop, cp.id_shop AS cp_id_shop FROM ' . _DB_PREFIX_ . 'cart_product cp JOIN ' . _DB_PREFIX_ . 'cart c ON (c.id_cart = cp.id_cart) JOIN ' . _DB_PREFIX_ . 'product p ON (cp.id_product = p.id_product) WHERE c.id_customer = ' . (int) $customer->id . ' AND NOT EXISTS ( SELECT 1 FROM ' . _DB_PREFIX_ . 'orders o JOIN ' . _DB_PREFIX_ . 'order_detail od ON (o.id_order = od.id_order) WHERE product_id = cp.id_product AND o.valid = 1 AND o.id_customer = ' . (int) $customer->id . ' )'; $interested = Db::getInstance()->executeS($sql); $total_interested = count($interested); for ($i = 0; $i < $total_interested; $i++) { $product = new Product($interested[$i]['id_product'], false, $this->default_form_language, $interested[$i]['id_shop']); if (!Validate::isLoadedObject($product)) { continue; } $interested[$i]['url'] = $this->context->link->getProductLink($product->id, $product->link_rewrite, Category::getLinkRewrite($product->id_category_default, $this->default_form_language), null, null, $interested[$i]['cp_id_shop']); $interested[$i]['id'] = (int) $product->id; $interested[$i]['name'] = Tools::htmlentitiesUTF8($product->name); } $emails = $customer->getLastEmails(); $connections = $customer->getLastConnections(); if (!is_array($connections)) { $connections = array(); } $total_connections = count($connections); for ($i = 0; $i < $total_connections; $i++) { $connections[$i]['http_referer'] = $connections[$i]['http_referer'] ? preg_replace('/^www./', '', parse_url($connections[$i]['http_referer'], PHP_URL_HOST)) : $this->l('Direct link'); } $referrers = Referrer::getReferrers($customer->id); $total_referrers = count($referrers); for ($i = 0; $i < $total_referrers; $i++) { $referrers[$i]['date_add'] = Tools::displayDate($referrers[$i]['date_add'], null, true); } $customerLanguage = new Language($customer->id_lang); $shop = new Shop($customer->id_shop); $this->tpl_view_vars = array('customer' => $customer, 'gender' => $gender, 'gender_image' => $gender_image, 'registration_date' => Tools::displayDate($customer->date_add, null, true), 'customer_stats' => $customer_stats, 'last_visit' => Tools::displayDate($customer_stats['last_visit'], null, true), 'count_better_customers' => $count_better_customers, 'shop_is_feature_active' => Shop::isFeatureActive(), 'name_shop' => $shop->name, 'customer_birthday' => Tools::displayDate($customer->birthday), 'last_update' => Tools::displayDate($customer->date_upd, null, true), 'customer_exists' => Customer::customerExists($customer->email), 'id_lang' => $customer->id_lang, 'customerLanguage' => $customerLanguage, 'customer_note' => Tools::htmlentitiesUTF8($customer->note), 'messages' => $messages, 'groups' => $groups, 'orders' => $orders, 'orders_ok' => $orders_ok, 'orders_ko' => $orders_ko, 'total_ok' => Tools::displayPrice($total_ok, $this->context->currency->id), 'products' => $products, 'addresses' => $customer->getAddresses($this->default_form_language), 'discounts' => CartRule::getCustomerCartRules($this->default_form_language, $customer->id, false, false), 'carts' => $carts, 'interested' => $interested, 'emails' => $emails, 'connections' => $connections, 'referrers' => $referrers, 'show_toolbar' => true); return parent::renderView(); }
public function viewcustomer() { global $currentIndex, $cookie; $irow = 0; $configurations = Configuration::getMultiple(array('PS_LANG_DEFAULT', 'PS_CURRENCY_DEFAULT')); $defaultLanguage = intval($configurations['PS_LANG_DEFAULT']); $defaultCurrency = intval($configurations['PS_CURRENCY_DEFAULT']); $customer = $this->loadObject(); $customerStats = $customer->getStats(); $addresses = $customer->getAddresses($defaultLanguage); $discounts = Discount::getCustomerDiscounts($defaultLanguage, $customer->id, false, false); $orders = Order::getCustomerOrders($customer->id); $carts = Cart::getCustomerCarts($customer->id); $groups = $customer->getGroups(); $referrers = Referrer::getReferrers($customer->id); echo ' <div style="float: left"> <fieldset style="width: 400px"><div style="float: right"><a href="' . $currentIndex . '&addcustomer&id_customer=' . $customer->id . '&token=' . $this->token . '"><img src="../img/admin/edit.gif" /></a></div> <span style="font-weight: bold; font-size: 14px;">' . $customer->firstname . ' ' . $customer->lastname . '</span> <img src="../img/admin/' . ($customer->id_gender == 2 ? 'female' : ($customer->id_gender == 1 ? 'male' : 'unknown')) . '.gif" style="margin-bottom: 5px" /><br /> <a href="mailto:' . $customer->email . '" style="text-decoration: underline; color: blue">' . $customer->email . '</a><br /><br /> ' . $this->l('ID:') . ' ' . sprintf('%06d', $customer->id) . '<br /> ' . $this->l('Registration date:') . ' ' . Tools::displayDate($customer->date_add, intval($cookie->id_lang), true) . '<br /> ' . $this->l('Last visit:') . ' ' . ($customerStats['last_visit'] ? Tools::displayDate($customerStats['last_visit'], intval($cookie->id_lang), true) : $this->l('never')) . ' </fieldset> </div> <div style="float: left; margin-left: 50px"> <fieldset style="width: 300px"><div style="float: right"><a href="' . $currentIndex . '&addcustomer&id_customer=' . $customer->id . '&token=' . $this->token . '"><img src="../img/admin/edit.gif" /></a></div> ' . $this->l('Newsletter:') . ' ' . ($customer->newsletter ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />') . '<br /> ' . $this->l('Opt-in:') . ' ' . ($customer->optin ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />') . '<br /> ' . $this->l('Age:') . ' ' . $customerStats['age'] . ' ' . (!empty($customer->birthday['age']) ? '(' . Tools::displayDate($customer->birthday, intval($cookie->id_lang)) . ')' : $this->l('unknown')) . '<br /><br /> ' . $this->l('Last update:') . ' ' . Tools::displayDate($customer->date_upd, intval($cookie->id_lang), true) . '<br /> ' . $this->l('Status:') . ' ' . ($customer->active ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />') . ' </fieldset> </div> <div class="clear"> </div>'; // display hook specified to this page : AdminCustomers if (($hook = Module::hookExec('adminCustomers', array('id_customer' => $customer->id))) !== false) { echo '<div>' . $hook . '</div>'; } echo '<h2>' . $this->l('Groups') . ' (' . sizeof($groups) . ')</h2>'; if ($groups and sizeof($groups)) { echo ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th class="center">' . $this->l('ID') . '</th> <th class="center">' . $this->l('Name') . '</th> <th class="center">' . $this->l('Actions') . '</th> </tr>'; $tokenGroups = Tools::getAdminToken('AdminGroups' . intval(Tab::getIdFromClassName('AdminGroups')) . intval($cookie->id_employee)); foreach ($groups as $group) { $objGroup = new Group($group); echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminGroups&id_group=' . $objGroup->id . '&viewgroup&token=' . $tokenGroups . '\'"> <td class="center">' . $objGroup->id . '</td> <td>' . $objGroup->name[$defaultLanguage] . '</td> <td align="center"><a href="?tab=AdminGroups&id_group=' . $objGroup->id . '&viewgroup&token=' . $tokenGroups . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo ' </table>'; } echo '<div class="clear"> </div>'; echo '<h2>' . $this->l('Orders') . ' (' . sizeof($orders) . ')</h2>'; if ($orders and sizeof($orders)) { echo ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th class="center">' . $this->l('ID') . '</th> <th class="center">' . $this->l('Date') . '</th> <th class="center">' . $this->l('Quantity') . '</th> <th class="center">' . $this->l('Total') . '</th> <th class="center">' . $this->l('Payment') . '</th> <th class="center">' . $this->l('State') . '</th> <th class="center">' . $this->l('Actions') . '</th> </tr>'; $tokenOrders = Tools::getAdminToken('AdminOrders' . intval(Tab::getIdFromClassName('AdminOrders')) . intval($cookie->id_employee)); foreach ($orders as $order) { echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '\'"> <td class="center">' . sprintf('%06d', $order['id_order']) . '</td> <td>' . Tools::displayDate($order['date_add'], intval($cookie->id_lang), true) . '</td> <td align="right">' . $order['nb_products'] . '</td> <td align="right">' . Tools::displayPrice($order['total_paid'], new Currency(intval($order['id_currency']))) . '</td> <td>' . $order['payment'] . '</td> <td>' . $order['order_state'] . '</td> <td align="center"><a href="?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo ' </table>'; } else { echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has placed no orders yet'); } echo '<div class="clear"> </div> <h2>' . $this->l('Addresses') . ' (' . sizeof($addresses) . ')</h2>'; if (sizeof($addresses)) { echo ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th>' . $this->l('Company') . '</th> <th>' . $this->l('Name') . '</th> <th>' . $this->l('Address') . '</th> <th>' . $this->l('Country') . '</th> <th>' . $this->l('Phone number(s)') . '</th> <th>' . $this->l('Actions') . '</th> </tr>'; $tokenAddresses = Tools::getAdminToken('AdminAddresses' . intval(Tab::getIdFromClassName('AdminAddresses')) . intval($cookie->id_employee)); foreach ($addresses as $address) { echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . '> <td>' . ($address['company'] ? $address['company'] : '--') . '</td> <td>' . $address['firstname'] . ' ' . $address['lastname'] . '</td> <td>' . $address['address1'] . ($address['address2'] ? ' ' . $address['address2'] : '') . ' ' . $address['postcode'] . ' ' . $address['city'] . '</td> <td>' . $address['country'] . '</td> <td>' . ($address['phone'] ? $address['phone'] . ($address['phone_mobile'] ? '<br />' . $address['phone_mobile'] : '') : ($address['phone_mobile'] ? '<br />' . $address['phone_mobile'] : '--')) . '</td> <td align="center"> <a href="?tab=AdminAddresses&id_address=' . $address['id_address'] . '&addaddress&token=' . $tokenAddresses . '"><img src="../img/admin/edit.gif" /></a> <a href="?tab=AdminAddresses&id_address=' . $address['id_address'] . '&deleteaddress&token=' . $tokenAddresses . '"><img src="../img/admin/delete.gif" /></a> </td> </tr>'; } echo ' </table>'; } else { echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has registered no addresses yet') . '.'; } echo '<div class="clear"> </div> <h2>' . $this->l('Discounts') . ' (' . sizeof($discounts) . ')</h2>'; if (sizeof($discounts)) { echo ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th>' . $this->l('ID') . '</th> <th>' . $this->l('Code') . '</th> <th>' . $this->l('Type') . '</th> <th>' . $this->l('Value') . '</th> <th>' . $this->l('Qty available') . '</th> <th>' . $this->l('Status') . '</th> <th>' . $this->l('Actions') . '</th> </tr>'; $tokenDiscounts = Tools::getAdminToken('AdminDiscounts' . intval(Tab::getIdFromClassName('AdminDiscounts')) . intval($cookie->id_employee)); foreach ($discounts as $discount) { echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . '> <td align="center">' . $discount['id_discount'] . '</td> <td>' . $discount['name'] . '</td> <td>' . $discount['type'] . '</td> <td align="right">' . $discount['value'] . '</td> <td align="center">' . $discount['quantity_for_user'] . '</td> <td align="center"><img src="../img/admin/' . ($discount['active'] ? 'enabled.gif' : 'disabled.gif') . '" alt="' . $this->l('Status') . '" title="' . $this->l('Status') . '" /></td> <td align="center"> <a href="?tab=AdminDiscounts&id_discount=' . $discount['id_discount'] . '&adddiscount&token=' . $tokenDiscounts . '"><img src="../img/admin/edit.gif" /></a> <a href="?tab=AdminDiscounts&id_discount=' . $discount['id_discount'] . '&deletediscount&token=' . $tokenDiscounts . '"><img src="../img/admin/delete.gif" /></a> </td> </tr>'; } echo ' </table>'; } else { echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has no discount vouchers') . '.'; } echo '<div class="clear"> </div>'; echo '<h2>' . $this->l('Carts') . ' (' . sizeof($carts) . ')</h2>'; if ($carts and sizeof($carts)) { echo ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th class="center">' . $this->l('ID') . '</th> <th class="center">' . $this->l('Date') . '</th> <th class="center">' . $this->l('Total') . '</th> <th class="center">' . $this->l('Carrier') . '</th> <th class="center">' . $this->l('Actions') . '</th> </tr>'; $tokenCarts = Tools::getAdminToken('AdminCarts' . intval(Tab::getIdFromClassName('AdminCarts')) . intval($cookie->id_employee)); foreach ($carts as $cart) { $cartI = new Cart(intval($cart['id_cart'])); $summary = $cartI->getSummaryDetails(); $currency = new Currency(intval($cart['id_currency'])); $carrier = new Carrier(intval($cart['id_carrier'])); echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminCarts&id_cart=' . $cart['id_cart'] . '&viewcart&token=' . $tokenCarts . '\'"> <td class="center">' . sprintf('%06d', $cart['id_cart']) . '</td> <td>' . Tools::displayDate($cart['date_add'], intval($cookie->id_lang), true) . '</td> <td align="right">' . Tools::displayPrice($summary['total_price'], $currency) . '</td> <td>' . $carrier->name . '</td> <td align="center"><a href="?tab=AdminCarts&id_cart=' . $cart['id_cart'] . '&viewcart&token=' . $tokenCarts . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo ' </table>'; } else { echo $this->l('No cart available') . '.'; } echo '<div class="clear"> </div>'; /* Last connections */ $connections = $customer->getLastConnections(); if (sizeof($connections)) { echo '<h2>' . $this->l('Last connections') . '</h2> <table cellspacing="0" cellpadding="0" class="table"> <tr> <th style="width: 200px">' . $this->l('Date') . '</th> <th style="width: 100px">' . $this->l('Pages viewed') . '</th> <th style="width: 100px">' . $this->l('Total time') . '</th> <th style="width: 100px">' . $this->l('Origin') . '</th> <th style="width: 100px">' . $this->l('IP Address') . '</th> </tr>'; foreach ($connections as $connection) { echo '<tr> <td>' . Tools::displayDate($connection['date_add'], intval($cookie->id_lang), true) . '</td> <td>' . intval($connection['pages']) . '</td> <td>' . $connection['time'] . '</td> <td>' . ($connection['http_referer'] ? preg_replace('/^www./', '', parse_url($connection['http_referer'], PHP_URL_HOST)) : $this->l('Direct link')) . '</td> <td>' . $connection['ipaddress'] . '</td> </tr>'; } echo '</table><div class="clear"> </div>'; } if (sizeof($referrers)) { echo '<h2>' . $this->l('Referrers') . '</h2> <table cellspacing="0" cellpadding="0" class="table"> <tr> <th style="width: 200px">' . $this->l('Date') . '</th> <th style="width: 200px">' . $this->l('Name') . '</th> </tr>'; foreach ($referrers as $referrer) { echo '<tr> <td>' . Tools::displayDate($referrer['date_add'], intval($cookie->id_lang), true) . '</td> <td>' . $referrer['name'] . '</td> </tr>'; } echo '</table><div class="clear"> </div>'; } echo '<a href="' . $currentIndex . '&token=' . $this->token . '"><img src="../img/admin/arrow2.gif" /> ' . $this->l('Back to customer list') . '</a><br />'; }
<?php /* SSL Management */ $useSSL = true; include dirname(__FILE__) . '/config/config.inc.php'; include dirname(__FILE__) . '/init.php'; if (!$cookie->isLogged()) { Tools::redirect('authentication.php?back=history.php'); } /* JS files call */ $js_files = array(__PS_BASE_URI__ . 'js/jquery/jquery.scrollto.js', _THEME_JS_DIR_ . 'history.js'); if ($orders = Order::getCustomerOrders(intval($cookie->id_customer))) { foreach ($orders as &$order) { $myOrder = new Order(intval($order['id_order'])); if (Validate::isLoadedObject($myOrder)) { $order['virtual'] = $myOrder->isVirtual(false); } } } include dirname(__FILE__) . '/header.php'; $smarty->assign(array('orders' => $orders, 'invoiceAllowed' => intval(Configuration::get('PS_INVOICE')))); $smarty->display(_PS_THEME_DIR_ . 'history.tpl'); include dirname(__FILE__) . '/footer.php';
public function displayAjaxSearchCarts() { $id_customer = (int) Tools::getValue('id_customer'); $carts = Cart::getCustomerCarts((int) $id_customer); $orders = Order::getCustomerOrders((int) $id_customer); $customer = new Customer((int) $id_customer); if (count($carts)) { foreach ($carts as $key => &$cart) { $cart_obj = new Cart((int) $cart['id_cart']); if ($cart['id_cart'] == $this->context->cart->id || !Validate::isLoadedObject($cart_obj) || $cart_obj->OrderExists()) { unset($carts[$key]); } $currency = new Currency((int) $cart['id_currency']); $cart['total_price'] = Tools::displayPrice($cart_obj->getOrderTotal(), $currency); } } if (count($orders)) { foreach ($orders as &$order) { $order['total_paid_real'] = Tools::displayPrice($order['total_paid_real'], $currency); } } if ($orders || $carts) { $to_return = array_merge($this->ajaxReturnVars(), array('carts' => $carts, 'orders' => $orders, 'found' => true)); } else { $to_return = array_merge($this->ajaxReturnVars(), array('found' => false)); } echo Tools::jsonEncode($to_return); }
public function renderView() { if (!($id_customer_thread = (int) Tools::getValue('id_customer_thread'))) { return; } $this->context = Context::getContext(); if (!($thread = $this->loadObject())) { return; } $this->context->cookie->{'customer_threadFilter_cl!id_contact'} = $thread->id_contact; $employees = Employee::getEmployees(); $messages = CustomerThread::getMessageCustomerThreads($id_customer_thread); $next_thread = CustomerThread::getNextThread((int) $thread->id); $actions = array(); if ($next_thread) { $actions['next_thread'] = array('href' => self::$currentIndex . '&id_customer_thread=' . (int) $next_thread . '&viewcustomer_thread&token=' . $this->token, 'name' => $this->l('Reply to the next unanswered message in this category.')); } else { $actions['next_thread'] = array('href' => false, 'name' => $this->l('All other messages in this category have been answered.')); } if ($thread->status != 'closed') { $actions['closed'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=2&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'name' => $this->l('Mark this message as handled.')); } if ($thread->status != 'pending1') { $actions['pending1'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=3&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'name' => $this->l('Mark this message as "pending 1" (will be answered later).')); } else { $actions['pending1'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=1&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'name' => $this->l('Disable pending status.')); } if ($thread->status != 'pending2') { $actions['pending2'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=4&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'name' => $this->l('Mark this message as "pending 2" (will be answered later).')); } else { $actions['pending2'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=1&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'name' => $this->l('Disable pending status.')); } if ($thread->id_customer) { $customer = new Customer($thread->id_customer); $orders = Order::getCustomerOrders($customer->id); if ($orders && count($orders)) { $total_ok = 0; $orders_ok = array(); foreach ($orders as $key => $order) { if ($order['valid']) { $orders_ok[] = $order; $total_ok += $order['total_paid_real']; } $orders[$key]['date_add'] = Tools::displayDate($order['date_add']); $orders[$key]['total_paid_real'] = Tools::displayPrice($order['total_paid_real'], new Currency((int) $order['id_currency'])); } } $products = $customer->getBoughtProducts(); if ($products && count($products)) { foreach ($products as $key => $product) { $products[$key]['date_add'] = Tools::displayDate($product['date_add'], null, true); } } } foreach ($messages as $key => $message) { $messages[$key] = $this->displayMessage($message); } $this->tpl_view_vars = array('id_customer_thread' => $id_customer_thread, 'thread' => $thread, 'actions' => $actions, 'employees' => $employees, 'messages' => $messages, 'next_thread' => $next_thread, 'orders' => isset($orders) ? $orders : false, 'customer' => isset($customer) ? $customer : false, 'products' => isset($products) ? $products : false, 'total_ok' => isset($total_ok) ? Tools::displayPrice($total_ok, $this->context->currency) : false, 'orders_ok' => isset($orders_ok) ? $orders_ok : false, 'count_ok' => isset($orders_ok) ? count($orders_ok) : false); return parent::renderView(); }
protected function getOrderByReference($order_reference) { if ($orders = Order::getCustomerOrders($this->customer_id)) { foreach ($orders as $o) { if ($o['reference'] == $order_reference) { return $o; } } } return null; }
/** * Hook display in tab AdminCustomers on BO * Data table with all sponsors informations for a customer */ public function hookAdminCustomers($params) { include_once dirname(__FILE__) . '/ReferralProgramModule.php'; $customer = new Customer((int) $params['id_customer']); $sponsor = null; if (!Validate::isLoadedObject($customer)) { die($this->l('Incorrect Customer object.')); } $friends = ReferralProgramModule::getSponsorFriend((int) $customer->id); if ($id_referralprogram = ReferralProgramModule::isSponsorised((int) $customer->id, true)) { $referralprogram = new ReferralProgramModule((int) $id_referralprogram); $sponsor = new Customer((int) $referralprogram->id_sponsor); } foreach ($friends as $key => &$friend) { $friend['orders_count'] = sizeof(Order::getCustomerOrders($friend['id_customer'])); $friend['date_add'] = Tools::displayDate($friend['date_add'], null, true); $friend['sponsored_friend_count'] = sizeof(ReferralProgramModule::getSponsorFriend($friend['id_customer'])); } $this->smarty->assign(array('friends' => $friends, 'sponsor' => $sponsor, 'customer' => $customer, 'admin_image_dir' => _PS_ADMIN_IMG_, 'token' => Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $this->context->employee->id))); if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { return $this->display(__FILE__, 'hook_customers_16.tpl'); } else { return $this->display(__FILE__, 'hook_customers.tpl'); } }
/** * Hook display in tab AdminCustomers on BO * Data table with all sponsors informations for a customer */ public function hookAdminCustomers($params) { include_once dirname(__FILE__) . '/ReferralProgramModule.php'; $customer = new Customer((int) $params['id_customer']); if (!Validate::isLoadedObject($customer)) { die($this->l('Incorrect Customer object.')); } $friends = ReferralProgramModule::getSponsorFriend((int) $customer->id); if ($id_referralprogram = ReferralProgramModule::isSponsorised((int) $customer->id, true)) { $referralprogram = new ReferralProgramModule((int) $id_referralprogram); $sponsor = new Customer((int) $referralprogram->id_sponsor); } $html = ' <div class="clear"> </div> <h2>' . $this->l('Referral program') . ' (' . count($friends) . ')</h2> <h3>' . (isset($sponsor) ? $this->l('Customer\'s sponsor:') . ' <a href="index.php?tab=AdminCustomers&id_customer=' . (int) $sponsor->id . '&viewcustomer&token=' . Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $this->context->employee->id) . '">' . $sponsor->firstname . ' ' . $sponsor->lastname . '</a>' : $this->l('No one has sponsored this customer.')) . '</h3>'; if ($friends and sizeof($friends)) { $html .= '<h3>' . sizeof($friends) . ' ' . (sizeof($friends) > 1 ? $this->l('Sponsored customers:') : $this->l('Sponsored customer:')) . '</h3>'; $html .= ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th class="center">' . $this->l('ID') . '</th> <th class="center">' . $this->l('Name') . '</th> <th class="center">' . $this->l('Email') . '</th> <th class="center">' . $this->l('Registration date') . '</th> <th class="center">' . $this->l('Customers sponsored by this friend') . '</th> <th class="center">' . $this->l('Placed orders') . '</th> <th class="center">' . $this->l('Customer account created') . '</th> </tr>'; foreach ($friends as $key => $friend) { $orders = Order::getCustomerOrders($friend['id_customer']); $html .= ' <tr ' . ($key++ % 2 ? 'class="alt_row"' : '') . ' ' . ((int) $friend['id_customer'] ? 'style="cursor: pointer" onclick="document.location = \'?tab=AdminCustomers&id_customer=' . $friend['id_customer'] . '&viewcustomer&token=' . Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $this->context->employee->id) . '\'"' : '') . '> <td class="center">' . ((int) $friend['id_customer'] ? $friend['id_customer'] : '--') . '</td> <td>' . $friend['firstname'] . ' ' . $friend['lastname'] . '</td> <td>' . $friend['email'] . '</td> <td>' . Tools::displayDate($friend['date_add'], $this->context->language->id, true) . '</td> <td align="right">' . sizeof(ReferralProgramModule::getSponsorFriend($friend['id_customer'])) . '</td> <td align="right">' . ($orders ? sizeof($orders) : 0) . '</td> <td align="center">' . ((int) $friend['id_customer'] ? '<img src="' . _PS_ADMIN_IMG_ . 'enabled.gif" />' : '<img src="' . _PS_ADMIN_IMG_ . 'disabled.gif" />') . '</td> </tr>'; } $html .= ' </table>'; } else { $html .= sprintf($this->l('%1$s %2$s has not sponsored any friends yet.'), $customer->firstname, $customer->lastname); } return $html . '<br/><br/>'; }
public static function getLastOrder($id_customer) { $customerOrders = Order::getCustomerOrders($id_customer); return reset($customerOrders); }