/**
  * Returns a dropdown map sorted by prioritive countries
  * 
  * @param bool   $onlyActive  Search only for active coutries?
  * @param string $emptyString String to show for empty value
  * 
  * @return array
  */
 public static function getPrioritiveDropdownMap($onlyActive = true, $emptyString = null)
 {
     $key = 0;
     if ($onlyActive) {
         $key = 1;
     }
     if (!is_null($emptyString)) {
         $key .= md5($emptyString);
     }
     if (!array_key_exists($key, self::$prioritiveDropdownMap)) {
         $dropdownMap = array();
         if (!is_null($emptyString)) {
             $dropdownMap[''] = $emptyString;
         }
         if (self::getPrioritiveCountryCount() > 0) {
             $prioritiveCountries = self::getPrioritiveCountries($onlyActive);
             foreach ($prioritiveCountries->map()->toArray() as $id => $title) {
                 $dropdownMap[$id] = $title;
             }
         }
         if (self::getNonPrioritiveCountryCount() > 0) {
             if (is_null($emptyString) && count($dropdownMap) > 0 || !is_null($emptyString) && count($dropdownMap) > 1) {
                 $dropdownMap[' '] = '------------------------';
             }
             $nonPrioritiveCountries = self::getNonPrioritiveCountries($onlyActive);
             foreach ($nonPrioritiveCountries->map()->toArray() as $id => $title) {
                 $dropdownMap[$id] = $title;
             }
         }
         if (empty($dropdownMap) && SilvercartTools::isBackendEnvironment()) {
             $allCountries = SilvercartCountry::get();
             $dropdownMap = $allCountries->map()->toArray();
         }
         self::$prioritiveDropdownMap[$key] = $dropdownMap;
     }
     return self::$prioritiveDropdownMap[$key];
 }
 /**
  * Returns a list of products using the given filter parameters.
  * The required attributes stored in self::$requiredAttributes will be added 
  * to the filter parameters.
  * 
  * @param string $callerClass    Caller class name
  * @param string $filter         Filter to use
  * @param string $sort           Sort field(s) and direction
  * @param string $join           Join tables
  * @param string $limit          Result limitation
  * @param string $containerClass Container class
  * 
  * @return DataList
  * 
  * @author Ramon Kupper <*****@*****.**>
  * @since 19.08.2014
  */
 public static function get($callerClass = 'SilvercartProduct', $filter = "", $sort = "", $join = "", $limit = null, $containerClass = 'DataList')
 {
     $products = parent::get($callerClass, $filter, $sort, $join, $limit, $containerClass);
     if (!SilvercartTools::isBackendEnvironment() && !SilvercartTools::isIsolatedEnvironment()) {
         $requiredAttributesFilter = self::buildRequiredAttributesFilter();
         if (!is_null($requiredAttributesFilter)) {
             $products = $products->where($requiredAttributesFilter);
         }
     }
     return $products;
 }
示例#3
0
 /**
  * Checks whether the current url location is in backend
  * 
  * @return boolean
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 26.11.2012
  */
 public static function isBackendEnvironment()
 {
     if (is_null(self::$isBackendEnvironment)) {
         $isBackendEnvironment = false;
         $controller = Controller::curr();
         $request = $controller->getRequest();
         if (strpos($request->getVar('url'), 'admin/') === 0 || strpos($request->getVar('url'), '/admin/') === 0) {
             $isBackendEnvironment = true;
         }
         self::$isBackendEnvironment = $isBackendEnvironment;
     }
     return self::$isBackendEnvironment;
 }
 /**
  * default constructor
  *
  * @param array $record      array of field values
  * @param bool  $isSingleton true if this is a singleton() object
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 15.11.2014
  */
 public function __construct($record = null, $isSingleton = false)
 {
     parent::__construct($record, $isSingleton);
     if ($this->ID > 0) {
         if (!SilvercartTools::isIsolatedEnvironment() && !SilvercartTools::isBackendEnvironment()) {
             // Initialize shopping cart position object, so that it can inject
             // its forms into the controller.
             if (self::$loadModules) {
                 foreach ($this->SilvercartShoppingCartPositions() as $position) {
                     $position->registerCustomHtmlForms();
                 }
             }
             if (!self::$cartCleaningFinished && !self::$cartCleaningInProgress) {
                 self::$cartCleaningInProgress = true;
                 $this->cleanUp();
             }
             $this->SilvercartShippingMethodID = 0;
             $this->SilvercartPaymentMethodID = 0;
             if (Member::currentUserID() && self::$loadModules) {
                 $this->callMethodOnRegisteredModules('performShoppingCartConditionsCheck', array($this, SilvercartCustomer::currentUser()));
                 $this->callMethodOnRegisteredModules('ShoppingCartInit', array($this));
             }
         }
     }
 }
示例#5
0
 /**
  * Returns the shoppingcart of the current user or false if there's no
  * member object registered.
  * 
  * @return mixed false|SilvercartShoppingCart
  * 
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 15.11.2014
  */
 public function SilvercartShoppingCart()
 {
     $controller = Controller::curr();
     if ($this->class == $controller->class && !SilvercartTools::isIsolatedEnvironment() && !SilvercartTools::isBackendEnvironment()) {
         $member = SilvercartCustomer::currentUser();
         if (!$member) {
             return false;
         }
         return $member->getCart();
     } else {
         return false;
     }
 }