PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/www/wp-content/plugins/ithemes-exchange/lib/cart/class.cart.php

https://github.com/ArzuA/gitwordpress
PHP | 577 lines | 352 code | 84 blank | 141 comment | 64 complexity | a45e7ba0a7dac572b9144474ef5e2885 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Shopping cart class.
  4. * @since 0.3.8
  5. * @package IT_Exchange
  6. */
  7. class IT_Exchange_Shopping_Cart {
  8. /**
  9. * Class constructor.
  10. *
  11. * Hooks default filters and actions for cart
  12. *
  13. * @since 0.3.8
  14. * @return void
  15. */
  16. function IT_Exchange_Shopping_Cart() {
  17. add_action( 'template_redirect', array( $this, 'handle_it_exchange_cart_function' ) );
  18. add_filter( 'it_exchange_process_transaction', array( $this, 'handle_purchase_cart_request' ) );
  19. // Filters to sync cart across devices
  20. add_action( 'it_exchange_clear_session', array( $this, 'sync_customer_active_carts' ) );
  21. add_action( 'it_exchange_clear_session_data', array( $this, 'sync_customer_active_carts' ) );
  22. add_action( 'it_exchange_update_session_data', array( $this, 'sync_customer_active_carts' ) );
  23. add_action( 'it_exchange_add_session_data', array( $this, 'sync_customer_active_carts' ) );
  24. add_action( 'wp_login', 'it_exchange_merge_cached_customer_cart_into_current_session', 10, 2 );
  25. }
  26. /**
  27. * Handles $_REQUESTs and submits them to the cart for processing
  28. *
  29. * @since 0.4.0
  30. * @return void
  31. */
  32. function handle_it_exchange_cart_function() {
  33. $this->redirect_checkout_if_empty_cart(); //if on checkout but have empty cart, redirect
  34. // Grab action and process it.
  35. if ( isset( $_REQUEST['it-exchange-action'] ) ) {
  36. call_user_func( array( $this, 'handle_' . esc_attr( $_REQUEST['it-exchange-action'] ) . '_request' ) );
  37. return;
  38. }
  39. // Possibly Handle Remove Product Request
  40. $remove_from_cart_var = it_exchange_get_field_name( 'remove_product_from_cart' );
  41. if ( ! empty( $_REQUEST[$remove_from_cart_var] ) ) {
  42. $this->handle_remove_product_from_cart_request();
  43. return;
  44. }
  45. // Possibly Handle Update Cart Request
  46. $update_cart_var = it_exchange_get_field_name( 'update_cart_action' );
  47. if ( ! empty( $_REQUEST[$update_cart_var] ) ) {
  48. $this->handle_update_cart_request();
  49. return;
  50. }
  51. // Possibly Handle Proceed to checkout
  52. $proceed_var = it_exchange_get_field_name( 'proceed_to_checkout' );
  53. if ( ! empty( $_REQUEST[$proceed_var] ) ) {
  54. $this->proceed_to_checkout();
  55. return;
  56. }
  57. // Possibly Handle Empty Cart request
  58. $empty_var = it_exchange_get_field_name( 'empty_cart' );
  59. if ( ! empty( $_REQUEST[$empty_var] ) ) {
  60. $this->handle_empty_shopping_cart_request();
  61. return;
  62. }
  63. // Possibly Handle Continue Shopping Request
  64. $empty_var = it_exchange_get_field_name( 'continue_shopping' );
  65. if ( ! empty( $_REQUEST[$empty_var] ) ) {
  66. if ( $url = it_exchange_get_page_url( 'store' ) ) {
  67. it_exchange_redirect( $url, 'cart-continue-shopping' );
  68. die();
  69. }
  70. return;
  71. }
  72. // Possibly handle update shipping address request
  73. if ( ! empty( $_REQUEST['it-exchange-update-shipping-address'] ) ) {
  74. $this->handle_update_shipping_address_request();
  75. return;
  76. }
  77. // Possibly handle update billing address request
  78. if ( ! empty( $_REQUEST['it-exchange-update-billing-address'] ) ) {
  79. $this->handle_update_billing_address_request();
  80. return;
  81. }
  82. }
  83. /**
  84. * Listens for $_REQUESTs to buy a product now
  85. *
  86. * @since 0.3.8
  87. * @return void
  88. */
  89. function handle_buy_now_request() {
  90. $buy_now_var = it_exchange_get_field_name( 'buy_now' );
  91. $product_id = empty( $_REQUEST[$buy_now_var] ) ? 0 : $_REQUEST[$buy_now_var];
  92. $product = it_exchange_get_product( $product_id );
  93. $quantity_var = it_exchange_get_field_name( 'product_purchase_quantity' );
  94. $requested_quantity = empty( $_REQUEST[$quantity_var] ) ? 1 : absint( $_REQUEST[$quantity_var] );
  95. $cart = it_exchange_get_page_url( 'cart' );
  96. // Vefify legit product
  97. if ( ! $product )
  98. $error = 'bad-product';
  99. // Verify nonce
  100. $nonce_var = apply_filters( 'it_exchange_purchase_product_nonce_var', '_wpnonce' );
  101. if ( empty( $_REQUEST[$nonce_var] ) || ! wp_verify_nonce( $_REQUEST[$nonce_var], 'it-exchange-purchase-product-' . $product_id ) )
  102. $error = 'product-not-added-to-cart';
  103. // Add product
  104. if ( empty( $error ) && it_exchange_add_product_to_shopping_cart( $product_id, $requested_quantity ) ) {
  105. $sw_state = is_user_logged_in() ? 'checkout' : 'login';
  106. // Get current URL without exchange query args
  107. $url = it_exchange_clean_query_args();
  108. if ( it_exchange_is_multi_item_cart_allowed() && it_exchange_get_page_url( 'checkout' ) ) {
  109. $url = it_exchange_get_page_url( 'checkout' );
  110. it_exchange_redirect( $url, 'buy-now-success-no-sw' );
  111. die();
  112. } else {
  113. $url = add_query_arg( 'ite-sw-state', $sw_state, $url );
  114. it_exchange_redirect( $url, 'buy-now-success-in-sw' );
  115. die();
  116. }
  117. }
  118. $error = empty( $error ) ? 'product-not-added-to-cart' : $error;
  119. it_exchange_add_message( 'error', __( 'Product not added to cart', 'it-l10n-ithemes-exchange' ) );
  120. it_exchange_redirect( $url, 'buy-now-failed' );
  121. die();
  122. }
  123. /**
  124. * Listens for $_REQUESTs to add a product to the cart and processes
  125. *
  126. * @since 0.3.8
  127. * @return void
  128. */
  129. function handle_add_product_to_cart_request() {
  130. $add_to_cart_var = it_exchange_get_field_name( 'add_product_to_cart' );
  131. $product_id = empty( $_REQUEST[$add_to_cart_var] ) ? 0 : $_REQUEST[$add_to_cart_var];
  132. $product = it_exchange_get_product( $product_id );
  133. $quantity_var = it_exchange_get_field_name( 'product_purchase_quantity' );
  134. $requested_quantity = empty( $_REQUEST[$quantity_var] ) ? 1 : absint( $_REQUEST[$quantity_var] );
  135. $cart = it_exchange_get_page_url( 'cart' );
  136. // Vefify legit product
  137. if ( ! $product )
  138. $error = 'bad-product';
  139. // Verify nonce
  140. $nonce_var = apply_filters( 'it_exchange_purchase_product_nonce_var', '_wpnonce' );
  141. if ( empty( $_REQUEST[$nonce_var] ) || ! wp_verify_nonce( $_REQUEST[$nonce_var], 'it-exchange-purchase-product-' . $product_id ) )
  142. $error = 'product-not-added-to-cart';
  143. // Add product
  144. if ( empty( $error ) && it_exchange_add_product_to_shopping_cart( $product_id, $requested_quantity ) ) {
  145. $sw_state = is_user_logged_in() ? 'cart' : 'login';
  146. // Get current URL without exchange query args
  147. $url = it_exchange_clean_query_args();
  148. it_exchange_add_message( 'notice', __( 'Product added to cart', 'it-l10n-ithemes-exchange' ) );
  149. if ( it_exchange_is_multi_item_cart_allowed() && it_exchange_get_page_url( 'cart' ) ) {
  150. $url = it_exchange_get_page_url( 'cart' );
  151. it_exchange_redirect( $url, 'add-to-cart-success-no-sw' );
  152. die();
  153. } else {
  154. $url = add_query_arg( 'ite-sw-state', $sw_state, $url );
  155. it_exchange_redirect( $url, 'add-to-cart-success-in-sw' );
  156. die();
  157. }
  158. }
  159. $error_var = it_exchange_get_field_name( 'error_message' );
  160. $error = empty( $error ) ? 'product-not-added-to-cart' : $error;
  161. $url = add_query_arg( array( $error_var => $error ), $cart );
  162. it_exchange_redirect( $url, 'add-to-cart-failed' );
  163. die();
  164. }
  165. /**
  166. * Empty the iThemes Exchange shopping cart
  167. *
  168. * @since 0.3.8
  169. * @return void
  170. */
  171. function handle_empty_shopping_cart_request() {
  172. // Verify nonce
  173. $nonce_var = apply_filters( 'it_exchange_cart_action_nonce_var', '_wpnonce' );
  174. $error_var = it_exchange_get_field_name( 'error_message' );
  175. $message_var = it_exchange_get_field_name( 'alert_message' );
  176. $session_id = it_exchange_get_session_id();
  177. if ( it_exchange_is_multi_item_cart_allowed() )
  178. $cart = it_exchange_get_page_url( 'cart' );
  179. else
  180. $cart = it_exchange_clean_query_args();
  181. if ( empty( $_REQUEST[$nonce_var] ) || ! wp_verify_nonce( $_REQUEST[$nonce_var], 'it-exchange-cart-action-' . $session_id ) ) {
  182. $url = add_query_arg( array( $error_var => 'cart-not-emptied' ), $cart );
  183. $url = remove_query_arg( it_exchange_get_field_name( 'empty_cart' ), $url );
  184. $redirect_options = array( 'query_arg' => array( $error_var => 'cart-not-emptied' ) );
  185. it_exchange_redirect( $url, 'cart-empty-failed', $redirect_options );
  186. die();
  187. }
  188. // Empty the cart
  189. it_exchange_empty_shopping_cart();
  190. $url = remove_query_arg( $error_var, $cart );
  191. $url = add_query_arg( array( $message_var => 'cart-emptied' ), $url );
  192. $url = remove_query_arg( it_exchange_get_field_name( 'empty_cart' ), $cart );
  193. $redirect_options = array( 'query_arg' => array( $message_var => 'cart-emptied' ) );
  194. it_exchange_redirect( $url, 'cart-empty-success', $redirect_options );
  195. die();
  196. }
  197. /**
  198. * Removes a single product from the shopping cart
  199. *
  200. * This listens for REQUESTS to remove a product from the cart, verifies the request, and passes it along to the correct function
  201. *
  202. * @since 0.3.8
  203. * @return void
  204. */
  205. function handle_remove_product_from_cart_request() {
  206. $var = it_exchange_get_field_name( 'remove_product_from_cart' );
  207. $car_product_ids = empty( $_REQUEST[$var] ) ? array() : $_REQUEST[$var];
  208. $session_id = it_exchange_get_session_id();
  209. // Base URL
  210. if ( it_exchange_is_multi_item_cart_allowed() )
  211. $cart_url = it_exchange_get_page_url( 'cart' );
  212. else
  213. $cart_url = it_exchange_clean_query_args();
  214. // Verify nonce
  215. $nonce_var = apply_filters( 'it_exchange_remove_product_from_cart_nonce_var', '_wpnonce' );
  216. if ( empty( $_REQUEST[$nonce_var] ) || ! wp_verify_nonce( $_REQUEST[$nonce_var], 'it-exchange-cart-action-' . $session_id ) ) {
  217. $var = it_exchange_get_field_name( 'error_message' );
  218. $url = add_query_arg( array( $var => 'product-not-removed' ), $cart_url );
  219. $redirect_options = array( 'query_arg' => array( $var => 'product-not-removed' ) );
  220. it_exchange_redirect( $url, 'cart-remove-product-failed', $redirect_options );
  221. die();
  222. }
  223. foreach( (array) $car_product_ids as $car_product_id ) {
  224. it_exchange_delete_cart_product( $car_product_id );
  225. }
  226. $var = it_exchange_get_field_name( 'alert_message' );
  227. $url = add_query_arg( array( $var => 'product-removed' ), $cart_url );
  228. $redirect_options = array( 'query_arg' => array( $var => 'product-removed' ) );
  229. it_exchange_redirect( $url, 'cart-remove-product-success', $redirect_options );
  230. die();
  231. }
  232. /**
  233. * Listens for the REQUEST to update the shopping cart, verifies it, and calls the correct function
  234. *
  235. * @since 0.3.8
  236. * @return void
  237. */
  238. function handle_update_cart_request( $redirect=true ) {
  239. $session_id = it_exchange_get_session_id();
  240. // Verify nonce
  241. $nonce_var = apply_filters( 'it_exchange_cart_action_nonce_var', '_wpnonce' );
  242. if ( it_exchange_is_multi_item_cart_allowed() ) {
  243. $cart = it_exchange_get_page_url( 'cart' );
  244. } else {
  245. $cart = it_exchange_clean_query_args( array( it_exchange_get_field_name( 'sw_cart_focus' ) ) );
  246. if ( it_exchange_in_superwidget() )
  247. $cart = add_query_arg( 'ite-sw-state', 'cart', $cart );
  248. }
  249. if ( empty( $_REQUEST[$nonce_var] ) || ! wp_verify_nonce( $_REQUEST[$nonce_var], 'it-exchange-cart-action-' . $session_id ) ) {
  250. $var = it_exchange_get_field_name( 'error_message' );
  251. $url = add_query_arg( array( $var => 'cart-not-updated' ), $cart );
  252. $url = remove_query_arg( it_exchange_get_field_name( 'empty_cart' ), $url );
  253. $redirect_options = array( 'query_arg' => array( $var => 'cart-not-updated' ) );
  254. it_exchange_redirect( $url, 'cart-update-failed', $redirect_options );
  255. die();
  256. }
  257. // Are we updating any quantities
  258. $var_name = it_exchange_get_field_name( 'product_purchase_quantity' );
  259. if ( ! empty( $_REQUEST[$var_name] ) ) {
  260. foreach( (array) $_REQUEST[$var_name] as $cart_product_id => $quantity ) {
  261. it_exchange_update_cart_product_quantity( $cart_product_id, $quantity, false );
  262. }
  263. }
  264. do_action( 'it_exchange_update_cart' );
  265. $message_var = it_exchange_get_field_name( 'alert_message' );
  266. if ( ! empty ( $message_var ) && $redirect ) {
  267. $url = remove_query_arg( $message_var, $cart );
  268. $url = add_query_arg( array( $message_var => 'cart-updated' ), $url );
  269. $url = remove_query_arg( it_exchange_get_field_name( 'empty_cart' ), $url );
  270. $redirect_options = array( 'query_arg' => array( $message_var => 'cart-updated' ) );
  271. it_exchange_redirect( $url, 'cart-update-success', $redirect_options );
  272. die();
  273. }
  274. }
  275. /**
  276. * Handles updating a Shipping address
  277. *
  278. * @since 1.4.0
  279. *
  280. * @return void
  281. */
  282. function handle_update_shipping_address_request() {
  283. // Validate nonce
  284. if ( empty( $_REQUEST['it-exchange-update-shipping-address'] ) || ! wp_verify_nonce( $_REQUEST['it-exchange-update-shipping-address'], 'it-exchange-update-checkout-shipping-address-' . it_exchange_get_session_id() ) ) {
  285. it_exchange_add_message( 'error', __( 'Error adding Shipping Address. Please try again.', 'it-l10n-ithemes-exchange' ) );
  286. $GLOBALS['it_exchange']['shipping-address-error'] = true;
  287. return false;
  288. }
  289. // Validate required fields
  290. $required_fields = apply_filters( 'it_exchange_required_shipping_address_fields', array( 'first-name', 'last-name', 'address1', 'state', 'country', 'zip' ) );
  291. $states = it_exchange_get_data_set( 'states', array( 'country' => $_REQUEST['it-exchange-shipping-address-country'] ) );
  292. if ( empty( $states ) && $key = array_search( 'state', $required_fields ) ) {
  293. unset( $required_fields[$key] );
  294. }
  295. foreach( $required_fields as $field ) {
  296. if ( empty( $_REQUEST['it-exchange-shipping-address-' . $field] ) ) {
  297. it_exchange_add_message( 'error', __( 'Please fill out all required fields', 'it-l10n-ithemes-exchange' ) );
  298. $GLOBALS['it_exchange']['shipping-address-error'] = true;
  299. return false;
  300. }
  301. }
  302. /** @todo This is hardcoded for now. will be more flexible at some point **/
  303. $shipping = array();
  304. $fields = apply_filters( 'it_exchange_shipping_address_fields', array(
  305. 'first-name',
  306. 'last-name',
  307. 'company-name',
  308. 'address1',
  309. 'address2',
  310. 'city',
  311. 'state',
  312. 'zip',
  313. 'country',
  314. 'email',
  315. 'phone',
  316. ) );
  317. foreach( $fields as $field ) {
  318. $shipping[$field] = empty( $_REQUEST['it-exchange-shipping-address-' . $field] ) ? '' : $_REQUEST['it-exchange-shipping-address-' . $field];
  319. }
  320. if ( it_exchange_save_shipping_address( $shipping, it_exchange_get_current_customer_id() ) ) {
  321. it_exchange_add_message( 'notice', __( 'Shipping Address Saved', 'it-l10n-ithemes-exchange' ) );
  322. return true;
  323. }
  324. return false;
  325. }
  326. /**
  327. * Handles updating a billing address
  328. *
  329. * @since 1.3.0
  330. *
  331. * @return void
  332. */
  333. function handle_update_billing_address_request() {
  334. // Validate nonce
  335. if ( empty( $_REQUEST['it-exchange-update-billing-address'] ) || ! wp_verify_nonce( $_REQUEST['it-exchange-update-billing-address'], 'it-exchange-update-checkout-billing-address-' . it_exchange_get_session_id() ) ) {
  336. it_exchange_add_message( 'error', __( 'Error adding Billing Address. Please try again.', 'it-l10n-ithemes-exchange' ) );
  337. $GLOBALS['it_exchange']['billing-address-error'] = true;
  338. return false;
  339. }
  340. // Validate required fields
  341. $required_fields = apply_filters( 'it_exchange_required_billing_address_fields', array( 'first-name', 'last-name', 'address1', 'city', 'state', 'country', 'zip' ) );
  342. $states = it_exchange_get_data_set( 'states', array( 'country' => $_REQUEST['it-exchange-billing-address-country'] ) );
  343. if ( empty( $states ) && $key = array_search( 'state', $required_fields ) ) {
  344. unset( $required_fields[$key] );
  345. }
  346. foreach( $required_fields as $field ) {
  347. if ( empty( $_REQUEST['it-exchange-billing-address-' . $field] ) ) {
  348. it_exchange_add_message( 'error', __( 'Please fill out all required fields', 'it-l10n-ithemes-exchange' ) );
  349. $GLOBALS['it_exchange']['billing-address-error'] = true;
  350. return false;
  351. }
  352. }
  353. /** @todo This is hardcoded for now. will be more flexible at some point **/
  354. $billing = array();
  355. $fields = apply_filters( 'it_exchange_billing_address_fields', array(
  356. 'first-name',
  357. 'last-name',
  358. 'company-name',
  359. 'address1',
  360. 'address2',
  361. 'city',
  362. 'state',
  363. 'zip',
  364. 'country',
  365. 'email',
  366. 'phone',
  367. ) );
  368. foreach( $fields as $field ) {
  369. $billing[$field] = empty( $_REQUEST['it-exchange-billing-address-' . $field] ) ? '' : $_REQUEST['it-exchange-billing-address-' . $field];
  370. }
  371. if ( it_exchange_save_customer_billing_address( $billing ) ) {
  372. it_exchange_add_message( 'notice', __( 'Billing Address Saved', 'it-l10n-ithemes-exchange' ) );
  373. // Update Shipping if checked
  374. if ( ! empty( $_REQUEST['it-exchange-ship-to-billing'] ) && '1' == $_REQUEST['it-exchange-ship-to-billing'] )
  375. it_exchange_save_shipping_address( $billing, it_exchange_get_current_customer_id() );
  376. }
  377. return true;
  378. }
  379. /**
  380. * Advances the user to the checkout screen after updating the cart
  381. *
  382. * @since 0.3.8
  383. * @return void
  384. */
  385. function proceed_to_checkout() {
  386. // Update cart info before redirecting.
  387. $this->handle_update_cart_request( false );
  388. // Redirect to Checkout
  389. if ( $checkout = it_exchange_get_page_url( 'checkout' ) ) {
  390. it_exchange_redirect( $checkout, 'cart-proceed-to-checkout' );
  391. die();
  392. }
  393. }
  394. /**
  395. * Process checkout
  396. *
  397. * Formats data and hands it off to the appropriate tranaction method
  398. *
  399. * @since 0.3.8
  400. * @param bool $status
  401. * @return boolean
  402. */
  403. function handle_purchase_cart_request( $status ) {
  404. if ( $status ) //if this has been modified as true already, return.
  405. return $status;
  406. // Verify transaction method exists
  407. $method_var = it_exchange_get_field_name( 'transaction_method' );
  408. $requested_transaction_method = empty( $_REQUEST[$method_var] ) ? false : $_REQUEST[$method_var];
  409. $enabled_addons = it_exchange_get_enabled_addons( array( 'category' => 'transaction-methods' ) );
  410. if ( ! $requested_transaction_method || empty( $enabled_addons[$requested_transaction_method] ) ) {
  411. do_action( 'it_exchange_error_bad_transaction_method_at_purchase', $requested_transaction_method );
  412. it_exchange_add_message( 'error', $this->get_cart_message( 'bad-transaction-method' ) );
  413. return false;
  414. }
  415. if ( $transaction_object = it_exchange_generate_transaction_object() ) {
  416. $transaction_object = apply_filters( 'it_exchange_transaction_object', $transaction_object, $requested_transaction_method );
  417. // Do the transaction
  418. return it_exchange_do_transaction( $requested_transaction_method, $transaction_object );
  419. }
  420. return false;
  421. }
  422. /**
  423. * Redirect from checkout to cart if there are no items in the cart
  424. *
  425. * @since 0.3.8
  426. * @return void
  427. */
  428. function redirect_checkout_if_empty_cart() {
  429. $cart = it_exchange_get_page_url( 'cart' );
  430. $checkout = it_exchange_get_page_url( 'checkout' );
  431. if ( empty( $checkout ) || ! it_exchange_is_page( 'checkout' ) )
  432. return;
  433. $products = it_exchange_get_cart_products();
  434. if ( empty( $products ) ){
  435. it_exchange_redirect( $cart, 'checkout-empty-send-to-cart' );
  436. die();
  437. }
  438. }
  439. /**
  440. * Gets message for given key
  441. *
  442. * @since 0.4.0
  443. * @param string $key
  444. * @return string
  445. */
  446. function get_cart_message( $key ) {
  447. $message = $this->default_cart_messages();
  448. return ( !empty( $message[$key] ) ) ? $message[$key] : __( 'Unknown error. Please try again.', 'it-l10n-ithemes-exchange' );;
  449. }
  450. /**
  451. * Sets up default messages
  452. *
  453. * @since 0.4.0
  454. * @return array
  455. */
  456. function default_cart_messages() {
  457. $messages['bad-transaction-method'] = __( 'Please select a payment method', 'it-l10n-ithemes-exchange' );
  458. $messages['failed-transaction'] = __( 'There was an error processing your transaction. Please try again.', 'it-l10n-ithemes-exchange' );
  459. $messages['product-not-removed'] = __( 'Product not removed from cart. Please try again.', 'it-l10n-ithemes-exchange' );
  460. $messages['cart-not-emptied'] = __( 'There was an error emptying your cart. Please try again.', 'it-l10n-ithemes-exchange' );
  461. $messages['cart-not-updated'] = __( 'There was an error updating your cart. Please try again.', 'it-l10n-ithemes-exchange' );
  462. $messages['cart-updated'] = __( 'Cart Updated.', 'it-l10n-ithemes-exchange' );
  463. $messages['cart-emptied'] = __( 'Cart Emptied', 'it-l10n-ithemes-exchange' );
  464. $messages['product-removed'] = __( 'Product removed from cart.', 'it-l10n-ithemes-exchange' );
  465. $messages['product-added-to-cart'] = __( 'Product added to cart', 'it-l10n-ithemes-exchange' );
  466. return apply_filters( 'it_exchange_default_cart_messages', $messages );
  467. }
  468. /**
  469. * Makes calls to sync carts when customer modifies cart data
  470. *
  471. * @since 1.9.0
  472. *
  473. * @return void
  474. */
  475. function sync_customer_active_carts() {
  476. // Don't do this if user is logging out
  477. if ( ! empty( $GLOBALS['it_exchange']['logging_out_user'] ) )
  478. return;
  479. remove_action( 'it_exchange_clear_session', array( $this, 'sync_customer_active_carts' ) );
  480. remove_action( 'it_exchange_clear_session_data', array( $this, 'sync_customer_active_carts' ) );
  481. remove_action( 'it_exchange_update_session_data', array( $this, 'sync_customer_active_carts' ) );
  482. remove_action( 'it_exchange_add_session_data', array( $this, 'sync_customer_active_carts' ) );
  483. it_exchange_add_current_session_to_customer_active_carts();
  484. it_exchange_cache_customer_cart();
  485. it_exchange_sync_current_cart_with_all_active_customer_carts();
  486. add_action( 'it_exchange_clear_session', array( $this, 'sync_customer_active_carts' ) );
  487. add_action( 'it_exchange_clear_session_data', array( $this, 'sync_customer_active_carts' ) );
  488. add_action( 'it_exchange_update_session_data', array( $this, 'sync_customer_active_carts' ) );
  489. add_action( 'it_exchange_add_session_data', array( $this, 'sync_customer_active_carts' ) );
  490. }
  491. }
  492. if ( ! is_admin() )
  493. $GLOBALS['IT_Exchange_Shopping_Cart'] = new IT_Exchange_Shopping_Cart();