/** * Hook called when order status changed * register a discount for sponsor and send him an e-mail */ public function hookUpdateOrderStatus($params) { if (!Validate::isLoadedObject($params['newOrderStatus'])) { die($this->l('Missing parameters')); } $orderState = $params['newOrderStatus']; $order = new Order((int) $params['id_order']); if ($order and !Validate::isLoadedObject($order)) { die($this->l('Incorrect Order object.')); } include_once dirname(__FILE__) . '/ReferralProgramModule.php'; $customer = new Customer((int) $order->id_customer); $stats = $customer->getStats(); $nbOrdersCustomer = (int) $stats['nb_orders'] + 1; // hack to count current order $referralprogram = new ReferralProgramModule(ReferralProgramModule::isSponsorised((int) $customer->id, true)); if (!Validate::isLoadedObject($referralprogram)) { return false; } $sponsor = new Customer((int) $referralprogram->id_sponsor); if ((int) $orderState->logable and $nbOrdersCustomer >= (int) $this->_configuration['REFERRAL_ORDER_QUANTITY'] and $referralprogram->registerDiscountForSponsor((int) $order->id_currency)) { $cartRule = new CartRule((int) $referralprogram->id_cart_rule_sponsor); $currency = new Currency((int) $order->id_currency); $discount_display = ReferralProgram::displayDiscount($cartRule->reduction_percent ? $cartRule->reduction_percent : $cartRule->reduction_amount, $cartRule->reduction_percent ? 1 : 2, $currency); $data = array('{sponsored_firstname}' => $customer->firstname, '{sponsored_lastname}' => $customer->lastname, '{discount_display}' => $discount_display, '{discount_name}' => $cartRule->code); Mail::Send((int) $order->id_lang, 'referralprogram-congratulations', Mail::l('Congratulations!', (int) $order->id_lang), $data, $sponsor->email, $sponsor->firstname . ' ' . $sponsor->lastname, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__) . '/mails/'); return true; } return false; }
/** * Hook called when order status changed * register a discount for sponsor and send him an e-mail */ public function hookUpdateOrderStatus($params) { if (!Validate::isLoadedObject($params['newOrderStatus'])) { die(Tools::displayError('Some parameters are missing.')); } $orderState = $params['newOrderStatus']; $order = new Order(intval($params['id_order'])); if ($order and !Validate::isLoadedObject($order)) { die(Tools::displayError('Incorrect object Order.')); } $customer = new Customer($order->id_customer); $stats = $customer->getStats(); $nbOrdersCustomer = intval($stats['nb_orders']) + 1; // hack to count current order $referralprogram = new ReferralProgramModule(ReferralProgramModule::isSponsorised(intval($customer->id), true)); if (!Validate::isLoadedObject($referralprogram)) { return false; } $sponsor = new Customer($referralprogram->id_sponsor); if (intval($orderState->logable) and $nbOrdersCustomer >= intval($this->_configuration['REFERRAL_ORDER_QUANTITY'])) { if ($referralprogram->registerDiscountForSponsor()) { $discount = new Discount($referralprogram->id_discount_sponsor); $currency = new Currency($order->id_currency); $discount_display = $discount->display($discount->value, $discount->id_discount_type, $currency); $data = array('{sponsored_firstname}' => $customer->firstname, '{sponsored_lastname}' => $customer->lastname, '{discount_display}' => $discount_display, '{discount_name}' => $discount->name); Mail::Send(intval($order->id_lang), 'referralprogram-congratulations', $this->l('Congratulations!'), $data, $sponsor->email, $sponsor->firstname . ' ' . $sponsor->lastname, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__) . '/mails/'); return true; } } return false; }