/** * Alternative method to set preferences. * * @return void * * @author Sascha Koehler <*****@*****.**> * @since 28.11.2011 */ public function preferences() { $this->preferences['submitButtonTitle'] = _t('SilvercartPage.REMOVE_FROM_CART'); $this->preferences['submitButtonToolTip'] = _t('SilvercartPage.REMOVE_FROM_CART'); $preferences = SilvercartPlugin::call($this, 'updatePreferences', array($this->preferences), true, array()); if (is_array($preferences) && count($preferences) > 0) { $this->preferences = $preferences[0]; } return $this->preferences; }
/** * executed if there are no validation errors on submit * * @param SS_HTTPRequest $data contains the frameworks form data * @param Form $form not used * @param array $formData contains the modules form data * * @return void * * @author Sebastian Diel <*****@*****.**>, * Roland Lehmann <*****@*****.**> * @since 15.11.2014 */ protected function submitSuccess($data, $form, $formData) { $overwrite = SilvercartPlugin::call($this, 'overwriteSubmitSuccess', array($data, $form, $formData), null, 'boolean'); if (!$overwrite) { if ($formData['positionID']) { //check if the position belongs to this user. Malicious people could manipulate it. $member = SilvercartCustomer::currentUser(); $position = DataObject::get_by_id('SilvercartShoppingCartPosition', $formData['positionID']); if ($position && $member->getCart()->ID == $position->SilvercartShoppingCartID) { $position->SilvercartProduct()->addToCart($member->getCart()->ID, 1, true); $backLinkPage = DataObject::get_by_id('SiteTree', $formData['BlID']); $this->controller->redirect($backLinkPage->Link()); } } } }
/** * We register the common forms for SilvercartPages here. * * @return void * * @author Sebastian Diel <*****@*****.**>, * Sascha Koehler <*****@*****.**>, * Patrick Schneider <*****@*****.**> * @since 08.07.2014 */ public function onBeforeInit() { SilvercartTools::initSession(); i18n::set_default_locale(Translatable::get_current_locale()); i18n::set_locale(Translatable::get_current_locale()); $controllerParams = Controller::curr()->getURLParams(); $anonymousCustomer = SilvercartCustomer::currentAnonymousCustomer(); if ($anonymousCustomer) { Session::set('MemberLoginForm.force_message', true); if ($controllerParams['Action'] == 'changepassword') { $anonymousCustomer->logOut(); } } else { Session::set('MemberLoginForm.force_message', false); // used to redirect the logged in user to my-account page $backURL = SilvercartTools::PageByIdentifierCodeLink(self::$newPasswordBackURLIdentifierCode); $this->owner->extend('updateNewPasswordBackURL', $backURL); Session::set('BackURL', $backURL); Session::save(); } $this->owner->registerCustomHtmlForm('SilvercartQuickSearchForm', new SilvercartQuickSearchForm($this->owner)); $this->owner->registerCustomHtmlForm('SilvercartQuickLoginForm', new SilvercartQuickLoginForm($this->owner)); SilvercartPlugin::call($this->owner, 'init', array($this->owner)); }
/** * Insert additional fields for this form from registered plugins. * * @return string * * @author Sascha Koehler <*****@*****.**> * @since 16.11.2011 */ public function AddCartFormDetailAdditionalFields() { return SilvercartPlugin::call($this, 'AddCartFormDetailAdditionalFields', array($this)); }
/** * Returns all additional information to display between Images and Content. * * @return DataObjectSet */ public function getPluggedInAfterImageContent() { if (is_null($this->pluggedInAfterImageContent)) { $this->pluggedInAfterImageContent = SilvercartPlugin::call($this, 'getPluggedInAfterImageContent', array(), false, 'DataObjectSet'); } return $this->pluggedInAfterImageContent; }
/** * Indicates wether this order is net calculated or not. * * @return boolean * * @author Sascha Koehler <*****@*****.**>, Sebastian Diel <*****@*****.**> * @since 14.06.2012 */ public function IsPriceTypeNet() { $isPriceTypeNet = false; if ($this->PriceType == 'net') { $isPriceTypeNet = true; } $isPriceTypeNet = SilvercartPlugin::call($this, 'IsPriceTypeNet', array($isPriceTypeNet)); return $isPriceTypeNet; }
/** * Returns additional tile information provided by plugins * * @return string * * @author Sebastian Diel <*****@*****.**> * @since 26.06.2012 */ public function addToTitle() { $addToTitle = SilvercartPlugin::call($this, 'addToTitle', null, false, ''); return $addToTitle; }
/** * All products of this group * * @param int $numberOfProducts The number of products to return * @param string $sort An SQL sort statement * @param bool $disableLimit Disables the product limitation * @param bool $force Forces to get the products * * @return DataList|false all products of this group * * @author Roland Lehmann <*****@*****.**>, * Sebastian Diel <*****@*****.**> * @since 24.04.2014 */ public function getProducts($numberOfProducts = false, $sort = false, $disableLimit = false, $force = false) { $hashKey = md5($numberOfProducts . '_' . $sort . '_' . $disableLimit . Translatable::get_current_locale()); if ($this->data()->DoNotShowProducts && !$force) { $this->groupProducts[$hashKey] = new ArrayList(); } elseif (!array_key_exists($hashKey, $this->groupProducts) || $force) { $SQL_start = $this->getSqlOffset($numberOfProducts); $productsPerPage = $this->getProductsPerPageSetting(); $pluginProducts = SilvercartPlugin::call($this, 'overwriteGetProducts', array($numberOfProducts, $productsPerPage, $SQL_start, $sort), true, new ArrayList()); if (!empty($pluginProducts)) { $this->groupProducts[$hashKey] = $pluginProducts; } else { $this->listFilters = array(); $filter = ''; // ---------------------------------------------------------------- // Get products that have this group set as mirror group // ---------------------------------------------------------------- if ($numberOfProducts !== false) { $productsPerPage = (int) $numberOfProducts; } $translations = $this->getTranslations(); $translationProductGroupIDs = array($this->ID); if ($translations && $translations->count() > 0) { foreach ($translations as $translation) { $translationProductGroupIDs[] = $translation->ID; } } $translationProductGroupIDList = implode(',', $translationProductGroupIDs); $mirroredProductIdList = ''; $mirroredProductIDs = $this->getMirroredProductIDs(); foreach ($mirroredProductIDs as $mirroredProductID) { $mirroredProductIdList .= sprintf("'%s',", $mirroredProductID); } if (!empty($mirroredProductIdList)) { $mirroredProductIdList = substr($mirroredProductIdList, 0, -1); } // ---------------------------------------------------------------- // Get products that have this group set as main group // ---------------------------------------------------------------- if ($this->isFilteredByManufacturer()) { $manufacturer = SilvercartManufacturer::getByUrlSegment($this->urlParams['ID']); if ($manufacturer) { $this->addListFilter('SilvercartManufacturerID', $manufacturer->ID); } } if (empty($mirroredProductIdList)) { $this->listFilters['original'] = sprintf("SilvercartProductGroupID IN (%s)", $translationProductGroupIDList); } else { $this->listFilters['original'] = sprintf("(SilvercartProductGroupID IN (%s) OR\n \"SilvercartProduct\".\"ID\" IN (%s))", $translationProductGroupIDList, $mirroredProductIdList); } if (count(self::$registeredFilterPlugins) > 0) { foreach (self::$registeredFilterPlugins as $registeredPlugin) { $pluginFilters = $registeredPlugin->filter(); if (is_array($pluginFilters)) { $this->listFilters = array_merge($this->listFilters, $pluginFilters); } } } foreach ($this->listFilters as $listFilterIdentifier => $listFilter) { $filter .= ' ' . $listFilter; } $this->extend('updateGetProductsFilter', $filter); if (!$sort) { $sort = SilvercartProduct::defaultSort(); $this->extend('updateGetProductsSort', $sort); } $groupProducts = SilvercartProduct::getProducts($filter, $sort); $this->extend('onAfterGetProducts', $groupProducts); $this->groupProducts[$hashKey] = $groupProducts; $this->totalNumberOfProducts = $groupProducts->count(); } // Inject additional methods into the ArrayList if ($this->groupProducts[$hashKey]) { $this->groupProducts[$hashKey]->HasMorePagesThan = $this->HasMorePagesThan; } } return $this->groupProducts[$hashKey]; }
/** * determins weather a customer gets prices shown gross or net dependent on * customer's invoice address or class * * @return string returns "gross" or "net" * * @author Roland Lehmann <*****@*****.**>, * Sebastian Diel <*****@*****.**> * @since 15.11.2014 */ public static function Pricetype() { if (is_null(self::$priceType)) { $member = SilvercartCustomer::currentUser(); $configObject = self::getConfig(); $silvercartPluginResult = SilvercartPlugin::call($configObject, 'overwritePricetype', array()); if (!empty($silvercartPluginResult)) { self::$priceType = $silvercartPluginResult; } elseif ($member) { foreach ($member->Groups() as $group) { if (!empty($group->Pricetype) && $group->Pricetype != '---') { self::$priceType = $group->Pricetype; break; } } if (is_null(self::$priceType)) { self::$priceType = self::DefaultPriceType(); } } else { self::$priceType = self::DefaultPriceType(); } } return self::$priceType; }
/** * Send the contact message via email. * * @return void * * @author Sebastian Diel <*****@*****.**> * @since 07.08.2014 */ public function send() { $silvercartPluginCall = SilvercartPlugin::call($this, 'send'); if (!$silvercartPluginCall) { SilvercartShopEmail::send('ContactMessage', SilvercartConfig::DefaultContactMessageRecipient(), array('FirstName' => $this->FirstName, 'Surname' => $this->Surname, 'Street' => $this->Street, 'StreetNumber' => $this->StreetNumber, 'Postcode' => $this->Postcode, 'City' => $this->City, 'SilvercartCountry' => $this->SilvercartCountry(), 'Email' => $this->Email, 'Phone' => $this->Phone, 'Message' => str_replace('\\r\\n', '<br/>', nl2br($this->Message)))); } }
/** * This method is called before CustomHtmlForm set the preferences. You * can manipulate the default preferences here. * * @param array &$preferences Preferences to manipulate * * @return bool * * @author Sascha Koehler <*****@*****.**>, Sebastian Diel <*****@*****.**> * @since 23.03.2012 */ public function updatePreferences(&$preferences) { $extendedPreferences = SilvercartPlugin::call($this->owner, 'updatePreferences', $preferences, true, array()); if ($extendedPreferences && is_array($extendedPreferences) && count($extendedPreferences) > 0) { $preferences = $preferences[0]; } }
/** * Returns one or more plugged in rows for the shopping carts editable table * as a ArrayList * * @return ArrayList * * @author Sebastian Diel <*****@*****.**> * @since 12.09.2012 */ public function addToEditableShoppingCartTable() { $addToCartTable = SilvercartPlugin::call($this, 'addToEditableShoppingCartTable', array(), false, 'ArrayList'); return $addToCartTable; }
// ---------------------------------------------------------------------------- SilvercartPlugin::registerPluginProvider('SilvercartConfig', 'SilvercartConfigPluginProvider'); SilvercartPlugin::registerPluginProvider('SilvercartContactMessage', 'SilvercartContactMessagePluginProvider'); SilvercartPlugin::registerPluginProvider('SilvercartIncrementPositionQuantityForm', 'SilvercartIncrementPositionQuantityFormPluginProvider'); SilvercartPlugin::registerPluginProvider('SilvercartOrder', 'SilvercartOrderPluginProvider'); SilvercartPlugin::registerPluginProvider('SilvercartOrderPosition', 'SilvercartOrderPositionPluginProvider'); SilvercartPlugin::registerPluginProvider('SilvercartProduct', 'SilvercartProductPluginProvider'); SilvercartPlugin::registerPluginProvider('SilvercartProductAddCartFormDetail', 'SilvercartProductAddCartFormDetailPluginProvider'); SilvercartPlugin::registerPluginProvider('SilvercartProductAddCartFormList', 'SilvercartProductAddCartFormListPluginProvider'); SilvercartPlugin::registerPluginProvider('SilvercartProductAddCartFormTile', 'SilvercartProductAddCartFormTilePluginProvider'); SilvercartPlugin::registerPluginProvider('SilvercartProductAddCartForm', 'SilvercartProductAddCartFormPluginProvider'); SilvercartPlugin::registerPluginProvider('SilvercartProductCsvBulkLoader', 'SilvercartProductCsvBulkLoaderPluginProvider'); SilvercartPlugin::registerPluginProvider('SilvercartProductGroupPage_Controller', 'SilvercartProductGroupPage_ControllerPluginProvider'); SilvercartPlugin::registerPluginProvider('SilvercartRemovePositionForm', 'SilvercartRemovePositionFormPluginProvider'); SilvercartPlugin::registerPluginProvider('SilvercartShoppingCart', 'SilvercartShoppingCartPluginProvider'); SilvercartPlugin::registerPluginProvider('SilvercartShoppingCartPosition', 'SilvercartShoppingCartPositionPluginProvider'); // use custom classes Object::useCustomClass('Member_ForgotPasswordEmail', 'SilvercartCustomer_ForgotPasswordEmail'); // configure WidgetSet WidgetSetWidgetExtension::preventWidgetCreationByClass('SilvercartWidget'); SilvercartGridFieldBatchController::addBatchActionFor('SilvercartOrder', 'SilvercartGridFieldBatchAction_ChangeOrderStatus'); SilvercartGridFieldBatchController::addBatchActionFor('SilvercartOrder', 'SilvercartGridFieldBatchAction_PrintOrders'); SilvercartGridFieldBatchController::addBatchActionFor('SilvercartOrder', 'SilvercartGridFieldBatchAction_MarkAsSeen'); SilvercartGridFieldBatchController::addBatchActionFor('SilvercartOrder', 'SilvercartGridFieldBatchAction_MarkAsNotSeen'); SilvercartGridFieldBatchController::addBatchActionFor('SilvercartProduct', 'SilvercartGridFieldBatchAction_ActivateDataObject'); SilvercartGridFieldBatchController::addBatchActionFor('SilvercartProduct', 'SilvercartGridFieldBatchAction_DeactivateDataObject'); SilvercartGridFieldBatchController::addBatchActionFor('SilvercartProduct', 'SilvercartGridFieldBatchAction_ChangeAvailabilityStatus'); SilvercartGridFieldBatchController::addBatchActionFor('SilvercartProduct', 'SilvercartGridFieldBatchAction_ChangeManufacturer'); SilvercartGridFieldBatchController::addBatchActionFor('SilvercartProduct', 'SilvercartGridFieldBatchAction_ChangeProductGroup'); // ---------------------------------------------------------------------------- // Blacklists for SilvercartRestfulServer
/** * Find out if the demanded quantity is in stock when stock management is enabled. * If stock management is disabled true will be returned. * * @param integer $quantity The quantity of products * * @return bool Can this position be incremented * * @author Roland Lehmann <*****@*****.**>, Sebastian Diel <*****@*****.**> * @since 25.06.2012 */ public function isQuantityIncrementableBy($quantity = 1) { if (!array_key_exists((int) $quantity, $this->isQuantityIncrementableByList)) { $isQuantityIncrementableBy = true; $pluginResult = SilvercartPlugin::call($this, 'overwriteIsQuantityIncrementableBy', $quantity, false, 'DataObject'); if (is_null($pluginResult) && SilvercartConfig::EnableStockManagement()) { $isQuantityIncrementableBy = false; if ($this->SilvercartProduct()->isStockQuantityOverbookable()) { $isQuantityIncrementableBy = true; } elseif ($this->SilvercartProduct()->StockQuantity >= $this->Quantity + $quantity) { $isQuantityIncrementableBy = true; } } elseif (!is_null($pluginResult) && is_bool($pluginResult)) { $isQuantityIncrementableBy = $pluginResult; } $this->isQuantityIncrementableByList[$quantity] = $isQuantityIncrementableBy; } return $this->isQuantityIncrementableByList[$quantity]; }
/** * Process a record from the import file * * @param array $record The record to process * @param array $columnMap The map of columns; NOT USED * @param BulkLoader_Result &$results Stores the results so they can be displayed for the user * @param boolean $preview If set to true changes will not be written to the database * * @return boolean * * @author Sascha Koehler <*****@*****.**>, Ramon Kupper <*****@*****.**> * @since 04.10.2014 */ protected function processRecord($record, $columnMap, &$results, $preview = false) { $pluginResult = SilvercartPlugin::call($this, 'overwriteProcessRecord', array($record, $columnMap, $results, $preview), false, 'DataObject'); if ($pluginResult && is_array($pluginResult)) { return $pluginResult[0]; } $silvercartProduct = false; $action = ''; $updateIdentifier = ''; // ---------------------------------------------------------------- // Check for an existing record // ---------------------------------------------------------------- foreach (self::$match_existing_fields as $field) { if (!$silvercartProduct && array_key_exists($field, $record)) { $silvercartProduct = DataObject::get_one('SilvercartProduct', sprintf("\"SilvercartProduct\".\"%s\" = '%s'", $field, $record[$field])); $action = 'update'; $updateIdentifier = $field; } } if (!$silvercartProduct && $this->createNewIfNotMatched) { // ---------------------------------------------------------------- // Create new object: // We go for speed here, thus using direct DB queries. // ---------------------------------------------------------------- $sqlQuery = new SQLQuery('ID', 'SilvercartProduct', null, 'ID DESC', null, null, '1'); $insertID = $sqlQuery->execute()->value(); $insertID = (int) $insertID + 1; DB::query(sprintf("\n INSERT INTO\n SilvercartProduct(\n ID,\n ClassName,\n Created,\n PriceGrossAmount\n ) VALUES(\n %d,\n 'SilvercartProduct',\n '%s',\n '%s'\n )\n ", $insertID, date('Y-m-d H:i:s'), $record['PriceGrossAmount'])); DB::query(sprintf("\n INSERT INTO\n SilvercartProductLanguage(\n ClassName,\n Created,\n SilvercartProductID,\n Locale\n ) VALUES(\n 'SilvercartProductLanguage',\n '%s',\n %d,\n '%s'\n )\n ", date('Y-m-d H:i:s'), $insertID, Translatable::get_current_locale())); $silvercartProduct = DataObject::get_by_id('SilvercartProduct', $insertID); $action = 'insert'; } if ($silvercartProduct) { // -------------------------------------------------------------------- // Update product fields // -------------------------------------------------------------------- if ($silvercartProduct) { if (array_key_exists('ID', $record)) { unset($record['ID']); } // ---------------------------------------------------------------- // save data // ---------------------------------------------------------------- foreach ($record as $fieldName => $val) { if ($this->isNullValue($val, $fieldName)) { continue; } if (strpos($fieldName, '->') !== false) { $funcName = substr($fieldName, 2); $this->{$funcName}($silvercartProduct, $val, $record); } elseif ($silvercartProduct->hasMethod("import" . $fieldName)) { $silvercartProduct->{"import{$fieldName}"}($val, $record); } else { $silvercartProduct->update(array($fieldName => $val)); } } // ---------------------------------------------------------------- // Update product group mirror pages // ---------------------------------------------------------------- if (array_key_exists('SilvercartProductMirrorGroupIDs', $record)) { $this->Log('Mirror IDs are to be set'); // Delete existing relations if ($silvercartProduct->SilvercartProductGroupMirrorPages()) { foreach ($silvercartProduct->SilvercartProductGroupMirrorPages() as $silvercartProductGroupMirrorPage) { $silvercartProduct->SilvercartProductGroupMirrorPages()->remove($silvercartProductGroupMirrorPage); } } // Set new relations $silvercartProductMirrorGroupIDs = explode(',', $record['SilvercartProductMirrorGroupIDs']); foreach ($silvercartProductMirrorGroupIDs as $silvercartProductMirrorGroupID) { if (!empty($silvercartProductMirrorGroupID)) { $silvercartProductGroupMirrorPage = DataObject::get_by_id('SilvercartProductGroupPage', $silvercartProductMirrorGroupID); if ($silvercartProductGroupMirrorPage) { $silvercartProduct->SilvercartProductGroupMirrorPages()->add($silvercartProductGroupMirrorPage); } unset($silvercartProductGroupMirrorPage); } } unset($silvercartProductMirrorGroupIDs); $this->Log('Mirror IDs set'); } $silvercartProduct->write(); $silvercartProductID = $silvercartProduct->ID; if ($action == 'update') { $this->Log("Updated Product ID: " . $silvercartProductID . ", identified by " . $updateIdentifier); } else { $this->Log("Inserted Product ID: " . $silvercartProductID); } } } unset($sqlQuery); unset($insertID); unset($action); return $silvercartProduct; }
/** * standard page controller * * @return void * * @author Roland Lehmann <*****@*****.**>, * Sebastian Diel <*****@*****.**> * @since 15.11.2014 */ public function init() { if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) { if (SilvercartConfig::isUserAgentBlacklisted($_SERVER['HTTP_USER_AGENT'])) { exit; } } if (array_key_exists($this->ID, self::$instanceMemorizer)) { parent::init(); return true; } SilvercartTools::initSession(); $controller = Controller::curr(); if ($this != $controller && method_exists($controller, 'getRegisteredCustomHtmlForms')) { $registeredCustomHtmlForms = $controller->getRegisteredCustomHtmlForms(); } if ($controller == $this || $controller->forceLoadOfWidgets) { $this->loadWidgetControllers(); } $this->loadJSRequirements(); // We have to check if we are in a customised controller (that's the // case for all Security pages). If so, we use the registered forms of // the outermost controller. if (empty($registeredCustomHtmlForms)) { $this->registerCustomHtmlForm('SilvercartQuickSearchForm', new SilvercartQuickSearchForm($this)); $this->registerCustomHtmlForm('SilvercartQuickLoginForm', new SilvercartQuickLoginForm($this)); if ($this->getTranslations()) { $this->registerCustomHtmlForm('SilvercartChangeLanguageForm', new SilvercartChangeLanguageForm($this)); } } else { $this->setRegisteredCustomHtmlForms($registeredCustomHtmlForms); } $allParams = Controller::curr()->getRequest()->allParams(); if (Controller::curr() instanceof Security && array_key_exists('Action', $allParams) && strtolower($allParams['Action']) == 'lostpassword' && Member::currentUserID() > 0 && SilvercartCustomer::currentUser() instanceof Member) { SilvercartCustomer::currentUser()->logOut(); } if (Member::currentUserID() > 0 && !SilvercartCustomer::currentUser() instanceof Member) { Session::set('loggedInAs', 0); Session::save(); } // check the SilverCart configuration if (!SilvercartTools::isIsolatedEnvironment()) { SilvercartConfig::Check(); } // Delete checkout session data if user is not in the checkout process. if ($this->class != 'SilvercartCheckoutStep' && $this->class != 'SilvercartCheckoutStep_Controller' && $this->class != 'ErrorPage_Controller' && $this->class != 'Security' && $this->class != 'SilvercartFrontPage_Controller' && !$this->class instanceof SilvercartCheckoutStep_Controller && !$this->class instanceof Security && !is_subclass_of($this->class, 'SilvercartCheckoutStep_Controller')) { SilvercartCheckoutStep::deleteSessionStepData(); } // Decorator can use this method to add custom forms and other stuff $this->extend('updateInit'); SilvercartPlugin::call($this, 'init', array($this)); self::$instanceMemorizer[$this->ID] = true; parent::init(); }