Beispiel #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');
 }
Beispiel #2
0
 public function hookCancelProduct($params)
 {
     include_once dirname(__FILE__) . '/LoyaltyStateModule.php';
     include_once dirname(__FILE__) . '/LoyaltyModule.php';
     if (!Validate::isLoadedObject($params['order']) || !Validate::isLoadedObject($order_detail = new OrderDetail((int) $params['id_order_detail'])) || !Validate::isLoadedObject($loyalty = new LoyaltyModule((int) LoyaltyModule::getByOrderId((int) $params['order']->id)))) {
         return false;
     }
     $loyalty_new = new LoyaltyModule();
     $loyalty_new->points = -1 * LoyaltyModule::getNbPointsByPrice(number_format($order_detail->total_price_tax_incl, 2, '.', ''));
     $loyalty_new->id_loyalty_state = (int) LoyaltyStateModule::getCancelId();
     $loyalty_new->id_order = (int) $params['order']->id;
     $loyalty_new->id_customer = (int) $loyalty->id_customer;
     $loyalty_new->add();
     return;
 }
Beispiel #3
0
 public function hookCancelProduct($params)
 {
     if (!Validate::isLoadedObject($params['order']) or !Validate::isLoadedObject($orderDetail = new OrderDetail(intval($params['id_order_detail'])))) {
         return false;
     }
     if (!Validate::isLoadedObject($loyalty = new LoyaltyModule(intval(LoyaltyModule::getByOrderId(intval($params['order']->id)))))) {
         return false;
     }
     $loyalty->points = $loyalty->points - LoyaltyModule::getNbPointsByPrice($orderDetail->product_price * (1 + $orderDetail->tax_rate / 100) * $orderDetail->product_quantity);
     $loyalty->id_loyalty_state = LoyaltyStateModule::getCancelId();
     return $loyalty->save();
     // Automatically "historize" the modification
 }
        $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 {
    die(Tools::displayError());
}
if (sizeof($voucherCategories) == sizeof($allCategories)) {
    $categoriesNames = null;
} else {
    $categoriesNames = array();
    foreach ($allCategories as $k => $allCategory) {
        if (in_array($allCategory['id_category'], $voucherCategories)) {
 public static function registerDiscount($cartRule)
 {
     if (!Validate::isLoadedObject($cartRule)) {
         die(Tools::displayError('Incorrect object CartRule.'));
     }
     $items = self::getAllByIdCustomer((int) $cartRule->id_customer, NULL, true);
     $associated = false;
     foreach ($items as $item) {
         $lm = new LoyaltyModule((int) $item['id_loyalty']);
         /* Check for negative points for this order */
         $negativePoints = (int) Db::getInstance()->getValue('SELECT SUM(points) points FROM ' . _DB_PREFIX_ . 'loyalty WHERE id_order = ' . (int) $f->id_order . ' AND id_loyalty_state = ' . (int) LoyaltyStateModule::getCancelId() . ' AND points < 0');
         if ($lm->points + $negativePoints <= 0) {
             continue;
         }
         $lm->id_cart_rule = (int) $cartRule->id;
         $lm->id_loyalty_state = (int) LoyaltyStateModule::getConvertId();
         $lm->save();
         $associated = true;
     }
     return $associated;
 }
Beispiel #6
0
 public static function registerDiscount($discount)
 {
     if (!Validate::isLoadedObject($discount)) {
         die(Tools::displayError('Incorrect object Discount.'));
     }
     $items = self::getAllByIdCustomer($discount->id_customer, NULL, true);
     foreach ($items as $item) {
         $f = new LoyaltyModule($item['id_loyalty']);
         $f->id_discount = $discount->id;
         $f->id_loyalty_state = LoyaltyStateModule::getConvertId();
         $f->save();
     }
 }
    // + 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';
Beispiel #8
0
 public function hookCancelProduct($params)
 {
     global $cookie;
     include_once dirname(__FILE__) . '/LoyaltyStateModule.php';
     include_once dirname(__FILE__) . '/LoyaltyModule.php';
     $orderDetail = '';
     if (!isset($params['order_detail']) || !Validate::isLoadedObject($params['order_detail'])) {
         if (Validate::isLoadedObject($orderDetail = new OrderDetail((int) $params['id_order_detail']))) {
             $orderDetail = get_object_vars($orderDetail);
         }
     } else {
         $orderDetail = get_object_vars($params['order_detail']);
     }
     if (!Validate::isLoadedObject($order = $params['order']) || !Validate::isLoadedObject($loyalty = new LoyaltyModule((int) LoyaltyModule::getByOrderId((int) $params['order']->id)))) {
         return false;
     }
     if (is_array($orderDetail) && count($orderDetail)) {
         $order->setProductPrices($orderDetail);
     } else {
         return false;
     }
     $qtyList = Tools::getValue('cancelQuantity');
     if (isset($qtyList[$orderDetail['id_order_detail']])) {
         $qtyList = abs((int) $qtyList[$orderDetail['id_order_detail']]);
     } else {
         $qtyList = (int) $orderDetail['product_quantity'];
     }
     $product_price = $order->getTaxCalculationMethod() == PS_TAX_EXC ? $orderDetail['product_price'] + $orderDetail['ecotax'] : $orderDetail['product_price_wt'];
     $points = (int) LoyaltyModule::getNbPointsByPrice(number_format($product_price, 2, '.', ''), (int) $params['order']->id_currency) * $qtyList;
     if (!$order->hasBeenDelivered()) {
         if ($points > $loyalty->points) {
             $points = (int) $loyalty->points;
         }
         $loyalty->points = $loyalty->points - $points;
         return $loyalty->save();
     } else {
         $loyaltyNew = new LoyaltyModule();
         $loyaltyNew->points = -1 * $points;
         $loyaltyNew->id_loyalty_state = (int) LoyaltyStateModule::getCancelId();
         $loyaltyNew->id_order = (int) $params['order']->id;
         $loyaltyNew->id_customer = (int) $loyalty->id_customer;
         return $loyaltyNew->add();
     }
     return false;
 }