|
| 1 | +<?php |
| 2 | +/****************************************************************//** |
| 3 | + * Beautiful Popup Notification or Prestashop |
| 4 | + * Add some beautiful popup, where and when you want on your shop |
| 5 | + * |
| 6 | + * @category Module / Front |
| 7 | + * @author Lathanao <Lathanaogmail.com> |
| 8 | + * @copyright 2017 Lathanao |
| 9 | + * @version 1.0 |
| 10 | + * @license Commercial license see README.md |
| 11 | +********************************************************************/ |
| 12 | + |
| 13 | +include_once(dirname(__FILE__).'/models/BNAutoLoad.php'); |
| 14 | +spl_autoload_register(array(BNAutoLoad::getInstance(), 'load')); |
| 15 | + |
| 16 | +class Beautifulpopup extends Module { |
| 17 | + |
| 18 | + protected static $instance = null; |
| 19 | + |
| 20 | + public function __construct() |
| 21 | + { |
| 22 | + $this->name = 'Beautifulpopup'; |
| 23 | + $this->version = '1.0'; |
| 24 | + $this->tab = 'Block'; |
| 25 | + $this->author = "Lathanao"; |
| 26 | + $this->year = '2017'; |
| 27 | + $this->ps_versions_compliancy['min'] = '1.6.0.1'; |
| 28 | + |
| 29 | + parent::__construct(); |
| 30 | + |
| 31 | + $this->displayName = $this->l('Beautiful Popup solution'); |
| 32 | + $this->description = $this->l('Add some beautifull popups, where and when you want on your shop'); |
| 33 | + $this->confirmUninstall = $this->l('Are you sure you want to uninstall this module?'); |
| 34 | + |
| 35 | + $this->file = __FILE__; |
| 36 | + } |
| 37 | + |
| 38 | + public static function getInstance() |
| 39 | + { |
| 40 | + if (self::$instance === null) |
| 41 | + self::$instance = new Beautifulpopup(); |
| 42 | + return self::$instance; |
| 43 | + } |
| 44 | + |
| 45 | + ################ |
| 46 | + # INSTALLATION # |
| 47 | + ################ |
| 48 | + |
| 49 | + public function install() { |
| 50 | + |
| 51 | + |
| 52 | + if (!BNPopup::createDatabase() || !BNTemplate::createDatabase()) |
| 53 | + return false; |
| 54 | + |
| 55 | + if (!parent::install()) |
| 56 | + return false; |
| 57 | + |
| 58 | + if (!$this->registerHook('footer') || !$this->registerHook('backOfficeHeader')) |
| 59 | + return false; |
| 60 | + |
| 61 | + return true; |
| 62 | + } |
| 63 | + |
| 64 | + public static function getVersionDir() |
| 65 | + { |
| 66 | + $version = explode('.', _PS_VERSION_); |
| 67 | + if ((int)$version[1] < 6) |
| 68 | + return ('1.5'); |
| 69 | + return ('1.6'); |
| 70 | + } |
| 71 | + |
| 72 | + |
| 73 | + public function hookbackOfficeHeader() { |
| 74 | + |
| 75 | + $this->context->controller->addCSS(($this->_path).'css/header.css', 'all'); |
| 76 | + } |
| 77 | + |
| 78 | + |
| 79 | + public function hookFooter() { |
| 80 | + |
| 81 | + global $cookie; |
| 82 | + |
| 83 | + if (!Tools::isSubmit('admin_preview_popup')) { |
| 84 | + |
| 85 | + $popups = BNPopup::getAllPopup(); |
| 86 | + $context = Context::getContext(); |
| 87 | + $page = Tools::getValue('controller'); |
| 88 | + $idCustomer = $context->customer->id; |
| 89 | + $nbOrder = Order::getCustomerNbOrders($idCustomer); |
| 90 | + |
| 91 | + foreach($popups as $key => $popup) { |
| 92 | + |
| 93 | + $cookieName = preg_replace('/[^A-Za-z]/', "", $popup->name); |
| 94 | + $cookie = new Cookie($cookieName); |
| 95 | + |
| 96 | + if (!$cookie->__isset($cookieName)) |
| 97 | + $cookie->__set($cookieName, 0); |
| 98 | + |
| 99 | + if ($popup->nb_view <= $cookie->__get($cookieName)) // 2. If allready see |
| 100 | + continue; |
| 101 | + if ($popup->id_bn_page == 2 && $page != "index") // 2. If right page |
| 102 | + continue; |
| 103 | + if ($popup->id_bn_page == 3 && $page != "product") // 2. If right page |
| 104 | + continue; |
| 105 | + if ($popup->id_bn_page == 4 && $page != "cms") // 2. If right page |
| 106 | + continue; |
| 107 | + if ($popup->id_bn_peaple == 2 && !empty($idCustomer)) // 4. Only guest |
| 108 | + continue; |
| 109 | + if ($popup->id_bn_peaple == 3 && empty($idCustomer)) // 5. Only all registered users |
| 110 | + continue; |
| 111 | + if ($popup->id_bn_peaple == 4 && (empty($idCustomer) || $nbOrder == 0)) // 6. Only registered users who made a order allready |
| 112 | + continue; |
| 113 | + if ($popup->id_bn_peaple == 5 && (empty($idCustomer) || $nbOrder != 0)) // 7. Only registered users who never made any order |
| 114 | + continue; |
| 115 | + |
| 116 | + $cookie->__set($cookieName, (1 + $cookie->__get($cookieName))); |
| 117 | + return $this->renderPopup($popup); |
| 118 | + } |
| 119 | + |
| 120 | + } else { |
| 121 | + |
| 122 | + $popup = new BNPopup(Tools::getValue('admin_preview_popup')); |
| 123 | + return $this->renderPopup($popup); |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + |
| 128 | + public function renderPopup($popup) { |
| 129 | + |
| 130 | + global $smarty; |
| 131 | + $template = new BNTemplate($popup->id_bn_template); |
| 132 | + $smarty->assign("popup", $popup); |
| 133 | + $smarty->assign("template", $template); |
| 134 | + $this->context->controller->addjqueryPlugin('fancybox'); |
| 135 | + return ($this->display(__FILE__, 'views/templates/front/popup.tpl')); |
| 136 | + } |
| 137 | +} |
0 commit comments