vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Backend/Member/Callback.php line 27

Open in your IDE?
  1. <?php
  2. /*
  3.  * Isotope eCommerce for Contao Open Source CMS
  4.  *
  5.  * Copyright (C) 2009 - 2019 terminal42 gmbh & Isotope eCommerce Workgroup
  6.  *
  7.  * @link       https://isotopeecommerce.org
  8.  * @license    https://opensource.org/licenses/lgpl-3.0.html
  9.  */
  10. namespace Isotope\Backend\Member;
  11. use Contao\Backend;
  12. use Contao\System;
  13. use Isotope\Isotope;
  14. use Isotope\Model\ProductCollection\Cart;
  15. class Callback extends Backend
  16. {
  17.     /**
  18.      * Limit the member countries to the selection in store config
  19.      * @param string
  20.      */
  21.     public function limitCountries($strTable)
  22.     {
  23.         if ('tl_member' !== $strTable || !Isotope::getConfig()->limitMemberCountries) {
  24.             return;
  25.         }
  26.         $originalField $GLOBALS['TL_DCA']['tl_member']['fields']['country'];
  27.         unset($GLOBALS['TL_DCA']['tl_member']['fields']['country']['options']);
  28.         $GLOBALS['TL_DCA']['tl_member']['fields']['country']['options_callback'] = function () use ($originalField) {
  29.             if (isset($originalField['options_callback'])) {
  30.                 if (\is_array($originalField['options_callback'])) {
  31.                     $callable = [
  32.                         System::importStatic($originalField['options_callback'][0]),
  33.                         $originalField['options_callback'][1],
  34.                     ];
  35.                 } else {
  36.                     $callable $originalField['options_callback'];
  37.                 }
  38.                 $options = \call_user_func_array(
  39.                     $callable,
  40.                     \func_get_args()
  41.                 );
  42.             } else {
  43.                 $options = (array) $originalField['options'];
  44.             }
  45.             $countries array_unique(
  46.                 array_merge(
  47.                     Isotope::getConfig()->getBillingCountries(),
  48.                     Isotope::getConfig()->getShippingCountries()
  49.                 )
  50.             );
  51.             $countries array_intersect_key(
  52.                 $options,
  53.                 array_flip($countries)
  54.             );
  55.             if (=== \count($countries)) {
  56.                 $countryCodes array_keys($countries);
  57.                 $GLOBALS['TL_DCA']['tl_member']['fields']['country']['default'] = $countryCodes[0];
  58.             }
  59.             return $countries;
  60.         };
  61.     }
  62.     /**
  63.      * Delete the cart when a member is deleted
  64.      *
  65.      * @param object $dc
  66.      */
  67.     public function deleteMemberCart($dc)
  68.     {
  69.         $carts Cart::findBy('member'$dc->id);
  70.         if (null !== $carts) {
  71.             foreach ($carts as $cart) {
  72.                 $cart->delete();
  73.             }
  74.         }
  75.     }
  76. }