/** * Returns the CustomHtmlFormConfig or triggers an error if not existent. * * @return SilvercartConfig|false * * @author Sascha Koehler <*****@*****.**>, Roland Lehmann * @since 10.02.2013 */ public static function getConfig() { if (is_null(self::$config)) { self::$config = SiteConfig::current_site_config(); if (!self::$config) { if (SilvercartTools::isIsolatedEnvironment()) { return false; } $errorMessage = _t('CustomHtmlFormConfiguration.ERROR_NO_CONFIG'); self::triggerError($errorMessage); } } return self::$config; }
/** * 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; }
/** * Diplays an error rendered with Silvercart's error template. * * @param string $errorMessage the error message to display * * @return void * * @author Sebastian Diel <*****@*****.**> * @since 08.04.2014 */ public static function triggerError($errorMessage) { if (SilvercartTools::isIsolatedEnvironment()) { $output = $errorMessage; } else { $elements = array('ErrorMessage' => $errorMessage); $output = Controller::curr()->customise($elements)->renderWith(array('SilvercartErrorPage', 'Page')); } print $output; exit; }
/** * 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)); } } } }
/** * Checks whether the current request is a special, isolated environment * * @return boolean * * @author Sebastian Diel <*****@*****.**> * @since 25.01.2013 */ public static function isIsolatedEnvironment() { if (is_null(self::$isIsolatedEnvironment)) { self::$isIsolatedEnvironment = false; if (array_key_exists('url', $_REQUEST) && (strpos($_REQUEST['url'], '/Security/login') !== false || strpos($_REQUEST['url'], 'dev/build') !== false || self::isInstallationCompleted() == false) || array_key_exists('QUERY_STRING', $_SERVER) && (strpos($_SERVER['QUERY_STRING'], 'dev/tests') !== false || strpos($_SERVER['QUERY_STRING'], 'dev/build') !== false) || array_key_exists('SCRIPT_NAME', $_SERVER) && strpos($_SERVER['SCRIPT_NAME'], 'install.php') !== false || SapphireTest::is_running_test() || ($_SERVER['SCRIPT_NAME'] === FRAMEWORK_DIR . '/cli-script.php' || $_SERVER['SCRIPT_NAME'] === '/' . FRAMEWORK_DIR . '/cli-script.php')) { self::$isIsolatedEnvironment = true; } } return self::$isIsolatedEnvironment; }
/** * Decrement the positions quantity if it is higher than the stock quantity. * If this position has a quantity of 5 but the products stock quantity is * only 3 the positions quantity would be set to 3. * This happens only if the product is not overbookable. * * @return void * * @author Roland Lehmann <*****@*****.**>, Sebastian Diel <*****@*****.**> * @since 26.11.2012 */ public function adjustQuantityToStockQuantity() { if (!SilvercartTools::isIsolatedEnvironment()) { if (SilvercartConfig::EnableStockManagement() && !$this->SilvercartProduct()->isStockQuantityOverbookable()) { if ($this->Quantity > $this->SilvercartProduct()->StockQuantity) { $this->Quantity = $this->SilvercartProduct()->StockQuantity; $this->write(); SilvercartShoppingCartPositionNotice::setNotice($this->ID, "adjusted"); } } } }
/** * 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; } }