public function getResult($queryRow) { $dr = DiscountRule::getByID($queryRow['drID']); if ($dr) { $dr->retrieveStatistics(); } return $dr; }
public function view() { $codeerror = false; $codesuccess = false; if ($this->isPost()) { if ($this->post('action') == 'code' && $this->post('code')) { $codesuccess = StoreCart::storeCode($this->post('code')); $codeerror = !$codesuccess; } if ($this->post('action') == 'update') { $data = $this->post(); $result = StoreCart::update($data); $added = $result['added']; $returndata = array('success' => true, 'quantity' => (int) $data['pQty'], 'action' => 'update', 'added' => $added); } if ($this->post('action') == 'clear') { StoreCart::clear(); $returndata = array('success' => true, 'action' => 'clear'); } if ($this->post('action') == 'remove') { $data = $this->post(); $result = StoreCart::remove($data['instance']); $returndata = array('success' => true, 'action' => 'remove'); } } $this->set('actiondata', $returndata); $this->set('codeerror', $codeerror); $this->set('codesuccess', $codesuccess); $this->set('cart', StoreCart::getCart()); $this->set('discounts', StoreCart::getDiscounts()); $this->set('total', StoreCalculator::getSubTotal()); $this->addHeaderItem("\n <script type=\"text/javascript\">\n var PRODUCTMODAL = '" . View::url('/productmodal') . "';\n var CARTURL = '" . View::url('/cart') . "';\n var CHECKOUTURL = '" . View::url('/checkout') . "';\n </script>\n "); $this->requireAsset('javascript', 'vivid-store'); $this->requireAsset('css', 'vivid-store'); $discountsWithCodesExist = StoreDiscountRule::discountsWithCodesExist(); $this->set("discountsWithCodesExist", $discountsWithCodesExist); }
public function save($data) { $db = Database::get(); if ($data['drID']) { //if we know the drID, we're updating. if ($data['validFrom'] == '0') { $data['drValidFrom_dt'] = null; } if ($data['validTo'] == '0') { $data['drValidTo_dt'] = null; } //update discount details $vals = array($data['drName'], $data['drDisplay'], $data['drEnabled'], $data['drDescription'], $data['drDeductType'], $data['drValue'], $data['drPercentage'], $data['drDeductFrom'], $data['drTrigger'], $data['drSingleUseCodes'], $data['drExclusive'], $data['drCurrency'], $data['drValidFrom_dt'], $data['drValidTo_dt'], $data['drID']); $drID = $data['drID']; $db->Execute('UPDATE VividStoreDiscountRules SET drName=?, drDisplay=?, drEnabled=?, drDescription=?, drDeductType=?, drValue=?, drPercentage=?, drDeductFrom=?, drTrigger=?, drSingleUseCodes=?, drExclusive=?, drCurrency=?, drValidFrom=?, drValidTo=? WHERE drID = ?', $vals); } else { //else, we don't know it, so we're adding $dt = Core::make('helper/date'); $now = $dt->getLocalDateTime(); //add discount details $vals = array($data['drName'], $data['drDisplay'], $data['drEnabled'], $data['drDescription'], $data['drDeductType'], $data['drValue'], $data['drPercentage'], $data['drDeductFrom'], $data['drTrigger'], $data['drSingleUseCodes'], $data['drExclusive'], $data['drExclusive'], $data['drCurrency'], $data['drValidFrom_dt'], $data['drValidTo_dt'], $now); $db->Execute("INSERT INTO VividStoreDiscountRules (\n drName,\n drDisplay,\n drEnabled,\n drDescription,\n drDeductType,\n drValue,\n drPercentage,\n drDeductFrom,\n drTrigger,\n drSingleUseCodes,\n drExclusive,\n drCurrency,\n drValidFrom,\n drValidTo,\n drDateAdded) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", $vals); $drID = $db->lastInsertId(); } $discountRule = DiscountRule::getByID($drID); return $discountRule; }
public function save() { if ($this->isPost()) { $data = $this->post(); if ($data['drID']) { $this->edit($data['drID']); } $errors = DiscountCode::validate($data); if (!$errors->has()) { $discountrule = DiscountRule::save($data); if ($data['drID']) { $this->redirect('/dashboard/store/discounts/', 'updated'); } else { if ($discountrule->drTrigger == 'code') { $this->redirect('/dashboard/store/discounts/codes/' . $discountrule->drID); } else { $this->redirect('/dashboard/store/discounts/', 'success'); } } } else { $this->error = $errors; } //if no errors } // if post }
public static function storeCode($code) { $rule = StoreDiscountRule::findDiscountRuleByCode($code); if (!empty($rule)) { Session::set('vividstore.code', $code); return true; } return false; }
public function view() { $pkg = Package::getByHandle('vivid_store'); $customer = new StoreCustomer(); $this->set('customer', $customer); $guestCheckout = Config::get('vividstore.guestCheckout'); $this->set('guestCheckout', $guestCheckout ? $guestCheckout : 'off'); $this->set('requiresLogin', StoreCart::requiresLogin()); if (StoreCart::getTotalItemsInCart() == 0) { $this->redirect("/cart/"); } $this->set('form', Core::make("helper/form")); $allcountries = Core::make('helper/lists/countries')->getCountries(); $db = Loader::db(); $ak = UserAttributeKey::getByHandle('billing_address'); $row = $db->GetRow('select akHasCustomCountries, akDefaultCountry from atAddressSettings where akID = ?', array($ak->getAttributeKeyID())); $defaultBillingCountry = $row['akDefaultCountry']; if ($row['akHasCustomCountries'] == 1) { $availableBillingCountries = $db->GetCol('select country from atAddressCustomCountries where akID = ?', array($ak->getAttributeKeyID())); $billingCountries = array(); foreach ($availableBillingCountries as $countrycode) { $billingCountries[$countrycode] = $allcountries[$countrycode]; } } else { $billingCountries = $allcountries; } $ak = UserAttributeKey::getByHandle('shipping_address'); $row = $db->GetRow('select akHasCustomCountries, akDefaultCountry from atAddressSettings where akID = ?', array($ak->getAttributeKeyID())); $defaultShippingCountry = $row['akDefaultCountry']; if ($row['akHasCustomCountries'] == 1) { $availableShippingCountries = $db->GetCol('select country from atAddressCustomCountries where akID = ?', array($ak->getAttributeKeyID())); $shippingCountries = array(); foreach ($availableShippingCountries as $countrycode) { $shippingCountries[$countrycode] = $allcountries[$countrycode]; } } else { $shippingCountries = $allcountries; } $discountsWithCodesExist = StoreDiscountRule::discountsWithCodesExist(); $this->set("discountsWithCodesExist", $discountsWithCodesExist); $this->set('cart', StoreCart::getCart()); $this->set('discounts', StoreCart::getDiscounts()); $this->set('hasCode', StoreCart::hasCode()); $this->set("billingCountries", $billingCountries); $this->set("shippingCountries", $shippingCountries); $this->set("defaultBillingCountry", $defaultBillingCountry); $this->set("defaultShippingCountry", $defaultShippingCountry); $this->set("states", Core::make('helper/lists/states_provinces')->getStates()); $totals = StoreCalculator::getTotals(); $this->set('subtotal', $totals['subTotal']); $this->set('taxes', $totals['taxes']); $this->set('taxtotal', $totals['taxTotal']); $this->set('shippingtotal', $totals['shippingTotal']); $this->set('total', $totals['total']); $this->set('shippingEnabled', StoreCart::isShippable()); $this->addHeaderItem("\n <script type=\"text/javascript\">\n var PRODUCTMODAL = '" . View::url('/productmodal') . "';\n var CARTURL = '" . View::url('/cart') . "';\n var CHECKOUTURL = '" . View::url('/checkout') . "';\n </script>\n "); $this->requireAsset('javascript', 'vivid-store'); $this->requireAsset('css', 'vivid-store'); $this->addFooterItem("\n <script type=\"text/javascript\">\n \$(function() {\n vividStore.loadViaHash();\n });\n </script>\n "); $enabledMethods = StorePaymentMethod::getEnabledMethods(); $availableMethods = array(); foreach ($enabledMethods as $em) { $emmc = $em->getMethodController(); if ($totals['total'] >= $emmc->getPaymentMinimum() && $totals['total'] <= $emmc->getPaymentMaximum()) { $availableMethods[] = $em; } } $this->set("enabledPaymentMethods", $availableMethods); }