/** * Action to add a product to cart. * * @param SS_HTTPRequest $request Request to check for product data * * @return void * * @author Sebastian Diel <*****@*****.**> * @since 12.03.2013 */ public function addToCart(SS_HTTPRequest $request) { $isValidRequest = false; $backLink = null; $postVars = $request->postVars(); $params = $request->allParams(); $productID = $params['ID']; $quantity = $params['OtherID']; if (is_null($productID) || is_null($quantity)) { if (array_key_exists('productID', $postVars) && array_key_exists('productQuantity', $postVars)) { $isValidRequest = true; $productID = $postVars['productID']; $quantity = $postVars['productQuantity']; } } else { $isValidRequest = true; } if ($isValidRequest) { $postVars['productID'] = $productID; $postVars['productQuantity'] = $quantity; if ($quantity == 0) { SilvercartShoppingCart::removeProduct($postVars); } else { SilvercartShoppingCart::addProduct($postVars); } if (SilvercartConfig::getRedirectToCartAfterAddToCartAction()) { $backLink = SilvercartTools::PageByIdentifierCodeLink('SilvercartCartPage'); } } $this->redirectBack($backLink, '#product' . $productID); }
/** * 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)); }
/** * Set initial form values * * @return void * * @author Sascha Koehler <*****@*****.**> * @since 09.11.2010 */ protected function fillInFieldValues() { $this->controller->fillFormFields($this->formFields); $this->formFields['ChosenShippingMethod']['title'] = _t('SilvercartCheckoutFormStep.CHOOSEN_SHIPPING', 'choosen shipping method'); $this->formFields['ChosenPaymentMethod']['title'] = _t('SilvercartCheckoutFormStep.CHOOSEN_PAYMENT', 'choosen payment method'); $this->formFields['HasAcceptedTermsAndConditions']['title'] = sprintf(_t('SilvercartCheckoutFormStep.I_ACCEPT_TERMS'), SilvercartTools::PageByIdentifierCodeLink('TermsOfServicePage')); $this->formFields['HasAcceptedRevocationInstruction']['title'] = sprintf(_t('SilvercartCheckoutFormStep.I_ACCEPT_REVOCATION'), SilvercartTools::PageByIdentifierCodeLink('SilvercartRevocationInstructionPage')); $this->formFields['SubscribedToNewsletter']['title'] = _t('SilvercartCheckoutFormStep.I_SUBSCRIBE_NEWSLETTER', 'I subscribe to the newsletter'); $this->formFields['Note']['placeholder'] = _t('SilvercartPage.YOUR_REMARKS') . '...'; $stepData = $this->controller->getCombinedStepData(); if ($stepData && isset($stepData['ShippingMethod']) && isset($stepData['PaymentMethod'])) { $chosenShippingMethod = DataObject::get_by_id('SilvercartShippingMethod', $stepData['ShippingMethod']); if ($chosenShippingMethod) { $this->formFields['ChosenShippingMethod']['value'] = $chosenShippingMethod->Title; } $chosenPaymentMethod = DataObject::get_by_id('SilvercartPaymentMethod', $stepData['PaymentMethod']); if ($chosenPaymentMethod) { $this->formFields['ChosenPaymentMethod']['value'] = $chosenPaymentMethod->Name; } } }
/** * returns a page link by IdentifierCode * * @param string $identifierCode the DataObjects IdentifierCode * * @return string * * @author Sascha Koehler <*****@*****.**>, Sebastian Diel <*****@*****.**> * @since 21.02.2013 */ public function PageByIdentifierCodeLink($identifierCode = "SilvercartFrontPage") { return SilvercartTools::PageByIdentifierCodeLink($identifierCode); }
/** * Returns a link to trigger the search with this query * * @return string * * @author Sebastian Diel <*****@*****.**> * @since 05.06.2012 */ public function Link() { $searchResultsLink = SilvercartTools::PageByIdentifierCodeLink('SilvercartSearchResultsPage'); return $searchResultsLink . 'SearchByQuery/' . $this->ID; }
/** * Returns the link to send a product question to the shop manager * * @return string * * @author Sebastian Diel <*****@*****.**> * @since 31.05.2012 */ public function ProductQuestionLink() { return SilvercartTools::PageByIdentifierCodeLink('SilvercartContactFormPage') . 'productQuestion/' . $this->ID; }
/** * Action to delete an address. Checks, whether the given address is related * to the logged in customer and deletes it. * * @param SS_HTTPRequest $request The given request * @param string $context specifies the context from the action to adjust redirect behaviour * * @return void * * @author Sebastian Diel <*****@*****.**> * @since 15.11.2014 */ public function deleteAddress(SS_HTTPRequest $request, $context = '') { $params = $request->allParams(); if (array_key_exists('ID', $params) && !empty($params['ID'])) { $addressID = (int) $params['ID']; $member = SilvercartCustomer::currentUser(); $membersAddresses = $member->SilvercartAddresses(); $membersAddress = $membersAddresses->find('ID', $addressID); if ($membersAddresses->count() == 1) { // address can't be deleted because it's the only one $this->setErrorMessage(_t('SilvercartAddressHolder.ADDRESS_CANT_BE_DELETED', "Sorry, but you can't delete your only address.")); } elseif ($membersAddress instanceof SilvercartAddress && $membersAddress->exists() && $membersAddress->canDelete()) { // Address contains to logged in user - delete it if ($member->SilvercartInvoiceAddress()->ID == $addressID) { // set shipping address as users invoice address $member->SilvercartInvoiceAddressID = $member->SilvercartShippingAddress()->ID; $member->write(); } if ($member->SilvercartShippingAddress()->ID == $addressID) { // set invoice address as users shipping address $member->SilvercartShippingAddressID = $member->SilvercartInvoiceAddress()->ID; $member->write(); } $membersAddress->delete(); $this->setSuccessMessage(_t('SilvercartAddressHolder.ADDRESS_SUCCESSFULLY_DELETED', 'Your address was successfully deleted.')); } else { // possible break in attempt! $this->setErrorMessage(_t('SilvercartAddressHolder.ADDRESS_NOT_FOUND', 'Sorry, but the given address was not found.')); } } if (!empty($context)) { $this->redirectBack(); } else { $this->redirect(SilvercartTools::PageByIdentifierCodeLink('SilvercartAddressHolder')); } }