WooCartPopUpFrontendFestiPlugin

The Woocart Popup Lite for WooCommerce WooCartPopUpFrontendFestiPlugin class.

Defined (1)

The class is defined in the following location(s).

/common/WooCartPopUpFrontendFestiPlugin.php  
  1. class WooCartPopUpFrontendFestiPlugin extends WooCartPopUpFestiPlugin 
  2. protected function onInit() 
  3. $this->_onInitPluginCookie(); 
  4.  
  5. $this->addActionListener('wp_enqueue_scripts', 'onInitJsAction'); 
  6.  
  7. $this->addActionListener('wp_print_styles', 'onInitCssAction'); 
  8.  
  9. $this->addActionListener( 
  10. 'wp_ajax_nopriv_remove_product',  
  11. 'onRemoveCartProductAction' 
  12. ); 
  13.  
  14. $this->addActionListener( 
  15. 'woocommerce_add_to_cart',  
  16. 'showPopupContainerAction' 
  17. ); 
  18.  
  19. $this->addActionListener( 
  20. 'wp_ajax_remove_product',  
  21. 'onRemoveCartProductAction' 
  22. ); 
  23.  
  24. $this->addFilterListener( 
  25. 'add_to_cart_fragments',  
  26. 'onDisplayCartFilter' 
  27. ); 
  28.  
  29. $options = $this->getOptions('settings'); 
  30.  
  31. $this->appendCssToHeaderForCartCustomize($options); 
  32.  
  33. $this->appendHiddenPopupContainer($options); 
  34. } // end onInit 
  35.  
  36. public function showPopupContainerAction() 
  37. $this->addActionListener( 
  38. 'wp_head',  
  39. 'appendCallScriptPopupContainerAction' 
  40. ); 
  41. } // end showPopupContainerAction 
  42.  
  43. public function appendCallScriptPopupContainerAction() 
  44. echo $this-> fetch('popup_call_script.phtml'); 
  45. } // end appendCallScriptPopupContainerAction 
  46.  
  47. public function getPluginCssUrl($fileName)  
  48. return $this->_pluginCssUrl.'frontend/'.$fileName; 
  49. } // end getPluginCssUrl 
  50.  
  51. public function getPluginJsUrl($fileName) 
  52. return $this->_pluginJsUrl.'frontend/'.$fileName; 
  53. } // end getPluginJsUrl 
  54.  
  55. public function getPluginTemplatePath($fileName) 
  56. return $this->_pluginTemplatePath.'frontend/'.$fileName; 
  57. } // end getPluginTemplatePath 
  58.  
  59. public function onInitJsAction() 
  60. $this->onEnqueueJsFileAction('jquery'); 
  61. $this->onEnqueueJsFileAction( 
  62. 'festi-cart-general',  
  63. 'general.js',  
  64. 'festi-cart-popup',  
  65. $this->_version 
  66. ); 
  67. $this->onEnqueueJsFileAction( 
  68. 'festi-cart-popup',  
  69. 'popup.js',  
  70. 'jquery',  
  71. $this->_version 
  72. ); 
  73. wp_localize_script( 
  74. 'festi-cart-general',  
  75. 'fesiCartAjax',  
  76. array('ajaxurl' => admin_url('admin-ajax.php')) 
  77. ); 
  78. } // end onInitJsAction 
  79.  
  80. public function onRemoveCartProductAction() 
  81. if ($this->_hasDeleteItemInRequest()) { 
  82. $woocommerce = $this->getWoocommerceInstance(); 
  83. $item = $_POST['deleteItem']; 
  84. $woocommerce->cart->set_quantity($item , 0); 
  85.  
  86. echo $woocommerce->cart->get_cart_contents_count(); 
  87. }  
  88.  
  89. exit(); 
  90. } // end onRemoveCartProductAction 
  91.  
  92. private function _hasDeleteItemInRequest() 
  93. return array_key_exists('deleteItem', $_POST)  
  94. && !empty($_POST['deleteItem']); 
  95. } // end _hasDeleteItemInRequest 
  96.  
  97. public function onInitCssAction() 
  98. $this->onEnqueueCssFileAction( 
  99. 'festi-cart-styles',  
  100. 'style.css',  
  101. array(),  
  102. $this->_version 
  103. ); 
  104. } // end onInitCssAction 
  105.  
  106. private function _onInitPluginCookie() 
  107. $value = $this->getPluginCookie(); 
  108.  
  109. if (!$value) { 
  110. return false; 
  111.  
  112. if (!$this->_hasValueInCookieArray('woocommerce_cart_hash')) { 
  113. $this->_setCookieForWoocommerceCartHash( 
  114. 'woocommerce_cart_hash',  
  115. $value 
  116. );  
  117.  
  118. $cookieName = 'festi_cart_for_woocommerce_storage'; 
  119. if (!$this->_hasValueInCookieArray($cookieName)) { 
  120. $this->_setCookieForWoocommerceCartHash( 
  121. 'festi_cart_for_woocommerce_storage',  
  122. $value 
  123. ); 
  124. } else if ($this->_isChangedCookieValue($value)) { 
  125. add_action( 
  126. 'wp_enqueue_scripts',  
  127. array(&$this, 'onClearStorageAction') 
  128. ); 
  129.  
  130. $this->_setCookieForWoocommerceCartHash( 
  131. 'festi_cart_for_woocommerce_storage',  
  132. $value 
  133. ); 
  134.  
  135. return true; 
  136.  
  137. } // end _onInitPluginCookie 
  138.  
  139. public function getPluginCookie() 
  140. $value = array(); 
  141.  
  142. $value = $this->getOptions('cookie'); 
  143.  
  144. return $value[0]; 
  145. } // end getPluginCookie 
  146.  
  147. private function _setCookieForWoocommerceCartHash($name, $value, $time = 0) 
  148. setcookie( 
  149. $name,  
  150. $value,  
  151. $time,  
  152. COOKIEPATH,  
  153. COOKIE_DOMAIN 
  154. ); 
  155. } // end _setCookieForWoocommerceCartHash 
  156.  
  157. public function fetchDropdownListContent() 
  158. $vars = array( 
  159. 'woocommerce' => $this->getWoocommerceInstance(),  
  160. 'settings' => $this->getOptions('settings') 
  161. ); 
  162.  
  163. return $this->fetch('dropdown_list_content.phtml', $vars); 
  164. } // end fetchDropdownListContent 
  165.  
  166. private function _hasValueInCookieArray($cookieName) 
  167. return isset($_COOKIE[$cookieName]) 
  168. && !empty($_COOKIE[$cookieName]); 
  169. } // end _hasValueInCookieArray 
  170.  
  171. private function _isChangedCookieValue($value) 
  172. return $_COOKIE['festi_cart_for_woocommerce_storage'] != $value; 
  173. } // end _isChangedCookieValue 
  174.  
  175. public function onClearStorageAction() 
  176. $this->onEnqueueJsFileAction( 
  177. 'festi-cart-clear-storage',  
  178. 'clear_storage.js',  
  179. 'jquery' 
  180. ); 
  181. } // end onHeadAction 
  182.  
  183. public function appendHiddenPopupContainer($options) 
  184. if (!$this->_isEnablePopUpWindow($options)) { 
  185. return false;  
  186.  
  187. $this->addActionListener( 
  188. 'wp_footer',  
  189. 'onDisplayPopupContainerAction' 
  190. ); 
  191. } // end appendHiddenPopupContainer 
  192.  
  193. private function _isEnablePopUpWindow($options) 
  194. return array_key_exists('popup', $options);  
  195. } // end _isEnablePopUpWindow 
  196.  
  197. public function onDisplayPopupContainerAction() 
  198. $vars = array( 
  199. 'woocommerce' => $this->getWoocommerceInstance(),  
  200. 'settings' => $this->getOptions('settings') 
  201. ); 
  202.  
  203. $content = $this->fetch('popup_content.phtml', $vars); 
  204.  
  205. $vars['content'] = $content; 
  206.  
  207. echo $this->fetch('popup_container.phtml', $vars); 
  208. } // end onDisplayPopupContainerAction 
  209.  
  210. public function appendCssToHeaderForCartCustomize($options) 
  211. $this->addActionListener( 
  212. 'wp_head',  
  213. 'addCssToHeaderAction' 
  214. ); 
  215. } // end appendCssToHeaderForCartCustomize 
  216.  
  217. public function addCssToHeaderAction() 
  218. $vars = array( 
  219. 'settings' => $this->getOptions('settings'),  
  220. 'woocommerce'=> $this->getWoocommerceInstance() 
  221. ); 
  222.  
  223. echo $this->fetch('popup_customize_style.phtml', $vars); 
  224. } // end addCssToHeaderAction 
  225.  
  226. public function fetchCart($template = 'cart.phtml') 
  227. $vars = array( 
  228. 'woocommerce' => $this->getWoocommerceInstance(),  
  229. 'settings' => $this->getOptions('settings') 
  230. ); 
  231.  
  232. return $this->fetch($template, $vars); 
  233. } // end fetchCart 
  234.  
  235. public function onDisplayCartFilter($cssSelectors) 
  236. $content = $this->fetchCart('popup_content.phtml'); 
  237.  
  238. $selectorName = '.festi-cart-pop-up-products-content'; 
  239.  
  240. $cssSelectors[$selectorName] = $content; 
  241.  
  242. return $cssSelectors; 
  243. } // end onDisplayCartFilter