public function run() { DB::table('discounts')->truncate(); $discount = new Discount(); $discount->role_id = 5; //Đại lý chính thức $discount->branch_id = 1; //Giày dép $discount->from_rate = 0; $discount->to_rate = 3000000; $discount->percentage = 5; $discount->save(); $discount = new Discount(); $discount->role_id = 5; //Đại lý chính thức $discount->branch_id = 1; //Giày dép $discount->from_rate = 3000001; $discount->to_rate = 6000000; $discount->percentage = 15; $discount->save(); $discount = new Discount(); $discount->role_id = 5; //Đại lý chính thức $discount->branch_id = 1; //Giày dép $discount->from_rate = 6000001; $discount->to_rate = 300000000; $discount->percentage = 25; $discount->save(); }
public function createDefaultBcashDiscounts() { foreach ($this->names as $name) { $coupon = new Discount(); $coupon->name = $this->getLangsForName($name); $coupon->quantity = self::billion; $coupon->quantity_per_user = self::billion; $coupon->date_from = date('Y-m-d H:i:s'); $coupon->date_to = date('Y-m-d', strtotime('+30 year')); $coupon->partial_use = 0; $coupon->code = 'gerenciado_pelo_modulo_' . Tools::passwdGen(8); $coupon->active = 0; //Invisivel $coupon->highlight = 0; //Envio excluido $coupon->minimum_amount_shipping = 0; //Acoes $coupon->free_shipping = 0; $coupon->reduction_percent = 0; if ($coupon->add()) { Configuration::updateValue(self::prefix . self::bcash . $name, (int) $coupon->id); } } return true; }
public function registerDiscount($id_customer, $register = false) { $configurations = Configuration::getMultiple(array('REFERRAL_DISCOUNT_TYPE', 'REFERRAL_DISCOUNT_VALUE')); $discount = new Discount(); $discount->id_discount_type = intval($configurations['REFERRAL_DISCOUNT_TYPE']); $discount->value = floatval($configurations['REFERRAL_DISCOUNT_VALUE']); $discount->quantity = 1; $discount->quantity_per_user = 1; $discount->date_from = date('Y-m-d H:i:s', time()); $discount->date_to = date('Y-m-d H:i:s', time() + 31536000); // + 1 year $discount->name = $this->getDiscountPrefix() . Tools::passwdGen(6); $discount->description = Configuration::getInt('REFERRAL_DISCOUNT_DESCRIPTION'); $discount->id_customer = intval($id_customer); if ($discount->add()) { if ($register != false) { if ($register == 'sponsor') { $this->id_discount_sponsor = $discount->id; } elseif ($register == 'sponsored') { $this->id_discount = $discount->id; } return $this->save(); } return true; } return false; }
/** * Create Discount, with applicable DiscountConditions */ static function createDiscountFromEntity($entity) { $discount = new Discount(); $discount->setId($entity->getId())->setName($entity->getName())->setAs($entity->getAppliedAs())->setTo($entity->getAppliedTo())->setValue($entity->getValue())->setIsPreTax($entity->getIsPreTax())->setIsAuto($entity->getIsAuto())->setCouponCode($entity->getCouponCode()); //TODO: build discount conditions return $discount; }
public function check(Discount $discount) { $zones = $discount->Zones(); if (!$zones->exists()) { return true; } $address = $this->order->getShippingAddress(); if (!$address) { $this->error(_t("OrderCouponModifier.NOTINZONE", "This coupon can only be used for a specific shipping location.")); return false; } $currentzones = Zone::get_zones_for_address($address); if (!$currentzones || !$currentzones->exists()) { $this->error(_t("OrderCouponModifier.NOTINZONE", "This discount can only be used for a specific shipping location.")); return false; } //check if any of currentzones is in zones $inzone = false; foreach ($currentzones as $zone) { if ($zones->find('ID', $zone->ID)) { $inzone = true; break; } } if (!$inzone) { $this->error(_t("OrderCouponModifier.NOTINZONE", "This discount can only be used for a specific shipping location.")); return false; } return true; }
public function check(Discount $discount) { if ($discount->MinOrderValue > 0 && $this->order->SubTotal() < $discount->MinOrderValue) { $this->error(sprintf(_t("Discount.MINORDERVALUE", "Your cart subtotal must be at least %s to use this discount"), $discount->dbObject("MinOrderValue")->Nice())); return false; } return true; }
public function check(Discount $discount) { if ($discount->UseLimit) { if ($discount->getUseCount($this->order->ID) >= $discount->UseLimit) { $this->error("This discount has reached it's maximum number of uses."); return false; } } return true; }
public function showDetailData() { if (isset($_GET['id'])) { $discount = new Discount(); return $discount->getOneDiscountById($_GET['id']); } else { header("location:" . HOME_LINK); return false; } }
public function check(Discount $discount) { $group = $discount->Group(); $member = $this->getMember(); if ($group->exists() && (!$member || !$member->inGroup($group))) { $this->error(_t("Discount.GROUPED", "Only specific members can use this discount.")); return false; } return true; }
public function itemMatchesCriteria(OrderItem $item, Discount $discount) { $products = $discount->Products(); $itemproduct = $item->Product(true); //true forces the current version of product to be retrieved. if ($products->exists() && !$products->find('ID', $item->ProductID)) { return false; } return true; }
public function check(Discount $discount) { $members = $discount->Members(); $member = $this->getMember(); if ($members->exists() && (!$member || !$members->byID($member->ID))) { $this->error(_t("Discount.MEMBERSHIP", "Only specific members can use this discount.")); return false; } return true; }
public function titleMaker() { //check if id is set if (isset($_GET['id'])) { //if id is set, set the title to the discount title $id = $_GET['id']; $discount = new Discount(); $title = $discount->getTitle($id); return $title['title']; } return isset($_GET['page']) ? ucfirst($_GET['page']) : "Homepage"; }
public function itemMatchesCriteria(OrderItem $item, Discount $discount) { $discountcategoryids = $discount->Categories()->getIDList(); if (empty($discountcategoryids)) { return true; } //get category ids from buyable $buyable = $item->Buyable(); if (!method_exists($buyable, "getCategoryIDs")) { return false; } $ids = array_intersect($buyable->getCategoryIDs(), $discountcategoryids); return !empty($ids); }
public static function fromArray($data) { $item = new InvoiceItem(); if (isset($data['quantity'])) { $item->setQuantity($data['quantity']); } if (isset($data['vat'])) { $item->setVat($data['vat']); } if (isset($data['price_item'])) { $item->setPriceItem($data['price_item']); } if (isset($data['price'])) { $item->setPrice($data['price']); } if (isset($data['price_total'])) { $item->setPriceTotal($data['price_total']); } if (isset($data['description'])) { $item->setPriceTotal($data['description']); } if (isset($data['discount']) && is_array($data['discount'])) { $item->setDiscount(Discount::fromArray($data['discount'])); } return $item; }
public function registerDiscount($id_customer, $register = false, $id_currency = 0) { $configurations = Configuration::getMultiple(array('REFERRAL_DISCOUNT_TYPE', 'REFERRAL_PERCENTAGE', 'REFERRAL_DISCOUNT_VALUE_' . (int) $id_currency)); $discount = new Discount(); $discount->id_discount_type = (int) $configurations['REFERRAL_DISCOUNT_TYPE']; /* % */ if ($configurations['REFERRAL_DISCOUNT_TYPE'] == 1) { $discount->value = (double) $configurations['REFERRAL_PERCENTAGE']; } elseif ($configurations['REFERRAL_DISCOUNT_TYPE'] == 2 and isset($configurations['REFERRAL_DISCOUNT_VALUE_' . (int) $id_currency])) { $discount->value = (double) $configurations['REFERRAL_DISCOUNT_VALUE_' . (int) $id_currency]; } else { $discount->value = 0; } $discount->quantity = 1; $discount->quantity_per_user = 1; $discount->date_from = date('Y-m-d H:i:s', time()); $discount->date_to = date('Y-m-d H:i:s', time() + 31536000); // + 1 year $discount->name = $this->getDiscountPrefix() . Tools::passwdGen(6); $discount->description = Configuration::getInt('REFERRAL_DISCOUNT_DESCRIPTION'); $discount->id_customer = (int) $id_customer; $discount->id_currency = (int) $id_currency; if ($discount->add()) { if ($register != false) { if ($register == 'sponsor') { $this->id_discount_sponsor = (int) $discount->id; } elseif ($register == 'sponsored') { $this->id_discount = (int) $discount->id; } return $this->save(); } return true; } return false; }
public function show($id) { $student = Issue::with('placements', 'placement', 'receivable.installments', 'educations', 'education', 'earnings', 'punishments', 'returnments', 'presences', 'points', 'retrievals', 'timelines', 'masteries')->find($id); $periods = Teach::with(array('presences' => function ($q) use($id) { $q->where('issue_id', '=', $id); }))->select(DB::raw('month(course_date) as months'), DB::raw('year(course_date) as years'))->groupBy(DB::raw('month(course_date)'))->get(); $presences = array(); foreach ($periods as $period) { $presences[] = array('month' => $period->months, 'year' => $period->years, 'presences' => $this->countPresences($id, $period->months, $period->years), 'presents' => $this->countPresents($id, $period->months, $period->years), 'absents' => $this->countAbsents($id, $period->months, $period->years), 'sicks' => $this->countSicks($id, $period->months, $period->years), 'permits' => $this->countPermits($id, $period->months, $period->years)); } $points = array(); foreach ($student->points as $point) { if ($point->pointable_type == 'Activity') { $points[] = array('date' => $point->pointable->agenda, 'event' => $point->pointable->name, 'point' => $point->point, 'lowest' => $this->getLowest($point->pointable_id), 'highest' => $this->getHighest($point->pointable_id)); } } $handbooks = Handbook::where('project_id', '=', Auth::user()->curr_project_id)->where('generation_id', '=', $student->generation_id)->get(); $courses = Course::where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->get(); $discounts = Discount::all(); $promotions = Promotion::where('project_id', '=', Auth::user()->curr_project_id)->get(); $vouchers = Voucher::where('project_id', '=', Auth::user()->curr_project_id)->get(); $charges = Charge::where('project_id', '=', Auth::user()->curr_project_id)->get(); $menu = 'student'; return View::make('students.show', compact('student', 'handbooks', 'courses', 'discounts', 'promotions', 'vouchers', 'charges', 'presences', 'points', 'menu')); }
public function __construct(\Order $order, $context = array()) { $this->order = $order; // get qualifying discounts for this order $this->discounts = \Discount::get_matching($this->order, $context); $this->modifier = $this->order->getModifier("OrderDiscountModifier", true); }
protected function _initialize($attributes) { $this->_attributes = $attributes; $addOnArray = []; if (isset($attributes['addOns'])) { foreach ($attributes['addOns'] as $addOn) { $addOnArray[] = AddOn::factory($addOn); } } $this->_attributes['addOns'] = $addOnArray; $discountArray = []; if (isset($attributes['discounts'])) { foreach ($attributes['discounts'] as $discount) { $discountArray[] = Discount::factory($discount); } } $this->_attributes['discounts'] = $discountArray; $planArray = []; if (isset($attributes['plans'])) { foreach ($attributes['plans'] as $plan) { $planArray[] = self::factory($plan); } } $this->_attributes['plans'] = $planArray; }
/** * later index/overview? */ public function admin_test() { if (!empty($this->request->data['DiscountCode'])) { # redeem if ($res = $this->Discount->redeem($this->request->data['DiscountCode']['code'])) { $this->Common->flashMessage(__('Done'), 'success'); } elseif ($res === null) { $this->Common->flashMessage(__('Already redeemed'), 'warning'); } else { $this->Common->flashMessage(__('Error'), 'error'); } $this->redirect(array('action' => 'test')); } elseif (!empty($this->request->data['Discount'])) { $value = $this->request->data['Discount']['amount']; # check if ($check = $this->Discount->check($this->request->data['Discount']['code'], $value)) { $new = Discount::calculate($value, $check['Discount']); $this->Common->flashMessage(__('Wert von ' . $value . ' auf ' . $new . ' gesenkt'), 'success'); } else { $this->Common->flashMessage(__('Error'), 'error'); } } if (empty($this->request->data)) { $this->request->data['Discount']['amount'] = 10; } }
/** * @see FrontController::initContent() */ public function initContent() { parent::initContent(); $shop_name = htmlentities(Configuration::get('PS_SHOP_NAME'), NULL, 'utf-8'); $shop_url = Tools::getHttpHost(true, true); $customer = Context::getContext()->customer; if (!preg_match("#.*\\.html\$#Ui", Tools::getValue('mail')) or !preg_match("#.*\\.html\$#Ui", Tools::getValue('mail'))) { die(Tools::redirect()); } $file = file_get_contents(dirname(__FILE__) . '/../../mails/' . strval(preg_replace('#\\.{2,}#', '.', Tools::getValue('mail')))); $file = str_replace('{shop_name}', $shop_name, $file); $file = str_replace('{shop_url}', $shop_url . __PS_BASE_URI__, $file); $file = str_replace('{shop_logo}', $shop_url . _PS_IMG_ . 'logo.jpg', $file); $file = str_replace('{firstname}', $customer->firstname, $file); $file = str_replace('{lastname}', $customer->lastname, $file); $file = str_replace('{email}', $customer->email, $file); $file = str_replace('{firstname_friend}', 'XXXXX', $file); $file = str_replace('{lastname_friend}', 'xxxxxx', $file); $file = str_replace('{link}', 'authentication.php?create_account=1', $file); $discount_type = (int) Configuration::get('REFERRAL_DISCOUNT_TYPE'); if ($discount_type == 1) { $file = str_replace('{discount}', Discount::display((double) Configuration::get('REFERRAL_PERCENTAGE'), $discount_type, new Currency($this->context->currency->id)), $file); } else { $file = str_replace('{discount}', Discount::display((double) Configuration::get('REFERRAL_DISCOUNT_VALUE_' . $this->context->currency->id), $discount_type, new Currency($this->context->currency->id)), $file); } $this->context->smarty->assign(array('content' => $file)); $this->setTemplate('email.tpl'); }
/** * @ignore */ protected function _initialize($attributes) { $this->_attributes = $attributes; $addOnArray = []; if (isset($attributes['addOns'])) { foreach ($attributes['addOns'] as $addOn) { $addOnArray[] = AddOn::factory($addOn); } } $this->_attributes['addOns'] = $addOnArray; $discountArray = []; if (isset($attributes['discounts'])) { foreach ($attributes['discounts'] as $discount) { $discountArray[] = Discount::factory($discount); } } $this->_attributes['discounts'] = $discountArray; if (isset($attributes['descriptor'])) { $this->_set('descriptor', new Descriptor($attributes['descriptor'])); } $statusHistory = []; if (isset($attributes['statusHistory'])) { foreach ($attributes['statusHistory'] as $history) { $statusHistory[] = new Subscription\StatusDetails($history); } } $this->_attributes['statusHistory'] = $statusHistory; $transactionArray = []; if (isset($attributes['transactions'])) { foreach ($attributes['transactions'] as $transaction) { $transactionArray[] = Transaction::factory($transaction); } } $this->_attributes['transactions'] = $transactionArray; }
public function run($request) { //check if OrderCouponModifier exists if (DB::getConn()->hasTable("OrderCouponModifier")) { $this->log("OrderCouponModifier table exists"); $query = DB::query("SELECT *\n\t\t\t\tFROM OrderModifier\n\t\t\t\tINNER JOIN `OrderAttribute` ON `OrderModifier`.`ID` = `OrderAttribute`.`ID`\n\t\t\t\tINNER JOIN `OrderCouponModifier` ON `OrderModifier`.`ID` = `OrderCouponModifier`.`ID`\n\t\t\t\tINNER JOIN `Order` ON `OrderAttribute`.`OrderID` = `Order`.`ID`;"); foreach ($query as $row) { $newdata = $row; $newdata["ClassName"] = "OrderDiscountModifier"; $newdata["ID"] = 0; if (!OrderDiscountModifier::get()->filter("OrderID", $newdata["OrderID"])->exists()) { $newmodifier = new OrderDiscountModifier($newdata); $newmodifier->write(); $discount = Discount::get()->byID($newdata["CouponID"]); //set up discount values if ($discount && $discount->exists()) { $newmodifier->Discounts()->add($discount, array("DiscountAmount" => $newmodifier->Amount)); } $this->log("Migrated modifier for Order " . $newdata["OrderID"] . " " . $newmodifier->ID); } } } else { $this->log("OrderCouponModifier table does not exist"); } }
/** * Autogenerate the code, if needed */ protected function onBeforeWrite() { if (empty($this->Code)) { $this->Code = self::generate_code(); } parent::onBeforeWrite(); }
function processOrderStep($params) { global $errors, $cart, $smarty, $order_pages_hook_stay; /* Manage discounts */ if (intval(Tools::getValue('addDiscount')) == 1) { $discountName = Tools::getValue('discount_name'); if (!Validate::isDiscountName($discountName)) { $errors[] = Tools::displayError('voucher name not valid'); } else { $discount = new Discount(intval(Discount::getIdByName($discountName))); if (is_object($discount) and $discount->id) { if ($tmpError = $cart->checkDiscountValidity($discount, $cart->getDiscounts(), $cart->getOrderTotalLC(), $cart->getProducts(), true)) { $errors[] = $tmpError; } } else { $errors[] = Tools::displayError('voucher name not valid'); } if (!sizeof($errors)) { $cart->addDiscount(intval($discount->id)); } } // Why do we need a redirect here? Copied from // original order.php source. Seems like // otherwize the cart display doesn't get // updated properly Tools::redirect('order.php?step=' . $params['step']); } elseif (intval(Tools::getValue('deleteDiscount')) == 1) { if (Validate::isUnsignedId($_GET['deleteDiscount'])) { $cart->deleteDiscount(intval($_GET['deleteDiscount'])); } Tools::redirect('order.php?step=' . $params['step']); } }
function findCode($code) { if (version_compare(_PS_VERSION_, '1.5', '>=')) { return CartRule::getIdByCode($code); } else { return Discount::getIdByName($code); } }
public function itemMatchesCriteria(OrderItem $item, Discount $discount) { $products = $discount->Products(); $itemproduct = $item->Product(true); // true forces the current version of product to be retrieved. if ($products->exists()) { foreach ($products as $product) { // uses 'DiscountedProductID' since some subclasses of buyable could be used as the item product (such as // a bundle) rather than the product stored. if ($product->ID == $itemproduct->DiscountedProductID) { return true; } } $this->error(_t('ProductsDiscountConstraint.MISSINGPRODUCT', "The required products are not in the cart.")); return false; } return true; }
/** * Attach behavior to model * @param $owner */ public function attach($owner) { if (!$owner->isNewRecord && Yii::app()->controller instanceof Controller) { if (DiscountBehavior::$discounts === null) { DiscountBehavior::$discounts = Discount::model()->activeOnly()->applyDate()->findAll(); } parent::attach($owner); } }
public function Edit() { $input = Input::all(); $discount_id = $input['id']; $role = $this->role->GetAllRoleAgent(); $listBranch = $this->branch->GetAllBranch(); $discount = Discount::find($discount_id); return View::make('admin.discount.add')->with('discount', $discount)->with('role', $role)->with('listBranch', $listBranch); }
public function destroy($id) { $discount = Discount::with('reductions')->find($id); if ($discount->reductions->count() > 0) { Session::flash('message', 'Tidak dapat menghapus data Diskon! Diskon ini pernah digunakan'); } else { Discount::destroy($id); Session::flash('message', 'Sukses menghapus Diskon!'); } }
function validate() { $result = parent::validate(); //prevent vital things from changing foreach (self::$defaults as $field => $value) { if ($this->isChanged($field)) { $result->error("{$field} should not be changed for partial use discounts."); } } return $result; }