public static function insertDefaultData() { $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT')); $default = new LoyaltyStateModule(LoyaltyStateModule::getDefaultId()); $default->name[$defaultLanguage] = 'Validation'; $default->save(); $validation = new LoyaltyStateModule(LoyaltyStateModule::getValidationId()); $validation->id_order_state = _PS_OS_DELIVERED_; $validation->name[$defaultLanguage] = 'Available'; $validation->save(); $cancel = new LoyaltyStateModule(LoyaltyStateModule::getCancelId()); $cancel->id_order_state = _PS_OS_CANCELED_; $cancel->name[$defaultLanguage] = 'Canceled'; $cancel->save(); $convert = new LoyaltyStateModule(LoyaltyStateModule::getConvertId()); $convert->name[$defaultLanguage] = 'Converted'; $convert->save(); $noneAward = new LoyaltyStateModule(LoyaltyStateModule::getNoneAwardId()); $noneAward->name[$defaultLanguage] = 'Unavailable on discounts'; $noneAward->save(); return true; }
public static function insertDefaultData() { $loyaltyModule = new Loyalty(); $languages = Language::getLanguages(); $defaultTranslations = array('default' => array('id_loyalty_state' => (int) LoyaltyStateModule::getDefaultId(), 'default' => $loyaltyModule->getL('Awaiting validation'), 'en' => 'Awaiting validation', 'fr' => 'En attente de validation')); $defaultTranslations['validated'] = array('id_loyalty_state' => (int) LoyaltyStateModule::getValidationId(), 'id_order_state' => Configuration::get('PS_OS_DELIVERED'), 'default' => $loyaltyModule->getL('Available'), 'en' => 'Available', 'fr' => 'Disponible'); $defaultTranslations['cancelled'] = array('id_loyalty_state' => (int) LoyaltyStateModule::getCancelId(), 'id_order_state' => Configuration::get('PS_OS_CANCELED'), 'default' => $loyaltyModule->getL('Cancelled'), 'en' => 'Cancelled', 'fr' => 'Annulés'); $defaultTranslations['converted'] = array('id_loyalty_state' => (int) LoyaltyStateModule::getConvertId(), 'default' => $loyaltyModule->getL('Already converted'), 'en' => 'Already converted', 'fr' => 'Déjà convertis'); $defaultTranslations['none_award'] = array('id_loyalty_state' => (int) LoyaltyStateModule::getNoneAwardId(), 'default' => $loyaltyModule->getL('Unavailable on discounts'), 'en' => 'Unavailable on discounts', 'fr' => 'Non disponbile sur produits remisés'); foreach ($defaultTranslations as $loyaltyState) { $state = new LoyaltyStateModule((int) $loyaltyState['id_loyalty_state']); if (isset($loyaltyState['id_order_state'])) { $state->id_order_state = (int) $loyaltyState['id_order_state']; } $state->name[(int) Configuration::get('PS_LANG_DEFAULT')] = $loyaltyState['default']; foreach ($languages as $language) { if (isset($loyaltyState[$language['iso_code']])) { $state->name[(int) $language['id_lang']] = $loyaltyState[$language['iso_code']]; } } $state->save(); } return true; }
public function hookUpdateOrderStatus($params) { if (!Validate::isLoadedObject($params['newOrderStatus'])) { die(Tools::displayError('Some parameters are missing.')); } $newOrder = $params['newOrderStatus']; $order = new Order(intval($params['id_order'])); if ($order and !Validate::isLoadedObject($order)) { die(Tools::displayError('Incorrect object Order.')); } $this->instanceDefaultStates(); if ($newOrder->id == $this->loyaltyStateValidation->id_order_state or $newOrder->id == $this->loyaltyStateCancel->id_order_state) { if (!Validate::isLoadedObject($loyalty = new LoyaltyModule(LoyaltyModule::getByOrderId($order->id)))) { return false; } if (intval(Configuration::get('PS_LOYALTY_NONE_AWARD')) and $loyalty->id_loyalty_state == LoyaltyStateModule::getNoneAwardId()) { return true; } if ($newOrder->id == $this->loyaltyStateValidation->id_order_state) { $loyalty->id_loyalty_state = LoyaltyStateModule::getValidationId(); if (intval($loyalty->points) < 0) { $loyalty->points = abs(intval($loyalty->points)); } } else { if ($newOrder->id == $this->loyaltyStateCancel->id_order_state) { $loyalty->id_loyalty_state = LoyaltyStateModule::getCancelId(); $loyalty->points = 0; //-abs(intval($loyalty->points)); } } return $loyalty->save(); } return true; }
public function hookUpdateOrderStatus($params) { include_once dirname(__FILE__) . '/LoyaltyStateModule.php'; include_once dirname(__FILE__) . '/LoyaltyModule.php'; if (!Validate::isLoadedObject($params['newOrderStatus'])) { die($this->l('Missing parameters')); } $new_order = $params['newOrderStatus']; $order = new Order((int) $params['id_order']); if ($order && !Validate::isLoadedObject($order)) { die($this->l('Incorrect Order object.')); } $this->instanceDefaultStates(); if ($new_order->id == $this->loyaltyStateValidation->id_order_state || $new_order->id == $this->loyaltyStateCancel->id_order_state) { if (!Validate::isLoadedObject($loyalty = new LoyaltyModule(LoyaltyModule::getByOrderId($order->id)))) { return false; } if ((int) Configuration::get('PS_LOYALTY_NONE_AWARD') && $loyalty->id_loyalty_state == LoyaltyStateModule::getNoneAwardId()) { return true; } if ($new_order->id == $this->loyaltyStateValidation->id_order_state) { $loyalty->id_loyalty_state = LoyaltyStateModule::getValidationId(); if ((int) $loyalty->points < 0) { $loyalty->points = abs((int) $loyalty->points); } } elseif ($new_order->id == $this->loyaltyStateCancel->id_order_state) { $loyalty->id_loyalty_state = LoyaltyStateModule::getCancelId(); $loyalty->points = 0; } return $loyalty->save(); } return true; }
public static function getPointsByCustomer($id_customer) { return Db::getInstance()->getValue(' SELECT SUM(f.points) points FROM `' . _DB_PREFIX_ . 'loyalty` f WHERE f.id_customer = ' . (int) $id_customer . ' AND f.id_loyalty_state IN (' . (int) LoyaltyStateModule::getValidationId() . ', ' . (int) LoyaltyStateModule::getNoneAwardId() . ')') + Db::getInstance()->getValue(' SELECT SUM(f.points) points FROM `' . _DB_PREFIX_ . 'loyalty` f WHERE f.id_customer = ' . (int) $id_customer . ' AND f.id_loyalty_state = ' . (int) LoyaltyStateModule::getCancelId() . ' AND points < 0'); }
public static function getPointsByCustomer($id_customer) { $validity_period = Configuration::get('PS_LOYALTY_VALIDITY_PERIOD'); $sql_period = ''; if ((int) $validity_period > 0) { $sql_period = ' AND datediff(NOW(),f.date_add) <= ' . $validity_period; } return Db::getInstance()->getValue(' SELECT SUM(f.points) points FROM `' . _DB_PREFIX_ . 'loyalty` f WHERE f.id_customer = ' . (int) $id_customer . ' AND f.id_loyalty_state IN (' . (int) LoyaltyStateModule::getValidationId() . ', ' . (int) LoyaltyStateModule::getNoneAwardId() . ') ' . $sql_period) + Db::getInstance()->getValue(' SELECT SUM(f.points) points FROM `' . _DB_PREFIX_ . 'loyalty` f WHERE f.id_customer = ' . (int) $id_customer . ' AND f.id_loyalty_state = ' . (int) LoyaltyStateModule::getCancelId() . ' AND points < 0 ' . $sql_period); }
public static function getPointsByCustomer($id_customer) { $return = Db::getInstance()->getRow(' SELECT sum(f.points) AS points FROM `' . _DB_PREFIX_ . 'loyalty` f WHERE f.id_customer = ' . intval($id_customer) . ' AND f.id_loyalty_state IN (' . intval(LoyaltyStateModule::getValidationId()) . ', ' . intval(LoyaltyStateModule::getCancelId()) . ', ' . intval(LoyaltyStateModule::getNoneAwardId()) . ')'); return $return['points']; }
public function hookUpdateOrderStatus($params) { include_once dirname(__FILE__) . '/LoyaltyStateModule.php'; include_once dirname(__FILE__) . '/LoyaltyModule.php'; if (!Validate::isLoadedObject($params['newOrderStatus'])) { die(Tools::displayError('Missing parameters')); } $newOrder = $params['newOrderStatus']; $order = new Order((int) $params['id_order']); if ($order and !Validate::isLoadedObject($order)) { die(Tools::displayError('Incorrect object Order.')); } $this->instanceDefaultStates(); $return = false; if ($newOrder->id == $this->loyaltyStateValidation->id_order_state or $newOrder->id == $this->loyaltyStateCancel->id_order_state) { if (!Validate::isLoadedObject($loyalty = new LoyaltyModule(LoyaltyModule::getByOrderId($order->id)))) { return false; } if ((int) Configuration::get('PS_LOYALTY_NONE_AWARD') and $loyalty->id_loyalty_state == LoyaltyStateModule::getNoneAwardId()) { return true; } if ($newOrder->id == $this->loyaltyStateValidation->id_order_state) { $loyalty->id_loyalty_state = LoyaltyStateModule::getValidationId(); if ((int) $loyalty->points < 0) { $loyalty->points = abs((int) $loyalty->points); } $return &= $loyalty->save(); } elseif ($newOrder->id == $this->loyaltyStateCancel->id_order_state) { $loyalties = LoyaltyModule::getAllByOrderId($order->id); if (is_array($loyalties)) { foreach ($loyalties as $entity) { $loyalty = new LoyaltyModule($entity['id_loyalty']); $loyalty->id_loyalty_state = LoyaltyStateModule::getCancelId(); $loyalty->points = 0; $return &= $loyalty->save(); } } } return $loyalty->save(); } return $return; }