Пример #1
0
 /**
  * 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');
 }
Пример #2
0
    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>&nbsp;</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;
    }
    }
    if (is_array($categories) and sizeof($categories)) {
        $cartRule->add(true, false, $categories);
    } else {
        $cartRule->add();
    }
    /* Register order(s) which contributed to create this voucher */
    if (!LoyaltyModule::registerDiscount($cartRule)) {
        $cartRule->delete();
    }
    Tools::redirect('modules/loyalty/loyalty-program.php');
}
include dirname(__FILE__) . '/../../header.php';
$orders = LoyaltyModule::getAllByIdCustomer((int) $cookie->id_customer, (int) $cookie->id_lang);
$displayorders = LoyaltyModule::getAllByIdCustomer((int) $cookie->id_customer, (int) $cookie->id_lang, false, true, (int) Tools::getValue('n') > 0 ? (int) Tools::getValue('n') : 10, (int) Tools::getValue('p') > 0 ? (int) Tools::getValue('p') : 1);
$smarty->assign(array('orders' => $orders, 'displayorders' => $displayorders, 'pagination_link' => __PS_BASE_URI__ . 'modules/loyalty/loyalty-program.php', 'totalPoints' => (int) $customerPoints, 'voucher' => LoyaltyModule::getVoucherValue($customerPoints, (int) $context->currency->id), 'validation_id' => LoyaltyStateModule::getValidationId(), 'transformation_allowed' => $customerPoints > 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(sizeof($orders) / ((int) (Tools::getValue('n') > 0) ? (int) Tools::getValue('n') : 10))));
/* Discounts */
$nbDiscounts = 0;
$discounts = array();
if ($ids_discount = LoyaltyModule::getDiscountByIdCustomer((int) $cookie->id_customer)) {
    $nbDiscounts = count($ids_discount);
    foreach ($ids_discount as $key => $discount) {
        $discounts[$key] = new Discount((int) $discount['id_cart_rule'], (int) $cookie->id_lang);
        $discounts[$key]->orders = LoyaltyModule::getOrdersByIdDiscount((int) $discount['id_cart_rule']);
    }
}
$allCategories = Category::getSimpleCategories((int) $cookie->id_lang);
$voucherCategories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY');
if ($voucherCategories != '' and $voucherCategories != 0) {
    $voucherCategories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'));
} else {
Пример #4
0
    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>&nbsp;</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;
    }
Пример #5
0
    // + 1 year
    $voucher->minimal = 0;
    $voucher->active = 1;
    $languages = Language::getLanguages(true);
    $default_text = Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', intval(Configuration::get('PS_LANG_DEFAULT')));
    foreach ($languages as $language) {
        $text = Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', intval($language['id_lang']));
        $voucher->description[intval($language['id_lang'])] = $text ? strval($text) : strval($default_text);
    }
    $voucher->save();
    /* register order(s) which contribute to create this voucher */
    LoyaltyModule::registerDiscount($voucher);
    Tools::redirect('modules/loyalty/loyalty-program.php');
}
include dirname(__FILE__) . '/../../header.php';
$orders = LoyaltyModule::getAllByIdCustomer(intval($cookie->id_customer), intval($cookie->id_lang));
$smarty->assign(array('orders' => $orders, 'totalPoints' => $customerPoints, 'voucher' => LoyaltyModule::getVoucherValue($customerPoints, intval($cookie->id_currency)), 'validation_id' => LoyaltyStateModule::getValidationId(), 'transformation_allowed' => $customerPoints > 0));
/* Discounts */
$nbDiscounts = 0;
$discounts = array();
if ($ids_discount = LoyaltyModule::getDiscountByIdCustomer(intval($cookie->id_customer))) {
    $nbDiscounts = count($ids_discount);
    foreach ($ids_discount as $key => $discount) {
        $discounts[$key] = new Discount($discount['id_discount'], intval($cookie->id_lang));
        $discounts[$key]->date_add = $discount['date_add'];
        $discounts[$key]->orders = LoyaltyModule::getOrdersByIdDiscount($discount['id_discount']);
    }
}
$smarty->assign(array('nbDiscounts' => $nbDiscounts, 'discounts' => $discounts));
echo Module::display(dirname(__FILE__) . '/loyalty.php', 'loyalty.tpl');
include dirname(__FILE__) . '/../../footer.php';