/** * constructor * * @param Controller $controller the controller object * @param array $params additional parameters * @param array $preferences array with preferences * @param bool $barebone is the form initialized completely? * * @return void * * @author Sebastian Diel <*****@*****.**>, * Sascha Koehler <*****@*****.**> * @since 15.11.2014 */ public function __construct($controller, $params = null, $preferences = null, $barebone = false) { $member = SilvercartCustomer::currentUser(); $checkoutData = $controller->getCombinedStepData(); if (!$this->payment && $member) { if (array_key_exists('PaymentMethod', $checkoutData)) { $this->paymentMethodObj = DataObject::get_by_id('SilvercartPaymentMethod', $checkoutData['PaymentMethod']); if ($this->paymentMethodObj) { $this->paymentMethodObj->setController($controller); $this->paymentMethodObj->setCancelLink(Director::absoluteURL($controller->Link()) . 'GotoStep/2'); $this->paymentMethodObj->setReturnLink(Director::absoluteURL($controller->Link())); $this->paymentMethodObj->setCustomerDetailsByCheckoutData($checkoutData); $this->paymentMethodObj->setInvoiceAddressByCheckoutData($checkoutData); $this->paymentMethodObj->setShippingAddressByCheckoutData($checkoutData); $this->paymentMethodObj->setShoppingCart($member->getCart()); } } } parent::__construct($controller, $params, $preferences, $barebone); if (!$barebone) { /* * redirect a user if his cart is empty and no order exists */ $checkoutData = $this->controller->getCombinedStepData(); if (!SilvercartCustomer::currentUser() || !SilvercartCustomer::currentUser()->getCart()->isFilled() && !array_key_exists('orderId', $checkoutData)) { $frontPage = SilvercartPage_Controller::PageByIdentifierCode(); $this->getController()->redirect($frontPage->RelativeLink()); } } }
/** * Initialise the shopping cart. * * @return void * * @author Sebastian Diel <*****@*****.**>, * Sascha Koehler <*****@*****.**> * @since 15.11.2014 */ public function init() { if (SilvercartCustomer::currentUser() && SilvercartCustomer::currentUser()->SilvercartShoppingCartID > 0) { SilvercartCustomer::currentUser()->getCart(); } parent::init(); if (SilvercartCustomer::currentUser() && SilvercartCustomer::currentUser()->getCart()->exists() && SilvercartCustomer::currentUser()->getCart()->SilvercartShoppingCartPositions()->count() > 0 && SilvercartConfig::RedirectToCheckoutWhenInCart()) { $this->redirect(SilvercartTools::PageByIdentifierCode('SilvercartCheckoutStep')->Link()); } }
/** * Provide additional information if availabel * * @return string * * @author Sebastian Diel <*****@*****.**>, * Sascha Koehler <*****@*****.**> * @since 15.11.2014 */ public function AdditionalInformation() { $member = SilvercartCustomer::currentUser(); $text = ''; if ($member) { if (!empty($member->OptInTempText)) { $text = $member->OptInTempText; } } return $text; }
/** * executed if there are no valdation errors on submit * Form data is saved in session * * @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) { 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->delete(); $backLinkPage = DataObject::get_by_id('SiteTree', $formData['BlID']); $this->controller->redirect($backLinkPage->Link()); } } }
/** * constructor * * @param Controller $controller the controller object * @param array $params additional parameters * @param array $preferences array with preferences * @param bool $barebone is the form initialized completely? * * @return void * * @author Sebastian Diel <*****@*****.**> * Sascha Koehler <*****@*****.**> * @since 15.11.2014 */ public function __construct($controller, $params = null, $preferences = null, $barebone = false) { parent::__construct($controller, $params, $preferences, $barebone); if (!$barebone) { /* * redirect a user if his cart is empty and no order exists */ $checkoutData = $this->controller->getCombinedStepData(); if (!SilvercartCustomer::currentUser() || !SilvercartCustomer::currentUser()->getCart()->isFilled() && !array_key_exists('orderId', $checkoutData)) { $frontPage = SilvercartPage_Controller::PageByIdentifierCode(); $this->getController()->redirect($frontPage->RelativeLink()); } } }
/** * 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()); } } } }
/** * Returns the form fields * * @param bool $withUpdate Execute update method of decorators? * * @return array * * @author Sebastian Diel <*****@*****.**> * @since 15.11.2014 */ public function getFormFields($withUpdate = true) { if (empty($this->formFields)) { if (Member::currentUserID() > 0) { $member = SilvercartCustomer::currentUser(); } else { $member = singleton('Member'); } $address = singleton('SilvercartAddress'); $this->formFields = array('Salutation' => array('type' => 'DropdownField', 'title' => $address->fieldLabel('Salutation'), 'selectedValue' => $member->Salutation, 'value' => array('' => _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE'), "Frau" => _t('SilvercartAddress.MISSES'), "Herr" => _t('SilvercartAddress.MISTER')), 'checkRequirements' => array('isFilledIn' => true)), 'FirstName' => array('type' => 'TextField', 'title' => $address->fieldLabel('FirstName'), 'value' => $member->FirstName, 'checkRequirements' => array('isFilledIn' => true, 'hasMinLength' => 3)), 'Surname' => array('type' => 'TextField', 'title' => $address->fieldLabel('Surname'), 'value' => $member->Surname, 'checkRequirements' => array('isFilledIn' => true, 'hasMinLength' => 3)), 'Email' => array('type' => 'TextField', 'title' => $member->fieldLabel('Email'), 'value' => $member->Email, 'checkRequirements' => array('isFilledIn' => true, 'isEmailAddress' => true)), 'Message' => array('type' => 'TextareaField', 'title' => _t('SilvercartPage.MESSAGE', 'message'), 'checkRequirements' => array('isFilledIn' => true, 'hasMinLength' => 3))); if ($this->EnableStreet()) { $requirements = array(); if ($this->StreetIsRequired()) { $requirements = array('isFilledIn' => true); } $this->formFields = array_merge($this->formFields, array('Street' => array('type' => 'TextField', 'title' => $address->fieldLabel('Street') . ' / ' . $address->fieldLabel('StreetNumber'), 'checkRequirements' => $requirements), 'StreetNumber' => array('type' => 'TextField', 'title' => $address->fieldLabel('StreetNumber'), 'checkRequirements' => $requirements))); } if ($this->EnableCity()) { $requirements = array(); if ($this->CityIsRequired()) { $requirements = array('isFilledIn' => true); } $this->formFields = array_merge($this->formFields, array('Postcode' => array('type' => 'TextField', 'title' => $address->fieldLabel('Postcode'), 'checkRequirements' => $requirements), 'City' => array('type' => 'TextField', 'title' => $address->fieldLabel('Postcode') . ' - ' . $address->fieldLabel('City'), 'checkRequirements' => $requirements))); } if ($this->EnableCountry()) { $requirements = array(); if ($this->CountryIsRequired()) { $requirements = array('isFilledIn' => true); } $this->formFields = array_merge($this->formFields, array('SilvercartCountryID' => array('type' => 'DropdownField', 'title' => $address->fieldLabel('SilvercartCountry'), 'value' => SilvercartCountry::getPrioritiveDropdownMap(true, _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE')), 'checkRequirements' => $requirements))); } if ($this->EnablePhoneNumber()) { $requirements = array(); if ($this->PhoneNumberIsRequired()) { $requirements = array('isFilledIn' => true); } $this->formFields = array_merge($this->formFields, array('Phone' => array('type' => 'TextField', 'title' => $address->fieldLabel('Phone'), 'checkRequirements' => $requirements))); } } return parent::getFormFields($withUpdate); }
/** * init * * @param Controller $controller the controller object * @param array $params additional parameters * @param array $preferences array with preferences * @param bool $barebone is the form initialized completely? * * @return void * * @author Sebastian Diel <*****@*****.**>, * Sascha Koehler <*****@*****.**> * @since 15.11.2014 */ public function __construct($controller, $params = null, $preferences = null, $barebone = false) { parent::__construct($controller, $params, $preferences, $barebone); if (!$barebone) { /* * redirect a user if his cart is empty and no order exists */ $checkoutData = $this->controller->getCombinedStepData(); if (!SilvercartCustomer::currentUser() || !SilvercartCustomer::currentUser()->getCart()->isFilled() && !array_key_exists('orderId', $checkoutData)) { $frontPage = SilvercartPage_Controller::PageByIdentifierCode(); $this->getController()->redirect($frontPage->RelativeLink()); } if ($this->isCustomerLoggedIn()) { $this->registerCustomHtmlForm('SilvercartCheckoutFormStep2Regular', new SilvercartCheckoutFormStep2Regular($this->controller)); Session::set("redirect", $this->controller->Link()); $this->registerCustomHtmlForm('SilvercartAddAddressForm', new SilvercartAddAddressForm($this->controller)); } else { $this->registerCustomHtmlForm('SilvercartCheckoutFormStep2Anonymous', new SilvercartCheckoutFormStep2Anonymous($this->controller)); } } }
/** * constructor. Set alternative form action here. * * @param Controller $controller the controller object * @param array $params additional parameters * @param array $preferences array with preferences * @param bool $barebone is the form initialized completely? * * @return void * * @author Sebastian Diel <*****@*****.**> * @since 15.11.2014 */ public function __construct($controller, $params = null, $preferences = null, $barebone = false) { $member = SilvercartCustomer::currentUser(); $checkoutData = $controller->getCombinedStepData(); if ($member && is_array($params) && array_key_exists('PaymentMethod', $params)) { $paymentMethod = DataObject::get_by_id('SilvercartPaymentMethod', $params['PaymentMethod']); if ($paymentMethod) { $paymentMethod->setController($controller); $paymentMethod->setCancelLink(Director::absoluteURL($controller->Link()) . 'GotoStep/2'); $paymentMethod->setReturnLink(Director::absoluteURL($controller->Link())); $paymentMethod->setCustomerDetailsByCheckoutData($checkoutData); $paymentMethod->setInvoiceAddressByCheckoutData($checkoutData); $paymentMethod->setShippingAddressByCheckoutData($checkoutData); if (array_key_exists('ShippingMethod', $checkoutData)) { $member->getCart()->setShippingMethodID($checkoutData['ShippingMethod']); } $paymentMethod->setShoppingCart($member->getCart()); $this->setPaymentMethod($paymentMethod); } } parent::__construct($controller, $params, $preferences, $barebone); }
/** * Is this product buyable with the given stock management settings? * If Stock management is deactivated true is returned. * If stock management is activated but the quantity is overbookable true is * returned. * * @return boolean Can this product be bought due to stock management * settings and the customers cart? * * @author Sebastian Diel <*****@*****.**>, * Roland Lehmann <*****@*****.**> * @since 15.11.2014 */ public function isBuyableDueToStockManagementSettings() { //is the product already in the cart? $cartPositionQuantity = 0; if (SilvercartCustomer::currentUser() && SilvercartCustomer::currentUser()->getCart()) { $cartPositionQuantity = SilvercartCustomer::currentUser()->getCart()->getQuantity($this->ID); } if (SilvercartConfig::EnableStockManagement()) { if (!$this->isStockQuantityOverbookable() && $this->StockQuantity - $cartPositionQuantity <= 0) { return false; } if ($this->StockQuantityExpirationDate) { $curDate = new DateTime(); $expirationDate = new DateTime(strftime($this->StockQuantityExpirationDate)); if ($this->isStockQuantityOverbookable() && $this->StockQuantity - $cartPositionQuantity <= 0 && $expirationDate < $curDate) { return false; } } } return true; }
/** * set the email for this order * * @param string $email the email address of the customer * * @return void */ public function setCustomerEmail($email = null) { $member = SilvercartCustomer::currentUser(); if ($member instanceof Member && $member->Email) { $email = $member->Email; } $this->CustomersEmail = $email; }
/** * Checks, whether this is an invoice address. * * @return bool * * @author Sebastian Diel <*****@*****.**>, * Ramon Kupper <*****@*****.**> * @since 23.02.2016 */ public function isShippingAddress() { $isShippingAddress = false; if ($this->ID == SilvercartCustomer::currentUser()->SilvercartShippingAddressID || $this->isAnonymousShippingAddress()) { $isShippingAddress = true; } else { if (Controller::curr() instanceof SilvercartCheckoutStep_Controller) { $checkoutData = Controller::curr()->getCombinedStepData(); if (array_key_exists('ShippingAddress', $checkoutData) && is_numeric($this->ID) && $this->ID > 0 && $this->ID === $checkoutData['ShippingAddress']) { $isShippingAddress = true; } } } return $isShippingAddress; }
/** * Returns the number of products per page according to where it is set. * Highest priority has the customer's configuration setting if available. * Next comes the shop owners setting for this page; if that's not * configured we use the global setting from SilvercartConfig. * * @return int */ public function getProductsPerPageSetting() { $productsPerPage = 0; $member = SilvercartCustomer::currentUser(); if ($member && $member->getSilvercartCustomerConfig() && $member->getSilvercartCustomerConfig()->productsPerPage !== null) { $productsPerPage = $member->getSilvercartCustomerConfig()->productsPerPage; if ($productsPerPage == 0) { $productsPerPage = SilvercartConfig::getProductsPerPageUnlimitedNumber(); } } else { if ($this->productsPerPage) { $productsPerPage = $this->productsPerPage; } else { $productsPerPage = SilvercartConfig::ProductsPerPage(); } } return $productsPerPage; }
/** * Returns the allowed payment methods. * * @return ArrayList|Boolean */ public function getAllowedPaymentMethods() { if (is_null($this->allowedPaymentMethods)) { $allowedPaymentMethods = new ArrayList(); $stepData = $this->controller->getCombinedStepData(); if (SilvercartCustomer::currentUser() instanceof Member && is_array($stepData) && array_key_exists('Shipping_Country', $stepData) && $stepData['Shipping_Country'] != "") { $shippingCountry = DataObject::get_by_id('SilvercartCountry', $stepData['Shipping_Country']); if ($shippingCountry instanceof SilvercartCountry) { $allowedPaymentMethods = SilvercartPaymentMethod::getAllowedPaymentMethodsFor($shippingCountry, SilvercartCustomer::currentUser()->getCart()); if (!$allowedPaymentMethods instanceof ArrayList) { $allowedPaymentMethods = new ArrayList(); } } } $this->setAllowedPaymentMethods($allowedPaymentMethods); } return $this->allowedPaymentMethods; }
/** * Creates the cache key for this widget. * * @param SilvercartWidget_Controller $widget Widget to get cache key for * * @return string * * @author Sebastian Diel <*****@*****.**> * @since 15.11.2014 */ public static function ProductWidgetCacheKey($widget) { $key = ''; if ($widget->Elements() instanceof SS_List && $widget->Elements()->exists()) { $map = $widget->Elements()->map('ID', 'LastEditedForCache'); if ($map instanceof SS_Map) { $productMap = $map->toArray(); } else { $productMap = $map; } if (!is_array($productMap)) { $productMap = array(); } if ($widget->Elements()->exists() && (empty($productMap) || count($productMap) == 1 && array_key_exists('', $productMap))) { $productMap = array(); foreach ($widget->Elements() as $page) { $map = $page->Elements->map('ID', 'LastEditedForCache'); if ($map instanceof SS_Map) { $productMapToAdd = $map->toArray(); } else { $productMapToAdd = $map; } $productMap = array_merge($productMap, $productMapToAdd); } } $productMapIDs = implode('_', array_keys($productMap)); sort($productMap); $productMapLastEdited = array_pop($productMap); $groupIDs = ''; if (Member::currentUserID() > 0) { $groupIDs = implode('-', SilvercartCustomer::currentUser()->getGroupIDs()); } $keyParts = array(i18n::get_locale(), $productMapIDs, $productMapLastEdited, $widget->LastEdited, $groupIDs); $key = implode('_', $keyParts); } return $key; }
/** * Returns the current customer. * * @return Member */ public function getCustomer() { return SilvercartCustomer::currentUser(); }
/** * determine the tax rate. This method can be extended via DataExtension * to implement project specific behavior. * * @param bool $ignoreTaxExemption Determines whether to ignore tax exemption or not. * * @return float the tax rate in percent * * @author Roland Lehmann <*****@*****.**>, * Sebastian Diel <*****@*****.**> * @since 15.11.2014 */ public function getTaxRate($ignoreTaxExemption = false) { $overwritten = $this->extend('getTaxRate'); if (empty($overwritten)) { $member = SilvercartCustomer::currentUser(); if (!$ignoreTaxExemption && $member instanceof Member && $member->doesNotHaveToPayTaxes()) { $rate = 0; } else { $rate = $this->Rate; } } else { $rate = $overwritten[0]; } return $rate; }
/** * Returns the payment step number. * * @return int */ public function getLastStepNumber() { $stepNumber = 5; if (SilvercartCustomer::currentUser()->isRegisteredCustomer()) { $stepNumber = 4; } return $stepNumber; }
/** * No validation errors occured, so we register the customer and send * mails with further instructions for the double opt-in procedure. * * @param SS_HTTPRequest $data SS session data * @param Form $form the form object * @param array $formData CustomHTMLForms session data * @param bool $doRedirect Set to true to redirect after submitSuccess * * @return void * * @author Sebastian Diel <*****@*****.**>, * Roland Lehmann <*****@*****.**>, * Sascha Koehler <*****@*****.**> * @since 28.01.2015 */ protected function submitSuccess($data, $form, $formData, $doRedirect = true) { $anonymousCustomer = false; /* * Logout anonymous users and save their shoppingcart temporarily. */ if (SilvercartCustomer::currentUser()) { $anonymousCustomer = SilvercartCustomer::currentUser(); SilvercartCustomer::currentUser()->logOut(); } // Aggregate Data and set defaults $formData['MemberID'] = Member::currentUserID(); $formData['Locale'] = Translatable::get_current_locale(); if ($this->demandBirthdayDate()) { $formData['Birthday'] = $formData['BirthdayYear'] . '-' . $formData['BirthdayMonth'] . '-' . $formData['BirthdayDay']; if ($this->UseMinimumAgeToOrder()) { if (!SilvercartConfig::CheckMinimumAgeToOrder($formData['Birthday'])) { $this->errorMessages['BirthdayDay'] = array('message' => SilvercartConfig::MinimumAgeToOrderError(), 'fieldname' => _t('SilvercartPage.BIRTHDAY'), 'BirthdayDay' => array('message' => SilvercartConfig::MinimumAgeToOrderError())); $this->errorMessages['BirthdayMonth'] = array('message' => SilvercartConfig::MinimumAgeToOrderError(), 'fieldname' => _t('SilvercartPage.BIRTHDAY'), 'BirthdayMonth' => array('message' => SilvercartConfig::MinimumAgeToOrderError())); $this->errorMessages['BirthdayYear'] = array('message' => SilvercartConfig::MinimumAgeToOrderError(), 'fieldname' => _t('SilvercartPage.BIRTHDAY'), 'BirthdayYear' => array('message' => SilvercartConfig::MinimumAgeToOrderError())); $this->setSubmitSuccess(false); return $this->submitFailure($data, $form); } } } // Create new regular customer and perform a log in $customer = new Member(); // Pass shoppingcart to registered customer and delete the anonymous // customer. if ($anonymousCustomer) { $newShoppingCart = $anonymousCustomer->getCart()->duplicate(true); foreach ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions() as $shoppingCartPosition) { $newShoppingCartPosition = $shoppingCartPosition->duplicate(false); $newShoppingCartPosition->SilvercartShoppingCartID = $newShoppingCart->ID; $newShoppingCartPosition->write(); $shoppingCartPosition->transferToNewPosition($newShoppingCartPosition); } $customer->SilvercartShoppingCartID = $newShoppingCart->ID; $anonymousCustomer->delete(); } $customer->castedUpdate($formData); $customer->write(); $customer->logIn(); $customer->changePassword($formData['Password']); $customerGroup = $this->getTargetCustomerGroup($formData); if ($customerGroup) { $customer->Groups()->add($customerGroup); } // Create ShippingAddress for customer and populate it with registration data $address = new SilvercartAddress(); $address->castedUpdate($formData); $country = DataObject::get_by_id('SilvercartCountry', (int) $formData['Country']); if ($country) { $address->SilvercartCountryID = $country->ID; } $address->write(); $this->extend('updateRegisteredAddress', $address, $data, $form, $formData); //connect the ShippingAddress and the InvoiceAddress to the customer $customer->SilvercartShippingAddressID = $address->ID; $customer->SilvercartInvoiceAddressID = $address->ID; $customer->SilvercartAddresses()->add($address); $customer->write(); // Remove from the anonymous newsletter recipients list if (SilvercartAnonymousNewsletterRecipient::doesExist($customer->Email)) { $recipient = SilvercartAnonymousNewsletterRecipient::getByEmailAddress($customer->Email); if ($recipient->NewsletterOptInStatus) { $customer->NewsletterOptInStatus = 1; $customer->NewsletterConfirmationHash = $recipient->NewsletterOptInConfirmationHash; $customer->write(); } SilvercartAnonymousNewsletterRecipient::removeByEmailAddress($customer->Email); } if ($customer->SubscribedToNewsletter && !$customer->NewsletterOptInStatus) { SilvercartNewsletter::subscribeRegisteredCustomer($customer); } $this->extend('updateRegisteredCustomer', $customer, $data, $form, $formData); if ($doRedirect) { // Redirect to welcome page if (array_key_exists('backlink', $formData) && !empty($formData['backlink'])) { $this->controller->redirect($formData['backlink']); } else { $this->controller->redirect($this->controller->PageByIdentifierCode('SilvercartRegisterConfirmationPage')->Link()); } } }
/** * We save the chosen value for the products per page in the customer's * configuration object here and redirect to the last view. * * @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 <*****@*****.**>, * Sascha Koehler <*****@*****.**> * @since 15.11.2014 */ public function submitSuccess($data, $form, $formData) { $backLink = $this->controller->Link(); $member = SilvercartCustomer::currentUser(); $product = singleton('SilvercartProduct'); $sortableFrontendFields = $product->sortableFrontendFields(); $sortableFrontendFieldValues = array_keys($sortableFrontendFields); $sortOrder = $sortableFrontendFieldValues[$data['SortOrder']]; SilvercartProduct::setDefaultSort($sortOrder); if (!$member) { $member = SilvercartCustomer::createAnonymousCustomer(); } if ($member) { $member->getSilvercartCustomerConfig()->productsPerPage = $data['productsPerPage']; $member->getSilvercartCustomerConfig()->write(); } if (isset($formData['backLink'])) { $backLink = $formData['backLink']; } $this->controller->redirect($backLink, 302); }
/** * 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; }
/** * Returns the prices amount * * @param bool $plain Set to true to load the price amount without any manipulation * @param float $amountToGetFeeFor Amount to get fee for * @param SilvercartCountry $countryToGetFeeFor Amount to get fee for * * @return float * * @author Sebastian Diel <*****@*****.**>, * Sascha Koehler <*****@*****.**> * @since 15.11.2014 */ public function getPriceAmount($plain = false, $amountToGetFeeFor = null, $countryToGetFeeFor = null) { $price = (double) $this->Price->getAmount(); if (!$plain) { if (SilvercartConfig::PriceType() == 'net') { $price = $price - $this->getTaxAmount($price); } if (SilvercartCustomer::currentUser() && SilvercartCustomer::currentUser()->SilvercartShoppingCartID > 0) { $silvercartShoppingCart = SilvercartCustomer::currentUser()->getCart(); $shoppingCartValue = $silvercartShoppingCart->getTaxableAmountWithoutFees(); if (is_null($amountToGetFeeFor)) { $amountToGetFeeFor = $shoppingCartValue->getAmount(); } if (is_null($countryToGetFeeFor)) { $countryToGetFeeFor = $this->SilvercartShippingMethod()->getShippingCountry(); } if ($this->ShippingIsFree($amountToGetFeeFor, $countryToGetFeeFor)) { $price = 0.0; } } $price = round($price, 2); $this->extend('updatePriceAmount', $price); } elseif (!is_null($amountToGetFeeFor) && !is_null($countryToGetFeeFor) && $this->ShippingIsFree($amountToGetFeeFor, $countryToGetFeeFor)) { $price = 0.0; } return $price; }
/** * Disable editing for all Member types. * * @param Member $member Member, defined for compatibility with parent * * @return bool * * @author Sebastian Diel <*****@*****.**> * @since 15.11.2014 */ public function canEdit($member = null) { if ($member === null) { $member = SilvercartCustomer::currentUser(); } if ($member && $member->inGroup('administrators')) { return true; } return false; }
/** * Returns the current shipping country * * @return SilvercartCountry * * @author Sebastian Diel <*****@*****.**> * @since 15.11.2014 */ public function ShippingCountry() { $customer = SilvercartCustomer::currentUser(); $shippingCountry = null; if ($customer) { $shippingCountry = $customer->SilvercartShippingAddress()->SilvercartCountry(); } if (is_null($shippingCountry) || $shippingCountry->ID == 0) { $shippingCountry = SilvercartCountry::get()->filter(array('ISO2' => substr(Translatable::get_current_locale(), 3), 'Active' => 1))->first(); } return $shippingCountry; }
/** * Returns the context address. * * @return SilvercartAddress */ public function getAddress() { $member = SilvercartCustomer::currentUser(); $id = $this->customParameters['addressID']; if ($member && $id) { $filter = array("MemberID" => $member->ID, "ID" => $id); $this->address = SilvercartAddress::get()->filter($filter)->first(); } return $this->address; }
/** * Action to set an address as shipping address. * * @param SS_HTTPRequest $request The given request * * @return void */ public function setShippingAddress(SS_HTTPRequest $request) { $params = $request->allParams(); if (array_key_exists('ID', $params) && !empty($params['ID'])) { $addressID = (int) $params['ID']; $membersAddresses = SilvercartCustomer::currentUser()->SilvercartAddresses(); $membersAddress = $membersAddresses->find('ID', $addressID); if ($membersAddress instanceof SilvercartAddress && $membersAddress->exists()) { // Address contains to logged in user - set as invoice address $member = SilvercartCustomer::currentUser(); $member->SilvercartShippingAddressID = $addressID; $member->write(); $this->setSuccessMessage(_t('SilvercartAddressHolder.UPDATED_SHIPPING_ADDRESS', 'Your shipping addres was successfully updated.')); } else { // possible break in attempt! $this->setErrorMessage(_t('SilvercartAddressHolder.ADDRESS_NOT_FOUND', 'Sorry, but the given address was not found.')); } } $this->redirectBack(); }
/** * chpppopt stands for "CHange Products Per Page Option". * Changes the quantity of products to display in a product lists. * * @param SS_HTTPRequest $request Request * * @return string * * @author Sebastian Diel <*****@*****.**> * @since 27.11.2014 */ public function chpppopt(SS_HTTPRequest $request) { $member = SilvercartCustomer::currentUser(); $newOption = $request->param('ID'); $product = singleton('SilvercartProduct'); $sortableFrontendFields = $product->sortableFrontendFields(); $sortableFrontendFieldValues = array_keys($sortableFrontendFields); if (array_key_exists($newOption, $sortableFrontendFieldValues)) { $sortOrder = $sortableFrontendFieldValues[$newOption]; SilvercartProduct::setDefaultSort($sortOrder); } if ($member instanceof Member && $member->exists()) { $member->getSilvercartCustomerConfig()->productsPerPage = $newOption; $member->getSilvercartCustomerConfig()->write(); } self::setProductsPerPage($newOption); $this->redirect($this->Link()); }
/** * Returns allowed payment methods. * * @param string $shippingCountry The SilvercartCountry to check the payment methods for. * @param SilvercartShoppingCart $shoppingCart The shopping cart object * @param Boolean $forceAnonymousCustomerIfNotExist When true, an anonymous customer will be created when no customer exists * * @return ArrayList * * @author Sebastian Diel <*****@*****.**>, * Sascha Koehler <*****@*****.**> * @since 15.11.2014 */ public static function getAllowedPaymentMethodsFor($shippingCountry, $shoppingCart, $forceAnonymousCustomerIfNotExist = false) { $allowedPaymentMethods = array(); if (!$shippingCountry) { return $allowedPaymentMethods; } $paymentMethods = $shippingCountry->SilvercartPaymentMethods('isActive = 1'); $member = SilvercartCustomer::currentUser(); if (!$member && $forceAnonymousCustomerIfNotExist) { $member = new Member(); $anonymousGroup = Group::get()->filter('Code', 'anonymous')->first(); $memberGroups = new ArrayList(); $memberGroups->push($anonymousGroup); } else { $memberGroups = $member->Groups(); } $shippingMethodID = null; if (Controller::curr() instanceof SilvercartCheckoutStep_Controller) { $checkoutData = Controller::curr()->getCombinedStepData(); if (array_key_exists('ShippingMethod', $checkoutData)) { $shippingMethodID = $checkoutData['ShippingMethod']; } } if ($paymentMethods) { foreach ($paymentMethods as $paymentMethod) { $assumePaymentMethod = true; $containedInGroup = false; $containedInUsers = false; $doAccessChecks = true; // ------------------------------------------------------------ // Basic checks // ------------------------------------------------------------ if ($paymentMethod->enableActivationByOrderRestrictions) { $assumePaymentMethod = $paymentMethod->isActivationByOrderRestrictionsPossible($member); $doAccessChecks = false; } $checkAmount = $shoppingCart->getAmountTotalWithoutFees()->getAmount(); if (!$paymentMethod->isAvailableForAmount($checkAmount)) { $assumePaymentMethod = false; $doAccessChecks = false; } // ------------------------------------------------------------ // Shipping method check // ------------------------------------------------------------ if (!is_null($shippingMethodID) && $paymentMethod->SilvercartShippingMethods()->exists() && !$paymentMethod->SilvercartShippingMethods()->find('ID', $shippingMethodID)) { $assumePaymentMethod = false; $doAccessChecks = false; } // ------------------------------------------------------------ // Access checks // ------------------------------------------------------------ if ($doAccessChecks) { // Check if access for groups or is set positively if ($paymentMethod->ShowOnlyForGroups()->exists()) { foreach ($paymentMethod->ShowOnlyForGroups() as $paymentGroup) { if ($memberGroups->find('ID', $paymentGroup->ID)) { $containedInGroup = true; break; } } if ($containedInGroup) { $assumePaymentMethod = true; } else { $assumePaymentMethod = false; } } // Check if access for users or is set positively if ($paymentMethod->ShowOnlyForUsers()->exists()) { if ($paymentMethod->ShowOnlyForUsers()->find('ID', $member->ID)) { $containedInUsers = true; } if ($containedInUsers) { $assumePaymentMethod = true; } else { if (!$containedInGroup) { $assumePaymentMethod = false; } } } // Check if access for groups is set negatively if ($paymentMethod->ShowNotForGroups()->exists()) { foreach ($paymentMethod->ShowNotForGroups() as $paymentGroup) { if ($memberGroups->find('ID', $paymentGroup->ID)) { if (!$containedInUsers) { $assumePaymentMethod = false; } } } } // Check if access for users is set negatively if ($paymentMethod->ShowNotForUsers()->exists()) { if ($paymentMethod->ShowNotForUsers()->find('ID', $member->ID)) { if (!$containedInUsers) { $assumePaymentMethod = false; } } } } if ($assumePaymentMethod) { $allowedPaymentMethods[] = $paymentMethod; } } } $allowedPaymentMethods = new ArrayList($allowedPaymentMethods); return $allowedPaymentMethods; }
/** * Returns the current shopping cart. * * @return SilvercartShoppingCart * * @author Sebastian Diel <*****@*****.**> * @since 15.11.2014 */ public function SilvercartShoppingCart() { $member = SilvercartCustomer::currentUser(); if ($member) { return $member->getCart(); } }
/** * Returns all registered modules. * * Every module contains two keys for further iteration inside templates: * - ShoppingCartPositions * - ShoppingCartActions * * @return DataList * * @author Sebastian Diel <*****@*****.**>, * Sascha Koehler <*****@*****.**> * @since 09.04.2014 */ public function registeredModules() { if (is_null($this->registeredModulesSet)) { $customer = SilvercartCustomer::currentUser(); $modules = array(); $registeredModules = self::$registeredModules; $hookMethods = array('NonTaxableShoppingCartPositions', 'TaxableShoppingCartPositions', 'IncludedInTotalShoppingCartPositions', 'ShoppingCartActions', 'ShoppingCartTotal', 'CustomShoppingCartPositions'); foreach ($registeredModules as $registeredModule) { $registeredModuleObjPlain = new $registeredModule(); $registeredModuleObj = false; if ($registeredModuleObjPlain->hasMethod('loadObjectForShoppingCart')) { $registeredModuleObj = $registeredModuleObjPlain->loadObjectForShoppingCart($this); } if (!$registeredModuleObj) { $registeredModuleObj = $registeredModuleObjPlain; } if ($registeredModuleObj) { $hooks = array(); foreach ($hookMethods as $hookMethod) { if ($registeredModuleObj->hasMethod($hookMethod)) { $hooks[$hookMethod] = $registeredModuleObj->{$hookMethod}($this, $customer); } } $modules[] = $hooks; } } $this->registeredModulesSet = new ArrayList($modules); } return $this->registeredModulesSet; }