public function getContent() { if (Tools::isSubmit('submitUpdate')) { Configuration::updateValue('NW_CONFIRMATION_EMAIL', (bool) Tools::getValue('NW_CONFIRMATION_EMAIL')); Configuration::updateValue('NW_VERIFICATION_EMAIL', (bool) Tools::getValue('NW_VERIFICATION_EMAIL')); $voucher = Tools::getValue('NW_VOUCHER_CODE'); if ($voucher && !Validate::isDiscountName($voucher)) { $this->_html .= $this->displayError($this->l('The voucher code is invalid.')); } else { Configuration::updateValue('NW_VOUCHER_CODE', pSQL($voucher)); $this->_html .= $this->displayConfirmation($this->l('Settings updated')); } } elseif (Tools::isSubmit('subscribedmerged')) { $id = Tools::getValue('id'); if (preg_match('/(^N)/', $id)) { $id = (int) substr($id, 1); $sql = 'UPDATE ' . _DB_PREFIX_ . 'newsletter SET active = 0 WHERE id = ' . $id; Db::getInstance()->execute($sql); } else { $c = new Customer((int) $id); $c->newsletter = (int) (!$c->newsletter); $c->update(); } Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&conf=4&token=' . Tools::getAdminTokenLite('AdminModules')); } elseif (Tools::isSubmit('exportSubscribers')) { $header = array('id', 'shop_name', 'gender', 'lastname', 'firstname', 'email', 'subscribed', 'subscribed_on'); // TODO $array_to_export = array_merge(array($header), $this->getSubscribers()); $file_name = time() . '.csv'; $fd = fopen($this->getLocalPath() . $file_name, 'w+'); foreach ($array_to_export as $tab) { $line = implode(';', $tab); $line .= "\n"; fwrite($fd, $line, 4096); } fclose($fd); Tools::redirect(_PS_BASE_URL_ . __PS_BASE_URI__ . 'modules/' . $this->name . '/' . $file_name); } elseif (Tools::isSubmit('exportOnlyBlockNews')) { $array_to_export = $this->getBlockNewsletterSubscriber(); $file_name = time() . '.csv'; $fd = fopen($this->getLocalPath() . $file_name, 'w+'); foreach ($array_to_export as $tab) { $line = implode(';', $tab); $line .= "\n"; fwrite($fd, $line, 4096); } fclose($fd); Tools::redirect(_PS_BASE_URL_ . __PS_BASE_URI__ . 'modules/' . $this->name . '/' . $file_name); } elseif (Tools::isSubmit('searchEmail')) { $this->_searched_email = Tools::getValue('searched_email'); } $this->_html .= $this->renderForm(); $this->_html .= $this->renderSearchForm(); $this->_html .= $this->renderList(); $this->_html .= '<div class="panel"><a href="' . $this->context->link->getAdminLink('AdminModules', false) . '&exportSubscribers&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '"> <button class="btn btn-default btn-lg"><span class="icon icon-share"></span> ' . $this->l('Export as CSV') . '</button> </a></div>'; $this->_html .= $this->renderExportForm(); return $this->_html; }
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']); } }
public function getContent() { $this->_html = '<h2>' . $this->displayName . '</h2>'; if (Tools::isSubmit('submitUpdate')) { if (isset($_POST['new_page']) and Validate::isBool((int) $_POST['new_page'])) { Configuration::updateValue('NW_CONFIRMATION_NEW_PAGE', $_POST['new_page']); } if (isset($_POST['conf_email']) and VAlidate::isBool((int) $_POST['conf_email'])) { Configuration::updateValue('NW_CONFIRMATION_EMAIL', pSQL($_POST['conf_email'])); } if (!empty($_POST['voucher']) and !Validate::isDiscountName($_POST['voucher'])) { $this->_html .= '<div class="alert">' . $this->l('Voucher code is invalid') . '</div>'; } else { Configuration::updateValue('NW_VOUCHER_CODE', pSQL($_POST['voucher'])); $this->_html .= '<div class="conf ok">' . $this->l('Updated') . '</div>'; } } return $this->_displayForm(); }
/** * Get discount ID from name * * @param string $discountName Discount name * @return integer Discount ID */ public static function getIdByName($discountName) { if (!Validate::isDiscountName($discountName)) { die(Tools::displayError()); } $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT `id_discount` FROM `' . _DB_PREFIX_ . 'discount` WHERE `name` = \'' . pSQL($discountName) . '\''); return isset($result['id_discount']) ? $result['id_discount'] : false; }
public function preProcess() { global $isVirtualCart; parent::preProcess(); // Redirect to the good order process if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 0 and strpos($_SERVER['PHP_SELF'], 'order.php') === false) { Tools::redirect('order.php'); } if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1 and strpos($_SERVER['PHP_SELF'], 'order-opc.php') === false) { if (isset($_GET['step']) and $_GET['step'] == 3) { Tools::redirect('order-opc.php?isPaymentStep=true'); } Tools::redirect('order-opc.php'); } if (Configuration::get('PS_CATALOG_MODE')) { $this->errors[] = Tools::displayError('This store has not accepted your new order.'); } if (Tools::isSubmit('submitReorder') and $id_order = (int) Tools::getValue('id_order')) { $oldCart = new Cart(Order::getCartIdStatic((int) $id_order, (int) self::$cookie->id_customer)); $duplication = $oldCart->duplicate(); if (!$duplication or !Validate::isLoadedObject($duplication['cart'])) { $this->errors[] = Tools::displayError('Sorry, we cannot renew your order.'); } elseif (!$duplication['success']) { $this->errors[] = Tools::displayError('Missing items - we are unable renew your order'); } else { self::$cookie->id_cart = $duplication['cart']->id; self::$cookie->write(); if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { Tools::redirect('order-opc.php'); } Tools::redirect('order.php'); } } if ($this->nbProducts) { if (Tools::isSubmit('submitAddDiscount') and Tools::getValue('discount_name')) { $discountName = Tools::getValue('discount_name'); if (!Validate::isDiscountName($discountName)) { $this->errors[] = Tools::displayError('Voucher name invalid.'); } else { $discount = new Discount((int) Discount::getIdByName($discountName)); if (Validate::isLoadedObject($discount)) { if ($tmpError = self::$cart->checkDiscountValidity($discount, self::$cart->getDiscounts(), self::$cart->getOrderTotal(), self::$cart->getProducts(), true)) { $this->errors[] = $tmpError; } } else { $this->errors[] = Tools::displayError('Voucher name invalid.'); } if (!sizeof($this->errors)) { self::$cart->addDiscount((int) $discount->id); Tools::redirect('order-opc.php'); } } self::$smarty->assign(array('errors' => $this->errors, 'discount_name' => Tools::safeOutput($discountName))); } elseif (isset($_GET['deleteDiscount']) and Validate::isUnsignedId($_GET['deleteDiscount'])) { self::$cart->deleteDiscount((int) $_GET['deleteDiscount']); Tools::redirect('order-opc.php'); } /* Is there only virtual product in cart */ if ($isVirtualCart = self::$cart->isVirtualCart()) { $this->_setNoCarrier(); } } self::$smarty->assign('back', Tools::safeOutput(Tools::getValue('back'))); }
public function postProcess() { global $currentIndex, $cookie; $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token; if ($discountName = Tools::getValue('name') and Validate::isDiscountName($discountName) and Discount::discountExists($discountName, Tools::getValue('id_discount'))) { $this->_errors[] = Tools::displayError('A voucher of this name already exists. Please choose another name.'); } if (Tools::getValue('submitAdd' . $this->table)) { if (Tools::getValue('id_discount_type') == 0) { $this->_errors[] = Tools::displayError('Please set a type for this voucher.'); } if (Tools::getValue('id_discount_type') == 2 and Tools::getValue('id_currency') == 0) { $this->_errors[] = Tools::displayError('Please set a currency for this voucher.'); } if ((Tools::getValue('id_discount_type') == 1 || Tools::getValue('id_discount_type') == 2) && !Tools::getValue('value')) { $this->_errors[] = Tools::displayError('Please set a amount for this voucher.'); } if (!Validate::isBool_Id(Tools::getValue('id_target'))) { $this->_errors[] = Tools::displayError('Invalid customer or group ID field'); } else { $rules = explode('_', Tools::getValue('id_target')); /* In form, there is one field for two differents fields in object*/ $_POST[$rules[0] ? 'id_group' : 'id_customer'] = $rules[1]; } /* Checking fields validity */ $this->validateRules(); if (!sizeof($this->_errors)) { $id = (int) Tools::getValue($this->identifier); /* Object update */ if (isset($id) and !empty($id)) { if ($this->tabAccess['edit'] === '1') { $object = new $this->className($id); if (Validate::isLoadedObject($object)) { /* Specific to objects which must not be deleted */ if ($this->deleted and $this->beforeDelete($object)) { $object->deleted = 1; $object->update(); $objectNew = new $this->className(); $this->copyFromPost($objectNew, $this->table); $result = $objectNew->add(); if (Validate::isLoadedObject($objectNew)) { $this->afterDelete($objectNew, $object->id); } } else { if (($categories = Tools::getValue('categoryBox')) === false or !empty($categories) and !is_array($categories)) { $this->_errors[] = Tools::displayError('Please set a category for this voucher.'); } $this->copyFromPost($object, $this->table); if ($object->id_discount_type == 3) { $object->id_currency = 0; $object->value = 0; } elseif ($object->id_discount_type == 1) { $object->id_currency = 0; } $result = $object->update(true, false, $categories); } if (!$result) { $this->_errors[] = Tools::displayError('An error occurred while updating object.') . ' <b>' . $this->table . '</b>'; } elseif ($this->postImage($object->id)) { if ($back = Tools::getValue('back')) { Tools::redirectAdmin(urldecode($back) . '&conf=4'); } if (Tools::getValue('stay_here') == 'on' || Tools::getValue('stay_here') == 'true' || Tools::getValue('stay_here') == '1') { Tools::redirectAdmin($currentIndex . '&' . $this->identifier . '=' . $object->id . '&conf=4&updatescene&token=' . $token); } Tools::redirectAdmin($currentIndex . '&' . $this->identifier . '=' . $object->id . '&conf=4&token=' . $token); } } else { $this->_errors[] = Tools::displayError('An error occurred while updating object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } else { if ($this->tabAccess['add'] === '1') { $object = new $this->className(); $this->copyFromPost($object, $this->table); $categories = Tools::getValue('categoryBox', null); if (!$object->add(true, false, $categories)) { $this->_errors[] = Tools::displayError('An error occurred while creating object.') . ' <b>' . $this->table . '</b>'; } elseif ($_POST[$this->identifier] = $object->id and $this->postImage($object->id) and $this->_redirect) { Tools::redirectAdmin($currentIndex . '&' . $this->identifier . '=' . $object->id . '&conf=3&token=' . $token); } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } } $this->_errors = array_unique($this->_errors); } else { return parent::postProcess(); } }
public function getContent() { if (Tools::isSubmit('submitUpdate')) { Configuration::updateValue('NW_CONFIRMATION_EMAIL', (bool) Tools::getValue('NW_CONFIRMATION_EMAIL')); Configuration::updateValue('NW_VERIFICATION_EMAIL', (bool) Tools::getValue('NW_VERIFICATION_EMAIL')); $voucher = Tools::getValue('NW_VOUCHER_CODE'); if ($voucher && !Validate::isDiscountName($voucher)) { $this->_html .= $this->displayError($this->l('The voucher code is invalid.')); } else { Configuration::updateValue('NW_VOUCHER_CODE', pSQL($voucher)); $this->_html .= $this->displayConfirmation($this->l('Settings updated')); } } elseif (Tools::isSubmit('subscribedmerged')) { $id = Tools::getValue('id'); if (preg_match('/(^N)/', $id)) { $id = (int) substr($id, 1); $sql = 'UPDATE ' . _DB_PREFIX_ . 'newsletter SET active = 0 WHERE id = ' . $id; Db::getInstance()->execute($sql); } else { $c = new Customer((int) $id); $c->newsletter = (int) (!$c->newsletter); $c->update(); } Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&conf=4&token=' . Tools::getAdminTokenLite('AdminModules')); } elseif (Tools::isSubmit('submitExport') && ($action = Tools::getValue('action'))) { $this->export_csv(); } elseif (Tools::isSubmit('searchEmail')) { $this->_searched_email = Tools::getValue('searched_email'); } $this->_html .= $this->renderForm(); $this->_html .= $this->renderSearchForm(); $this->_html .= $this->renderList(); $this->_html .= $this->renderExportForm(); return $this->_html; }
public function preProcess() { global $isVirtualCart, $cookie; parent::preProcess(); // Redirect to the good order process if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 0 and (strpos($_SERVER['PHP_SELF'], 'order.php') === false and strpos($_SERVER['PHP_SELF'], 'cart-summary-large.php') === false)) { Tools::redirect('order.php'); } if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1 and strpos($_SERVER['PHP_SELF'], 'order-opc.php') === false) { if (isset($_GET['step']) and $_GET['step'] == 3) { Tools::redirect('order-opc.php?isPaymentStep=true'); } Tools::redirect('order-opc.php'); } if (Configuration::get('PS_CATALOG_MODE')) { $this->errors[] = Tools::displayError('This store has not accepted your new order.'); } if (Tools::isSubmit('submitReorder') and $id_order = (int) Tools::getValue('id_order')) { $oldCart = new Cart(Order::getCartIdStatic((int) $id_order, (int) self::$cookie->id_customer)); $duplication = $oldCart->duplicate(); if (!$duplication or !Validate::isLoadedObject($duplication['cart'])) { $this->errors[] = Tools::displayError('Sorry, we cannot renew your order.'); } elseif (!$duplication['success']) { $this->errors[] = Tools::displayError('Missing items - we are unable to renew your order'); } else { self::$cookie->id_cart = $duplication['cart']->id; self::$cookie->write(); if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { Tools::redirect('order-opc.php'); } Tools::redirect('order.php'); } } if (Tools::isSubmit('submit_instructions')) { $instructions = Tools::getValue('special_instructions'); self::$cart->gift_message = pSQL($instructions); self::$cart->update(); Tools::redirect('order?step=3'); } if ($this->nbProducts) { /* check discount validity */ $cartDiscounts = self::$cart->getDiscounts(); $discountInvalid = false; foreach ($cartDiscounts as $k => $cartDiscount) { if ($error = self::$cart->checkDiscountValidity(new Discount((int) $cartDiscount['id_discount']), $cartDiscounts, self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING), self::$cart->getProducts())) { self::$cart->deleteDiscount((int) $cartDiscount['id_discount']); $discountInvalid = true; } } if ($discountInvalid) { Tools::redirect('order-opc.php'); } if (Tools::getValue('redeem_points')) { $points = (int) Tools::getValue('redeem_points'); if ($points < 1) { self::$smarty->assign('redeem_points', $points); $this->errors[] = Tools::displayError('You can redeem minimum of 1 coin in an order.'); } $orderTotal = self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS); $redemption_status = VBRewards::checkPointsValidity($cookie->id_customer, $points + self::$cart->getPoints(), $orderTotal); if ($redemption_status === CAN_REDEEM_COINS) { self::$cart->addPoints($points); self::$smarty->assign('redeem_points', (int) self::$cart->getPoints()); } else { if ($redemption_status === INSUFFICIENT_VALID_ORDERS) { $this->errors[] = Tools::displayError('Coins can be redeemed from second purchase onwards.'); } else { if ($redemption_status === MIN_CRITERIA_NOT_MET) { $this->errors[] = Tools::displayError('Order value should be more than 100 USD to redeem coins'); } } } $this->adjustPoints(); } elseif (Tools::getValue('deletePoints')) { self::$cart->deletePoints(); } if (Tools::isSubmit('submitAddDiscount') and Tools::getValue('discount_name')) { $discountName = Tools::getValue('discount_name'); if (!Validate::isDiscountName($discountName)) { $this->errors[] = Tools::displayError('Voucher name invalid.'); } else { $discount = new Discount((int) Discount::getIdByName($discountName)); if (Validate::isLoadedObject($discount)) { if ($tmpError = self::$cart->checkDiscountValidity($discount, self::$cart->getDiscounts(), self::$cart->getOrderTotal(), self::$cart->getProducts(), true)) { $this->errors[] = $tmpError; } } else { $this->errors[] = Tools::displayError('Voucher name invalid.'); } if (!sizeof($this->errors)) { self::$cart->addDiscount((int) $discount->id); Tools::redirect('order-opc.php'); } } self::$smarty->assign(array('errors' => $this->errors, 'discount_name' => Tools::safeOutput($discountName))); $this->adjustPoints(); } elseif (isset($_GET['deleteDiscount']) and Validate::isUnsignedId($_GET['deleteDiscount'])) { self::$cart->deleteDiscount((int) $_GET['deleteDiscount']); Tools::redirect('order-opc.php'); } /* Is there only virtual product in cart */ if ($isVirtualCart = self::$cart->isVirtualCart()) { $this->_setNoCarrier(); } } //if enough stock, show free gift message $free_products = array(66254, 66255, 66256); $sql = "select quantity from ps_product where id_product in (" . implode(",", $free_products) . ")"; $result = Db::getInstance()->ExecuteS($sql); $free_gift_stock = $has_free_gift = false; foreach ($result as $row) { if (intval($row['quantity']) > 0) { $free_gift_stock = true; break; } } $total_products_wt = self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS); $cv = Tools::convertPrice($total_products_wt, (int) self::$cookie->id_currency, false); /*if( $cv > 50) { if( $free_gift_stock ) { $cart_products = self::$cart->getProducts(); foreach($cart_products as $cproduct) { $id_product = $cproduct['id_product']; if( in_array($id_product, $free_products )) { $has_free_gift = true; break; } } } if( !$has_free_gift && $free_gift_stock ) { self::$smarty->assign("spl_voucher_message","Here is the free <a href='/1222-free-gifts'>gift product</a> for you.Valid still stock lasts. Read <a href='/content/30-womens-day-special-discount'>T&C</a> here"); } } else { $free_products = array(66254, 66255, 66256); foreach($free_products as $p) self::$cart->deleteProduct($p); self::$smarty->assign("spl_voucher_message","We have a free <a href='/1222-free-gifts'>gift product</a> for you if the shopping cart value is atleast USD 50."); } self::$smarty->assign('back', Tools::safeOutput(Tools::getValue('back'))); if (self::$cart->gift_message) { self::$smarty->assign('cart_instructions', 1); self::$smarty->assign('special_instructions', self::$cart->gift_message); }*/ //buy1 get 1 $products = self::$cart->getProducts(true); $offeredProducts = 0; // this is a very interesting array, keeps as many rows as there are items in your cart // if there is an item with quantity 2, it will have two rows in that array, // ie item will have as many rows as the quantity of the item in cart. $offerproducts = array(); foreach ($products as $product) { $productObj = new Product($product['id_product'], true); $tags = $productObj->getTags(1); //print_r($productObj); if (in_array('buy1get1', $tags)) { self::$smarty->assign("spl_voucher_message", "You are eligible for Buy 1 Get 1 Offer"); //counting the b1g1 products $offeredProducts = $offeredProducts + $product['cart_quantity']; } else { if (in_array('buy2get3', $tags)) { self::$smarty->assign("spl_voucher_message", "You are eligible for buy 3 pay for 2 offer"); //counting the b1g1 products $offeredProducts = $offeredProducts + $product['cart_quantity']; } } //adding rows to interesting array $b1g1products for ($q = 0; $q < $product['cart_quantity']; $q++) { array_push($offerproducts, $product); } } //sorting products in ascending order of price usort($offerproducts, function ($prod1, $prod2) { return $prod1['price'] - $prod2['price']; }); ///echo "<pre>";print_r($offerproducts); if (in_array('buy1get1', $tags)) { $noOfferedAdvantageAvailable = (int) ($offeredProducts / 2); } elseif (in_array('buy2get3', $tags)) { $noOfferedAdvantageAvailable = (int) ($offeredProducts / 3); } $discount = 0; for ($p = 0; $p < $noOfferedAdvantageAvailable; $p++) { //print_r("offerproducts".$offerproducts[$p]['price']); $discount = $discount + $offerproducts[$p]['price']; //print_r($discount); } if ((int) self::$cart->id_currency != 2) { $discount = Tools::convertPrice($discount, (int) self::$cart->id_currency, false); } $discount = round($discount, 2); $b1g1DiscountInCart = null; $b2g3DiscountInCart = null; $allCartDiscounts = self::$cart->getDiscounts(); //print_r($allCartDiscounts); foreach ($allCartDiscounts as $cartDiscount) { if (strpos($cartDiscount['name'], 'B1G1') === 0) { $b1g1DiscountInCart = new Discount((int) Discount::getIdByName($cartDiscount['name'])); //echo "buy1get1"; } else { if (strpos($cartDiscount['name'], 'B2G3') === 0) { $b2g3DiscountInCart = new Discount((int) Discount::getIdByName($cartDiscount['name'])); //echo "buy2get3"; } } } if (in_array('buy1get1', $tags)) { if ($discount > 0 && empty($b1g1DiscountInCart)) { $new_discount = new Discount(); $new_discount->id_discount_type = 2; $new_discount->value = $discount; // coupon value $new_discount->name = "B1G1" . Tools::rand_string(5); $new_discount->id_currency = 2; $new_discount->quantity = 1; $new_discount->quantity_per_user = 0; $new_discount->date_from = date('Y-m-d H:i:s'); $new_discount->date_to = '2015-08-10 20:00:00'; //validity $new_discount->cumulable_reduction = 1; $languages = Language::getLanguages(); foreach ($languages as $language) { $new_discount->description[$language['id_lang']] = "Buy1 Get1"; } // coupon description $new_discount->add(); $id_discount = Discount::getIdByName($new_discount->name); self::$cart->addDiscount($id_discount); } else { if (!empty($b1g1DiscountInCart)) { $b1g1DiscountInCart->value = (double) $discount; // coupon value if ($b1g1DiscountInCart->value > 0) { $b1g1DiscountInCart->update(); } else { $b1g1DiscountInCart->delete(); } } } } else { if (in_array('buy2get3', $tags)) { if ($discount > 0 && empty($b2g3DiscountInCart)) { $new_discount = new Discount(); $new_discount->id_discount_type = 2; $new_discount->value = $discount; // coupon value $new_discount->name = "B2G3" . Tools::rand_string(5); $new_discount->id_currency = 2; $new_discount->quantity = 1; $new_discount->quantity_per_user = 0; $new_discount->date_from = date('Y-m-d H:i:s'); $new_discount->date_to = '2015-08-10 20:00:00'; //validity $new_discount->cumulable_reduction = 1; $languages = Language::getLanguages(); foreach ($languages as $language) { $new_discount->description[$language['id_lang']] = "Buy2 Get3"; } // coupon description $new_discount->add(); $id_discount = Discount::getIdByName($new_discount->name); self::$cart->addDiscount($id_discount); } else { if (!empty($b2g3DiscountInCart)) { $b2g3DiscountInCart->value = (double) $discount; // coupon value if ($b2g3DiscountInCart->value > 0) { $b2g3DiscountInCart->update(); } else { $b2g3DiscountInCart->delete(); } } } } } /*//pick3pay2 $products = self::$cart->getProducts(true); //print_r($products); $nP3P2Products = 0; // this is a very interesting array, keeps as many rows as there are items in your cart // if there is an item with quantity 2, it will have two rows in that array, // ie item will have as many rows as the quantity of the item in cart. $p3p2products = array(); foreach($products as $product) { $productObj = new Product($product['id_product'], true); $tags = $productObj->getTags(1); if(in_array('pick3pay2', $tags)){ self::$smarty->assign("spl_voucher_message", "Pick 3 and Pay for 2 only offer"); $nP3P2Products = $nP3P2Products + $product['cart_quantity']; for($q = 0; $q < $product['cart_quantity']; $q++){ array_push($p3p2products, $product); } } } //sorting products in ascending order of price usort($p3p2products, function($prod1, $prod2){ return $prod1['price'] - $prod2['price']; }); $noP3P2AdvantageAvailable = (int)($nP3P2Products/3); print_r($noP3P2AdvantageAvailable); $discount = 0; for($p = 0; $p < $noP3P2AdvantageAvailable; $p++){ $discount = $discount + $p3p2products[$p]['price']; } if((int)self::$cart->id_currency != 2){ $discount = Tools::convertPrice($discount, (int)self::$cart->id_currency, false); } $discount = round($discount, 2); $p3p2DiscountInCart = null; $allCartDiscounts = self::$cart->getDiscounts(); foreach ($allCartDiscounts as $cartDiscount) { //print_r($cartDiscount);print_r('<br/>');die; if(strpos('P3P2', $cartDiscount['name']) == 0){ $p3p2DiscountInCart = new Discount((int) (Discount::getIdByName($cartDiscount['name']))); } } if($discount > 0 && empty($p3p2DiscountInCart)){ $new_discount = new Discount(); $new_discount->id_discount_type = 2; $new_discount->value = $discount; // coupon value $new_discount->name = "P3P2" . Tools::rand_string(5); $new_discount->id_currency = 2; $new_discount->quantity = 1; $new_discount->quantity_per_user = 100; $new_discount->date_from = date('Y-m-d H:i:s'); $new_discount->date_to = '2015-09-10 20:00:00'; //validity $new_discount->cumulable_reduction = 1; $languages = Language::getLanguages(); foreach ($languages as $language) $new_discount->description[$language['id_lang']] = "Pick3 Pay2"; // coupon description $new_discount->add(); $id_discount = Discount::getIdByName($new_discount->name); print_r($id_discount); self::$cart->addDiscount($id_discount); }else if(!empty($p3p2DiscountInCart)){ $p3p2DiscountInCart->value = (float) $discount; // coupon value if($p3p2DiscountInCart->value > 0) $p3p2DiscountInCart->update(); else $p3p2DiscountInCart->delete(); }*/ }
$orderTotal = $cart->getOrderTotal(); $orderTotalDefaultCurrency = Tools::convertPrice($cart->getOrderTotal(true, 1), Currency::getCurrency(intval(Configuration::get('PS_CURRENCY_DEFAULT')))); $minimalPurchase = floatval(Configuration::get('PS_PURCHASE_MINIMUM')); if ($orderTotalDefaultCurrency < $minimalPurchase) { $step = 0; $errors[] = Tools::displayError('A minimum purchase total of') . ' ' . Tools::displayPrice($minimalPurchase, Currency::getCurrency(intval($cart->id_currency))) . ' ' . Tools::displayError('is required in order to validate your order'); } if (!$cookie->isLogged() and in_array($step, array(1, 2, 3))) { Tools::redirect('authentication.php?back=order.php?step=' . $step); } $smarty->assign('back', Tools::safeOutput(Tools::getValue('back'))); if ($cart->nbProducts()) { /* Manage discounts */ if ((Tools::isSubmit('submitDiscount') or Tools::isSubmit('submitDiscount')) and Tools::getValue('discount_name')) { $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->getOrderTotal(), $cart->getProducts(), true)) { $errors[] = $tmpError; } } else { $errors[] = Tools::displayError('voucher name not valid'); } if (!sizeof($errors)) { $cart->addDiscount(intval($discount->id)); Tools::redirect('order.php'); } else { $smarty->assign(array('errors' => $errors, 'discount_name' => Tools::safeOutput($discountName)));
public function getContent() { $this->_html = ''; if (Tools::isSubmit('submitUpdate')) { $conf_email = Tools::getValue('NW_CONFIRMATION_EMAIL'); if ($conf_email && Validate::isBool((int) $conf_email)) { Configuration::updateValue('NW_CONFIRMATION_EMAIL', (int) $conf_email); } $verif_email = Tools::getValue('NW_VERIFICATION_EMAIL'); if ($verif_email && Validate::isBool((int) $verif_email)) { Configuration::updateValue('NW_VERIFICATION_EMAIL', (int) $verif_email); } $voucher = Tools::getValue('NW_VOUCHER_CODE'); if ($voucher && !Validate::isDiscountName($voucher)) { $this->_html .= $this->displayError($this->l('The voucher code is invalid.')); } else { Configuration::updateValue('NW_VOUCHER_CODE', pSQL($voucher)); $this->_html .= $this->displayConfirmation($this->l('Settings updated')); } } return $this->_html . $this->renderForm(); }
public function postProcess() { global $currentIndex, $cookie; $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token; if ($discountName = Tools::getValue('name') and Validate::isDiscountName($discountName) and Discount::discountExists($discountName, Tools::getValue('id_discount'))) { $this->_errors[] = Tools::displayError('A voucher of this name already exists. Please choose another name.'); } if (Tools::getValue('submitAdd' . $this->table)) { /* Checking fields validity */ $this->validateRules(); if (!sizeof($this->_errors)) { $id = intval(Tools::getValue($this->identifier)); /* Object update */ if (isset($id) and !empty($id)) { if ($this->tabAccess['edit'] === '1') { $object = new $this->className($id); if (Validate::isLoadedObject($object)) { /* Specific to objects which must not be deleted */ if ($this->deleted and $this->beforeDelete($object)) { $object->deleted = 1; $object->update(); $objectNew = new $this->className(); $this->copyFromPost($objectNew, $this->table); $result = $objectNew->add(); if (Validate::isLoadedObject($objectNew)) { $this->afterDelete($objectNew, $object->id); } } else { if (($categories = Tools::getValue('categoryBox')) === false or !empty($categories) and !is_array($categories)) { die(Tools::displayError()); } $this->copyFromPost($object, $this->table); $result = $object->update(true, false, $categories); } if (!$result) { $this->_errors[] = Tools::displayError('an error occurred while updating object') . ' <b>' . $this->table . '</b>'; } elseif ($this->postImage($object->id)) { if ($back = Tools::getValue('back')) { Tools::redirectAdmin(urldecode($back) . '&conf=4'); } if (Tools::getValue('stay_here') == 'on' || Tools::getValue('stay_here') == 'true' || Tools::getValue('stay_here') == '1') { Tools::redirectAdmin($currentIndex . '&' . $this->identifier . '=' . $object->id . '&conf=4&updatescene&token=' . $token); } Tools::redirectAdmin($currentIndex . '&' . $this->identifier . '=' . $object->id . '&conf=4&token=' . $token); } } else { $this->_errors[] = Tools::displayError('an error occurred while updating object') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); } } else { if ($this->tabAccess['add'] === '1') { $object = new $this->className(); $this->copyFromPost($object, $this->table); $categories = Tools::getValue('categoryBox', null); if (!$object->add(true, false, $categories)) { $this->_errors[] = Tools::displayError('an error occurred while creating object') . ' <b>' . $this->table . '</b>'; } elseif ($_POST[$this->identifier] = $object->id and $this->postImage($object->id) and $this->_redirect) { Tools::redirectAdmin($currentIndex . '&' . $this->identifier . '=' . $object->id . '&conf=3&token=' . $token); } } else { $this->_errors[] = Tools::displayError('You do not have permission to add anything here.'); } } } $this->_errors = array_unique($this->_errors); } else { return parent::postProcess(); } }
public function getContent() { $this->_html = ''; $dbquery = new DbQuery(); $dbquery->select('c.`id_customer`, c.`id_shop`, c.`lastname`, c.`firstname`, c.`email`, c.`newsletter_date_add`')->from('customer', 'c')->where('c.`newsletter` = 1'); $customers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($dbquery->build()); $non_customers = Db::getInstance()->executeS('SELECT `email`, `id_shop`, `newsletter_date_add` FROM `' . _DB_PREFIX_ . 'newsletter` WHERE `active` = 1'); foreach ($non_customers as &$non_customer) { $non_customer['id_customer'] = ''; $non_customer['lastname'] = ''; $non_customer['firstname'] = ''; } $customers = array_merge($customers, $non_customers); foreach ($customers as &$customer) { ksort($customer); } if (Tools::isSubmit('submitUpdate')) { $conf_email = Tools::getValue('NW_CONFIRMATION_EMAIL'); if ($conf_email && Validate::isBool((int) $conf_email)) { Configuration::updateValue('NW_CONFIRMATION_EMAIL', (int) $conf_email); } $verif_email = Tools::getValue('NW_VERIFICATION_EMAIL'); if ($verif_email && Validate::isBool((int) $verif_email)) { Configuration::updateValue('NW_VERIFICATION_EMAIL', (int) $verif_email); } $voucher = Tools::getValue('NW_VOUCHER_CODE'); if ($voucher && !Validate::isDiscountName($voucher)) { $this->_html .= $this->displayError($this->l('The voucher code is invalid.')); } else { Configuration::updateValue('NW_VOUCHER_CODE', pSQL($voucher)); $this->_html .= $this->displayConfirmation($this->l('Settings updated')); } } elseif (Tools::isSubmit('exportCustomers')) { $header = array('email', 'firstname', 'id_customer', 'id_shop', 'lastname', 'newsletter_date_add'); $array_to_export = array_merge(array($header), $customers); $file_name = time() . '.csv'; $fd = fopen($this->getLocalPath() . $file_name, 'w+'); foreach ($array_to_export as $tab) { $line = implode(';', $tab); $line .= "\n"; fwrite($fd, $line, 4096); } fclose($fd); $this->_html .= $this->displayConfirmation('<a href="' . $this->_path . $file_name . '">' . $file_name . '</a>'); } $fields_list = array('id_customer' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 'auto'), 'id_shop' => array('title' => $this->l('Shop ID'), 'align' => 'center', 'width' => 'auto'), 'lastname' => array('title' => $this->l('Last name'), 'align' => 'center', 'width' => 'auto'), 'firstname' => array('title' => $this->l('First name'), 'align' => 'center', 'width' => 'auto'), 'email' => array('title' => $this->l('Email address'), 'align' => 'center', 'width' => 'auto'), 'newsletter_date_add' => array('title' => $this->l('Registration date'), 'align' => 'center', 'width' => 'auto')); $helper_list = new HelperList(); $helper_list->module = $this; $helper_list->title = $this->l('Newsletter registrations'); $helper_list->shopLinkType = ''; $helper_list->no_link = true; $helper_list->simple_header = true; $helper_list->identifier = 'id_customer'; $helper_list->table = 'customer'; $helper_list->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name; $helper_list->token = Tools::getAdminTokenLite('AdminModules'); $helper_list->actions = array('viewCustomer'); $helper_list = $helper_list->generateList($customers, $fields_list); $button = '<div class="panel"><a href="' . $this->context->link->getAdminLink('AdminModules', false) . '&exportCustomers&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '"> <button class="btn btn-default">' . $this->l('Export as CSV') . '</button> </a></div>'; return $this->_html . $this->renderForm() . $helper_list . $button; }