/** * Assign summary template */ public function assignSummaryExecution() { $customer_points = (int) LoyaltyModule::getPointsByCustomer((int) $this->context->customer->id); $orders = LoyaltyModule::getAllByIdCustomer((int) $this->context->customer->id, (int) $this->context->language->id); $displayorders = LoyaltyModule::getAllByIdCustomer((int) $this->context->customer->id, (int) $this->context->language->id, false, true, (int) Tools::getValue('n') > 0 ? (int) Tools::getValue('n') : 10, (int) Tools::getValue('p') > 0 ? (int) Tools::getValue('p') : 1); $this->context->smarty->assign(array('orders' => $orders, 'displayorders' => $displayorders, 'totalPoints' => (int) $customer_points, 'voucher' => LoyaltyModule::getVoucherValue($customer_points, (int) $this->context->currency->id), 'validation_id' => LoyaltyStateModule::getValidationId(), 'transformation_allowed' => $customer_points > 0, 'page' => (int) Tools::getValue('p') > 0 ? (int) Tools::getValue('p') : 1, 'nbpagination' => (int) Tools::getValue('n') > 0 ? (int) Tools::getValue('n') : 10, 'nArray' => array(10, 20, 50), 'max_page' => floor(count($orders) / ((int) Tools::getValue('n') > 0 ? (int) Tools::getValue('n') : 10)), 'pagination_link' => $this->getSummaryPaginationLink(array(), $this->context->smarty))); /* Discounts */ $nb_discounts = 0; $discounts = array(); if ($ids_discount = LoyaltyModule::getDiscountByIdCustomer((int) $this->context->customer->id)) { $nb_discounts = count($ids_discount); foreach ($ids_discount as $key => $discount) { $discounts[$key] = new CartRule((int) $discount['id_cart_rule'], (int) $this->context->cookie->id_lang); $discounts[$key]->orders = LoyaltyModule::getOrdersByIdDiscount((int) $discount['id_cart_rule']); } } $all_categories = Category::getSimpleCategories((int) $this->context->cookie->id_lang); $voucher_categories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'); if ($voucher_categories != '' && $voucher_categories != 0) { $voucher_categories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY')); } else { die(Tools::displayError()); } if (count($voucher_categories) == count($all_categories)) { $categories_names = null; } else { $categories_names = array(); foreach ($all_categories as $k => $all_category) { if (in_array($all_category['id_category'], $voucher_categories)) { $categories_names[$all_category['id_category']] = trim($all_category['name']); } } if (!empty($categories_names)) { $categories_names = Tools::truncate(implode(', ', $categories_names), 100) . '.'; } else { $categories_names = null; } } $this->context->smarty->assign(array('nbDiscounts' => (int) $nb_discounts, 'discounts' => $discounts, 'minimalLoyalty' => (double) Configuration::get('PS_LOYALTY_MINIMAL'), 'categories' => $categories_names)); $this->setTemplate('loyalty.tpl'); }
public function hookAdminCustomers($params) { $customer = new Customer(intval($params['id_customer'])); if ($customer and !Validate::isLoadedObject($customer)) { die(Tools::displayError('Incorrect object Customer.')); } $fidelities = LoyaltyModule::getAllByIdCustomer(intval($params['id_customer']), intval($params['cookie']->id_lang)); $points = intval(LoyaltyModule::getPointsByCustomer(intval($params['id_customer']))); $html = '<h2>' . $this->l('Loyalty points') . '</h2> <table cellspacing="0" cellpadding="0" class="table"> <tr style="background-color:#F5E9CF; padding: 0.3em 0.1em;"> <th>' . $this->l('Order') . '</th> <th>' . $this->l('Date') . '</th> <th>' . $this->l('Total (without shipping)') . '</th> <th>' . $this->l('Points') . '</th> <th>' . $this->l('Points Status') . '</th> </tr>'; foreach ($fidelities as $key => $loyalty) { $html .= ' <tr style="background-color: ' . ($key % 2 != 0 ? '#FFF6CF' : '#FFFFFF') . ';"> <td>' . (intval($loyalty['id']) > 0 ? '<a style="color: #268CCD; font-weight: bold; text-decoration: underline;" href="index.php?tab=AdminOrders&id_order=' . $loyalty['id'] . '&vieworder&token=' . Tools::getAdminToken('AdminOrders' . intval(Tab::getIdFromClassName('AdminOrders')) . intval($params['cookie']->id_employee)) . '">' . $this->l('#') . sprintf('%06d', $loyalty['id']) . '</a>' : '--') . '</td> <td>' . Tools::displayDate($loyalty['date'], intval($params['cookie']->id_lang)) . '</td> <td>' . (intval($loyalty['id']) > 0 ? $loyalty['total_without_shipping'] : '--') . '</td> <td>' . $loyalty['points'] . '</td> <td>' . $loyalty['state'] . '</td> </tr>'; } $html .= ' <tr> <td> </td> <td colspan="2" class="bold" style="text-align: right;">' . $this->l('Total points available:') . '</td> <td>' . $points . '</td> <td>' . $this->l('Voucher value:') . ' ' . Tools::displayPrice(LoyaltyModule::getVoucherValue($points), new Currency(Configuration::get('PS_CURRENCY_DEFAULT'))) . '</td> </tr> </table><br/>'; return $html; }
* International Registered Trademark & Property of PrestaShop SA */ /* SSL Management */ $useSSL = true; require_once dirname(__FILE__) . '/../../config/config.inc.php'; require_once dirname(__FILE__) . '/../../init.php'; include_once dirname(__FILE__) . '/LoyaltyModule.php'; include_once dirname(__FILE__) . '/LoyaltyStateModule.php'; include_once dirname(__FILE__) . '/loyalty.php'; Tools::displayFileAsDeprecated(); $context = Context::getContext(); if (!$context->customer->isLogged()) { Tools::redirect('index.php?controller=authentication&back=modules/loyalty/loyalty-program.php'); } $context->controller->addJqueryPlugin(array('dimensions', 'cluetip')); $customerPoints = (int) LoyaltyModule::getPointsByCustomer((int) $cookie->id_customer); /* transform point into voucher if needed */ if (Tools::getValue('transform-points') == 'true' and $customerPoints > 0) { /* Generate a voucher code */ $voucherCode = NULL; do { $voucherCode = 'FID' . rand(1000, 100000); } while (CartRule::cartRuleExists($voucherCode)); /* Voucher creation and affectation to the customer */ $cartRule = new CartRule(); $cartRule->code = $voucherCode; $cartRule->id_customer = (int) $context->customer->id; $cartRule->id_currency = (int) $context->currency->id; $cartRule->reduction_amount = LoyaltyModule::getVoucherValue((int) $customerPoints); $cartRule->quantity = 1; $cartRule->quantity_per_user = 1;
public function hookAdminCustomers($params) { include_once dirname(__FILE__) . '/LoyaltyModule.php'; include_once dirname(__FILE__) . '/LoyaltyStateModule.php'; $customer = new Customer((int) $params['id_customer']); if ($customer && !Validate::isLoadedObject($customer)) { die($this->l('Incorrect Customer object.')); } $details = LoyaltyModule::getAllByIdCustomer((int) $params['id_customer'], (int) $params['cookie']->id_lang); $points = (int) LoyaltyModule::getPointsByCustomer((int) $params['id_customer']); $html = ' <br /><h2>' . sprintf($this->l('Loyalty points (%d points)'), $points) . '</h2>'; if (!isset($points) || count($details) == 0) { return $html . ' ' . $this->l('This customer has no points'); } $html .= ' <table cellspacing="0" cellpadding="0" class="table"> <tr style="background-color:#F5E9CF; padding: 0.3em 0.1em;"> <th>' . $this->l('Order') . '</th> <th>' . $this->l('Date') . '</th> <th>' . $this->l('Total (without shipping)') . '</th> <th>' . $this->l('Points') . '</th> <th>' . $this->l('Points Status') . '</th> </tr>'; foreach ($details as $key => $loyalty) { $url = 'index.php?tab=AdminOrders&id_order=' . $loyalty['id'] . '&vieworder&token=' . Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $params['cookie']->id_employee); $html .= ' <tr style="background-color: ' . ($key % 2 != 0 ? '#FFF6CF' : '#FFFFFF') . ';"> <td>' . ((int) $loyalty['id'] > 0 ? '<a style="color: #268CCD; font-weight: bold; text-decoration: underline;" href="' . $url . '">' . sprintf($this->l('#%d'), $loyalty['id']) . '</a>' : '--') . '</td> <td>' . Tools::displayDate($loyalty['date']) . '</td> <td>' . ((int) $loyalty['id'] > 0 ? $loyalty['total_without_shipping'] : '--') . '</td> <td>' . (int) $loyalty['points'] . '</td> <td>' . $loyalty['state'] . '</td> </tr>'; } $html .= ' <tr> <td> </td> <td colspan="2" class="bold" style="text-align: right;">' . $this->l('Total points available:') . '</td> <td>' . $points . '</td> <td>' . $this->l('Voucher value:') . ' ' . Tools::displayPrice(LoyaltyModule::getVoucherValue((int) $points, (int) Configuration::get('PS_CURRENCY_DEFAULT')), new Currency((int) Configuration::get('PS_CURRENCY_DEFAULT'))) . '</td> </tr> </table>'; return $html; }
<?php /* SSL Management */ $useSSL = true; require_once dirname(__FILE__) . '/../../config/config.inc.php'; require_once dirname(__FILE__) . '/../../init.php'; include_once dirname(__FILE__) . '/LoyaltyModule.php'; include_once dirname(__FILE__) . '/LoyaltyStateModule.php'; if (!$cookie->isLogged()) { Tools::redirect('authentication.php?back=modules/loyalty/loyalty-program.php'); } // CSS ans JS file calls $css_files = array(_PS_CSS_DIR_ . 'jquery.cluetip.css' => 'all'); $js_files = array(_PS_JS_DIR_ . 'jquery/jquery.dimensions.js', _PS_JS_DIR_ . 'jquery/jquery.cluetip.js'); $customerPoints = intval(LoyaltyModule::getPointsByCustomer(intval($cookie->id_customer))); /* transform point into voucher if needed */ if (Tools::getValue('transform-points') == 'true' and $customerPoints > 0) { /* generate a voucher code */ $voucherCode = null; do { $voucherCode = 'FID' . rand(1000, 100000); } while (Discount::discountExists($voucherCode)); /* voucher creation and add to customer */ $voucher = new Discount(); $voucher->name = $voucherCode; $voucher->id_discount_type = 2; // Discount on order (amount) $voucher->id_customer = intval($cookie->id_customer); $voucher->id_currency = intval($cookie->id_currency); $voucher->value = LoyaltyModule::getVoucherValue($customerPoints); $voucher->quantity = 1;