/**
  * 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);
 }
 /**
  * Fill the form with default values
  *
  * @return void
  * 
  * @author Sebastian Diel <*****@*****.**>,
  *         Roland Lehmann <*****@*****.**>
  * @since 15.11.2014
  */
 protected function fillInFieldValues()
 {
     $member = SilvercartCustomer::currentUser();
     $id = $this->customParameters['addressID'];
     if ($member && $id) {
         $filter = array("MemberID" => $member->ID, "ID" => $id);
         $this->address = SilvercartAddress::get()->filter($filter)->first();
         if ($this->address) {
             $this->formFields['Salutation']['selectedValue'] = $this->address->Salutation;
             $this->formFields['AcademicTitle']['value'] = $this->address->AcademicTitle;
             $this->formFields['FirstName']['value'] = $this->address->FirstName;
             $this->formFields['Surname']['value'] = $this->address->Surname;
             $this->formFields['Addition']['value'] = $this->address->Addition;
             $this->formFields['Street']['value'] = $this->address->Street;
             $this->formFields['StreetNumber']['value'] = $this->address->StreetNumber;
             $this->formFields['Postcode']['value'] = $this->address->Postcode;
             $this->formFields['City']['value'] = $this->address->City;
             $this->formFields['PhoneAreaCode']['value'] = $this->address->PhoneAreaCode;
             $this->formFields['Phone']['value'] = $this->address->Phone;
             $this->formFields['Fax']['value'] = $this->address->Fax;
             $this->formFields['Country']['selectedValue'] = $this->address->SilvercartCountry()->ID;
             if (SilvercartConfig::enablePackstation()) {
                 $this->formFields['PostNumber']['value'] = $this->address->PostNumber;
                 $this->formFields['Packstation']['value'] = $this->address->Packstation;
                 $this->formFields['IsPackstation']['selectedValue'] = $this->address->IsPackstation;
             }
             if (SilvercartConfig::enableBusinessCustomers()) {
                 $this->formFields['Company']['value'] = $this->address->Company;
                 $this->formFields['TaxIdNumber']['value'] = $this->address->TaxIdNumber;
             }
         }
     }
 }
 /**
  * Initialisierung
  *
  * @return void
  *
  * @author Sascha Koehler <*****@*****.**>
  * @since 02.12.2010
  */
 public function init()
 {
     if (SilvercartConfig::EnableSSL()) {
         Director::forceSSL();
     }
     parent::init();
 }
Пример #4
0
 /**
  * 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());
     }
 }
 /**
  * Getter for the language object for an object that has translations
  * I impemented it a a static method because it would be redundantly declared
  * in any multilanguage DataObject
  *
  * @param HasManyList $componentset has_many relation to be searched for the right translation
  * @param string      $locale       locale eg. de_DE, en_NZ, ...
  *
  * @return DataObject|false
  * 
  * @author Roland Lehmann <*****@*****.**>
  * @since 03.01.2012
  */
 public static function getLanguage($componentset, $locale = false)
 {
     $lang = false;
     if ($locale == false) {
         $locale = Translatable::get_current_locale();
     }
     if ($componentset->find('Locale', $locale)) {
         $lang = $componentset->find('Locale', $locale);
     } elseif (SilvercartConfig::useDefaultLanguageAsFallback()) {
         if ($componentset->find('Locale', SilvercartConfig::DefaultLanguage())) {
             $lang = $componentset->find('Locale', SilvercartConfig::DefaultLanguage());
         }
     }
     return $lang;
 }
 /**
  * Set the Money value
  *
  * @param mixed $val Value to set
  * 
  * @return void
  */
 public function setValue($val)
 {
     $defaultCurrency = SilvercartConfig::DefaultCurrency();
     if (is_array($val)) {
         if (empty($val['Currency'])) {
             $val['Currency'] = $defaultCurrency;
         }
         if (!empty($val['Amount'])) {
             $val['Amount'] = $this->prepareAmount($val['Amount']);
         }
     } elseif ($val instanceof Money) {
         if ($val->getCurrency() != $defaultCurrency && $this->getCurrencyIsReadonly()) {
             $val->setCurrency($defaultCurrency);
         }
         if ($val->getAmount() != '') {
             $val->setAmount($this->prepareAmount($val->getAmount()));
         }
     }
     parent::setValue($val);
 }
Пример #7
0
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * Return the start value for the limit part of the sql query that
  * retrieves the product group list for the current product group page.
  * 
  * @param int|bool $numberOfProductGroups The number of product groups to return
  *
  * @return int
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 04.07.2011
  */
 public function getSqlOffsetForProductGroups($numberOfProductGroups = false)
 {
     if ($this->productGroupsPerPage) {
         $productGroupsPerPage = $this->productGroupsPerPage;
     } else {
         $productGroupsPerPage = SilvercartConfig::ProductsPerPage();
     }
     if ($numberOfProductGroups !== false) {
         $productGroupsPerPage = (int) $numberOfProductGroups;
     }
     if (!isset($_GET['groupStart']) || !is_numeric($_GET['groupStart']) || (int) $_GET['groupStart'] < 1) {
         if (isset($_GET['groupOffset'])) {
             // --------------------------------------------------------
             // Use offset for getting the current item rage
             // --------------------------------------------------------
             $offset = (int) $_GET['groupOffset'];
             if ($offset > 0) {
                 $offset -= 1;
             }
             // Prevent too high values
             if ($offset > 999999) {
                 $offset = 0;
             }
             $SQL_start = $offset * $productGroupsPerPage;
         } else {
             // --------------------------------------------------------
             // Use item number for getting the current item range
             // --------------------------------------------------------
             $SQL_start = 0;
         }
     } else {
         $SQL_start = (int) $_GET['groupStart'];
     }
     return $SQL_start;
 }
 /**
  * Write a log message.
  * 
  * @param string $logString string to log
  * @param string $filename  filename to log into
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 17.01.2012
  */
 public function Log($logString, $filename = 'importProducts')
 {
     SilvercartConfig::Log('CSV Import', $logString, $filename);
 }
 /**
  * statements to be called on object initialisation
  *
  * @author Roland Lehmann <*****@*****.**>
  * @since 18.11.2010
  * @return void
  */
 public function init()
 {
     if (SilvercartConfig::EnableSSL()) {
         Director::forceSSL();
     }
     Session::clear("redirect");
     //if customer has been to the checkout yet this is set to direct him back to the checkout after address editing
     parent::init();
     $this->registerCustomHtmlForm('SilvercartLoginForm', new SilvercartLoginForm($this));
 }
Пример #12
0
 /**
  * sends email to defined address
  *
  * @param string $identifier  identifier for email template
  * @param string $to          recipients email address
  * @param array  $variables   array with template variables that can be called in the template
  * @param array  $attachments absolute filename to an attachment file
  *
  * @return bool
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 16.06.2014
  */
 public static function send($identifier, $to, $variables = array(), $attachments = null)
 {
     $mailObj = SilvercartShopEmail::get()->filter('Identifier', $identifier)->first();
     if (!$mailObj) {
         return false;
     }
     $emailText = trim($mailObj->EmailText);
     if (is_null($emailText) || empty($emailText)) {
         return false;
     }
     $emailSubject = trim($mailObj->Subject);
     if (is_null($emailSubject) || empty($emailSubject)) {
         return false;
     }
     if (!is_array($variables)) {
         $variables = array();
     }
     $templateVariables = new ArrayData($variables);
     $emailTextTemplate = new SSViewer_FromString($mailObj->EmailText);
     $emailText = HTTP::absoluteURLs($emailTextTemplate->process($templateVariables));
     $emailSubjectTemplate = new SSViewer_FromString($mailObj->Subject);
     $emailSubject = HTTP::absoluteURLs($emailSubjectTemplate->process($templateVariables));
     $email = new Email(SilvercartConfig::EmailSender(), $to, $emailSubject, $mailObj->EmailText);
     $email->setTemplate('SilvercartShopEmail');
     $email->populateTemplate(array('ShopEmailSubject' => $emailSubject, 'ShopEmailMessage' => $emailText));
     self::attachFiles($email, $attachments);
     $email->send();
     if (SilvercartConfig::GlobalEmailRecipient() != '') {
         $email = new Email(SilvercartConfig::EmailSender(), SilvercartConfig::GlobalEmailRecipient(), $emailSubject, $mailObj->EmailText);
         $email->setTemplate('SilvercartShopEmail');
         $email->populateTemplate(array('ShopEmailSubject' => $emailSubject, 'ShopEmailMessage' => $emailText));
         $email->send();
     }
     //Send the email to additional standard receipients from the n:m
     //relation AdditionalReceipients;
     //Email address is validated.
     if ($mailObj->AdditionalReceipients()->exists()) {
         foreach ($mailObj->AdditionalReceipients() as $additionalReceipient) {
             if ($additionalReceipient->getEmailAddressWithName() && Email::validEmailAddress($additionalReceipient->Email)) {
                 $to = $additionalReceipient->getEmailAddressWithName();
             } elseif ($additionalReceipient->getEmailAddress() && Email::validEmailAddress($additionalReceipient->Email)) {
                 $to = $additionalReceipient->getEmailAddress();
             } else {
                 continue;
             }
             $email = new Email(SilvercartConfig::EmailSender(), $to, $emailSubject, $mailObj->EmailText);
             $email->setTemplate('SilvercartShopEmail');
             $email->populateTemplate(array('ShopEmailSubject' => $emailSubject, 'ShopEmailMessage' => $emailText));
             self::attachFiles($email, $attachments);
             $email->send();
         }
     }
 }
 /**
  * Returns whether to skip this step or not.
  * 
  * @return bool
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 11.03.2013
  */
 public function SkipPaymentStep()
 {
     if (is_null($this->skipPaymentStep)) {
         if (SilvercartConfig::SkipPaymentStepIfUnique() && $this->getAllowedPaymentMethods()->Count() == 1) {
             if (($this->getRegisteredNestedForms() instanceof DataList || $this->getRegisteredNestedForms() instanceof ArrayList) && $this->getRegisteredNestedForms()->Count() >= 1 && $this->getRegisteredNestedForms()->First() instanceof SilvercartCheckoutFormStep4DefaultPayment) {
                 $this->skipPaymentStep = false;
             } else {
                 $this->skipPaymentStep = true;
             }
         } elseif (SilvercartConfig::SkipPaymentStepIfUnique() && $this->getActivePaymentMethods()->Count() == 1) {
             if (($this->getRegisteredNestedForms() instanceof DataList || $this->getRegisteredNestedForms() instanceof ArrayList) && $this->getRegisteredNestedForms()->Count() >= 1 && $this->getRegisteredNestedForms()->First() instanceof SilvercartCheckoutFormStep4DefaultPayment) {
                 $this->skipPaymentStep = false;
             } else {
                 $this->skipPaymentStep = true;
             }
         } else {
             $this->skipPaymentStep = false;
         }
     }
     return $this->skipPaymentStep;
 }
 /**
  * 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 <*****@*****.**>
  * @since 16.06.2014
  */
 protected function submitSuccess($data, $form, $formData)
 {
     $formData['RevocationOrderData'] = str_replace('\\r\\n', "\n", $formData['RevocationOrderData']);
     $config = SilvercartConfig::getConfig();
     $country = DataObject::get_by_id('SilvercartCountry', $formData['Country']);
     $variables = array('Email' => $formData['Email'], 'Salutation' => $formData['Salutation'], 'FirstName' => $formData['FirstName'], 'Surname' => $formData['Surname'], 'Street' => $formData['Street'], 'StreetNumber' => $formData['StreetNumber'], 'Addition' => $formData['Addition'], 'Postcode' => $formData['Postcode'], 'City' => $formData['City'], 'Country' => $country, 'OrderDate' => $formData['OrderDate'], 'OrderNumber' => $formData['OrderNumber'], 'RevocationOrderData' => str_replace('\\r\\n', '<br/>', nl2br($formData['RevocationOrderData'])), 'CurrentDate' => $this->getCurrentDate(), 'ShopName' => $config->ShopName, 'ShopStreet' => $config->ShopStreet, 'ShopStreetNumber' => $config->ShopStreetNumber, 'ShopPostcode' => $config->ShopPostcode, 'ShopCity' => $config->ShopCity, 'ShopCountry' => $config->ShopCountry());
     SilvercartShopEmail::send('RevocationNotification', SilvercartConfig::DefaultMailOrderNotificationRecipient(), $variables);
     SilvercartShopEmail::send('RevocationConfirmation', $formData['Email'], $variables);
     $revocationPage = SilvercartRevocationFormPage::get()->first();
     $this->Controller()->redirect($revocationPage->Link('success'));
 }
 /**
  * Returns tax amounts included in the shoppingcart separated by tax rates
  * without fee taxes.
  *
  * @param array $excludeModules              An array of registered modules that shall not
  *                                           be taken into account.
  * @param array $excludeShoppingCartPosition Positions that shall not be counted
  *
  * @return ArrayList
  */
 public function getTaxRatesWithoutFeesAndCharges($excludeModules = array(), $excludeShoppingCartPosition = false)
 {
     $positions = $this->SilvercartShoppingCartPositions();
     $taxes = new ArrayList();
     $registeredModules = $this->callMethodOnRegisteredModules('ShoppingCartPositions', array(SilvercartCustomer::currentUser()->getCart(), SilvercartCustomer::currentUser(), true), $excludeModules, $excludeShoppingCartPosition);
     // products
     foreach ($positions as $position) {
         $taxRate = $position->SilvercartProduct()->getTaxRate();
         $originalTaxRate = $position->SilvercartProduct()->getTaxRate(true);
         if (!$taxes->find('Rate', $taxRate)) {
             $taxes->push(new DataObject(array('Rate' => $taxRate, 'OriginalRate' => $originalTaxRate, 'AmountRaw' => (double) 0.0)));
         }
         $taxSection = $taxes->find('Rate', $taxRate);
         $taxSection->AmountRaw += $position->getTaxAmount();
     }
     // Registered Modules
     foreach ($registeredModules as $moduleName => $moduleOutput) {
         foreach ($moduleOutput as $modulePosition) {
             $taxRate = $modulePosition->TaxRate;
             if (!$taxes->find('Rate', $taxRate)) {
                 $taxes->push(new DataObject(array('Rate' => $taxRate, 'OriginalRate' => $taxRate, 'AmountRaw' => (double) 0.0)));
             }
             $taxSection = $taxes->find('Rate', $taxRate);
             $taxAmount = $modulePosition->TaxAmount;
             $taxSection->AmountRaw = round($taxSection->AmountRaw + $taxAmount, 4);
         }
     }
     foreach ($taxes as $tax) {
         $taxObj = new Money();
         $taxObj->setAmount($tax->AmountRaw);
         $taxObj->setCurrency(SilvercartConfig::DefaultCurrency());
         $tax->Amount = $taxObj;
     }
     return $taxes;
 }
 /**
  * Initializes the step form. Includes forms and requirements.
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 15.11.2014
  */
 public function init()
 {
     $this->preferences['templateDir'] = PIXELTRICKS_CHECKOUT_BASE_PATH_REL . 'templates/Layout/';
     if (SilvercartConfig::EnableSSL()) {
         Director::forceSSL();
     }
     parent::init();
     // Inject payment and shippingmethods to shoppingcart, if available
     $member = SilvercartCustomer::currentUser();
     if ($member) {
         $stepData = $this->getCombinedStepData();
         $shoppingCart = $member->getCart();
         // If minimum order value is set and shoppingcart value is below we
         // have to redirect the customer to the shoppingcart page and set
         // an appropriate error message.
         if ($this->getCurrentStep() < 5 && SilvercartConfig::UseMinimumOrderValue() && SilvercartConfig::MinimumOrderValue() && SilvercartConfig::MinimumOrderValue()->getAmount() > $shoppingCart->getAmountTotalWithoutFees()->getAmount()) {
             $silvercartSessionErrors = Session::get('Silvercart.errors');
             $silvercartSessionErrors[] = sprintf(_t('SilvercartShoppingCart.ERROR_MINIMUMORDERVALUE_NOT_REACHED'), SilvercartConfig::MinimumOrderValue()->Nice());
             Session::set('Silvercart.errors', $silvercartSessionErrors);
             Session::save();
             $this->redirect(SilvercartPage_Controller::PageByIdentifierCode('SilvercartCartPage')->Link());
         }
         if (isset($stepData['ShippingMethod'])) {
             $shoppingCart->setShippingMethodID($stepData['ShippingMethod']);
         }
         if (isset($stepData['PaymentMethod'])) {
             $shoppingCart->setPaymentMethodID($stepData['PaymentMethod']);
         }
         $requestParams = $this->getRequest()->allParams();
         if ($requestParams['Action'] == 'editAddress') {
             $addressID = (int) $requestParams['ID'];
             $membersAddresses = SilvercartCustomer::currentUser()->SilvercartAddresses();
             $membersAddress = $membersAddresses->find('ID', $addressID);
             if ($membersAddress instanceof SilvercartAddress && $membersAddress->exists()) {
                 Session::set("redirect", $this->Link());
                 $preferences = array();
                 $preferences['submitAction'] = 'editAddress/' . $addressID . '/customHtmlFormSubmit';
                 $this->registerCustomHtmlForm('SilvercartEditAddressForm', new SilvercartEditAddressForm($this, array('addressID' => $addressID), $preferences));
             }
         } elseif ($requestParams['Action'] == 'addNewAddress') {
             Session::set("redirect", $this->Link());
             $preferences = array();
             $preferences['submitAction'] = 'addNewAddress/customHtmlFormSubmit';
             $this->registerCustomHtmlForm('SilvercartAddAddressForm', new SilvercartAddAddressForm($this, array(), $preferences));
         }
     }
 }
 /**
  * Returns whether invoice address is always shipping address.
  * 
  * @return bool
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 17.07.2014
  */
 public function InvoiceAddressIsAlwaysShippingAddress()
 {
     return SilvercartConfig::InvoiceAddressIsAlwaysShippingAddress();
 }
 /**
  * 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))));
     }
 }
 /**
  * Preferences
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 03.03.2015
  */
 public function preferences()
 {
     $numberOfDecimalPlaces = false;
     if ($this->getProduct()->isInCart()) {
         $this->preferences['submitButtonTitle'] = _t('SilvercartProduct.CHANGE_QUANTITY_CART');
     } else {
         $this->preferences['submitButtonTitle'] = _t('SilvercartProduct.ADD_TO_CART');
     }
     $this->preferences['doJsValidationScrolling'] = false;
     $this->formFields['productQuantity']['title'] = _t('SilvercartProduct.QUANTITY');
     $backLink = Controller::curr()->getRequest()->getURL();
     if (Director::is_relative_url($backLink)) {
         $backLink = Director::absoluteURL($backLink, true);
     }
     $this->setCustomParameter('backLink', $backLink);
     // Get maxlength for quantity field
     $quantityFieldMaxLength = strlen((string) SilvercartConfig::addToCartMaxQuantity());
     if ($quantityFieldMaxLength == 0) {
         $quantityFieldMaxLength = 1;
     }
     if (array_key_exists('productID', $this->customParameters)) {
         $silvercartProduct = $this->getProduct();
         if ($silvercartProduct instanceof SilvercartProduct) {
             $numberOfDecimalPlaces = $silvercartProduct->SilvercartQuantityUnit()->numberOfDecimalPlaces;
         }
     }
     if ($numberOfDecimalPlaces !== false && $numberOfDecimalPlaces > 0) {
         if (array_key_exists('isNumbersOnly', $this->formFields['productQuantity']['checkRequirements'])) {
             unset($this->formFields['productQuantity']['checkRequirements']['isNumbersOnly']);
         }
         $this->formFields['productQuantity']['checkRequirements']['isDecimalNumber'] = $numberOfDecimalPlaces;
         $this->formFields['productQuantity']['maxLength'] = $quantityFieldMaxLength + 1 + $numberOfDecimalPlaces;
     } else {
         $this->formFields['productQuantity']['maxLength'] = $quantityFieldMaxLength;
     }
     parent::preferences();
 }
 /**
  * Returns the maximum weights unit abreviation in context of
  * SilvercartConfig::DisplayWeightsInKilogram().
  * 
  * @return string
  */
 public function getMaximumWeightUnitAbreviation()
 {
     $maximumWeightUnitAbreviation = 'g';
     if (SilvercartConfig::DisplayWeightsInKilogram()) {
         $maximumWeightUnitAbreviation = 'kg';
     }
     return $maximumWeightUnitAbreviation;
 }
 /**
  * Returns the prices amount
  *
  * @return float
  */
 public function getPriceAmount()
 {
     $price = (double) $this->amount->getAmount();
     if (SilvercartConfig::PriceType() == 'net') {
         $price = $price - $this->getTaxAmount();
     }
     return $price;
 }
 /**
  * Increases the SilverCart version if necessary.
  * 
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 08.04.2013
  */
 public function increaseSilvercartVersion()
 {
     $defaults = Config::inst()->get('SilvercartSiteConfig', 'defaults');
     $minorVersion = $defaults['SilvercartMinorVersion'];
     $config = SilvercartConfig::getConfig();
     if ($config->SilvercartMinorVersion != $minorVersion) {
         $config->SilvercartMinorVersion = $minorVersion;
         $config->write();
     }
 }
 /**
  * Returns whether to skip this step or not.
  * 
  * @return bool
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 11.03.2013
  */
 public function SkipShippingStep()
 {
     if (is_null($this->skipShippingStep)) {
         if (SilvercartConfig::SkipShippingStepIfUnique() && $this->getShippingMethods()->Count() == 1) {
             $this->skipShippingStep = true;
         } else {
             $this->skipShippingStep = false;
         }
     }
     return $this->skipShippingStep;
 }
Пример #24
0
 /**
  * Determin wether the default language should be used for multilingual DataObjects
  * in case a translation does not exist.
  *
  * @return bool 
  * 
  * @author Roland Lehmann <*****@*****.**>
  * @since 04.01.2012
  */
 public static function useDefaultLanguageAsFallback()
 {
     if (is_null(self::$useDefaultLanguageAsFallback)) {
         if (!self::getConfig() === false) {
             self::$useDefaultLanguageAsFallback = self::getConfig()->useDefaultLanguageAsFallback;
         }
     }
     return self::$useDefaultLanguageAsFallback;
 }
Пример #25
0
 /**
  * returns carts net value including all editional costs
  *
  * @return Money amount
  * 
  * @deprecated Use property AmountTotal instead
  */
 public function getAmountNet()
 {
     user_error('SilvercartOrder::getAmountNet() is marked as deprecated! Use property AmountTotal instead.', E_USER_ERROR);
     $amountNet = $this->AmountGrossTotal->getAmount() - $this->Tax->getAmount();
     $amountNetObj = new Money();
     $amountNetObj->setAmount($amountNet);
     $amountNetObj->setCurrency(SilvercartConfig::DefaultCurrency());
     return $amountNetObj;
 }
 /**
  * Returns whether there are products per page options.
  * 
  * @return bool
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 13.09.2013
  */
 public function hasProductsPerPageOptions()
 {
     $productsPerPageOptions = SilvercartConfig::getProductsPerPageOptions();
     return !empty($productsPerPageOptions);
 }
 /**
  * Returns the language for the given locale if exists
  *
  * @param string $locale Locale to get language for
  * 
  * @return bool
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 03.07.2012
  */
 public function getLanguageFor($locale)
 {
     $useDefaultLanguageAsFallback = SilvercartConfig::$useDefaultLanguageAsFallback;
     SilvercartConfig::$useDefaultLanguageAsFallback = false;
     $language = SilvercartLanguageHelper::getLanguage($this->getLanguageRelation(), $locale);
     SilvercartConfig::$useDefaultLanguageAsFallback = $useDefaultLanguageAsFallback;
     return $language;
 }
 /**
  * Adds example configuration to SilverCart when triggered in ModelAdmin.
  *
  * @return SS_HTTPResponse 
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 21.02.2013
  */
 public function add_example_config()
 {
     SilvercartConfig::enableTestData();
     $result = SilvercartRequireDefaultRecords::createTestConfiguration();
     if ($result) {
         $responseText = _t('SilvercartConfig.ADDED_EXAMPLE_CONFIGURATION');
     } else {
         $responseText = _t('SilvercartConfig.EXAMPLE_CONFIGURATION_ALREADY_ADDED');
     }
     $this->owner->getResponse()->addHeader('X-Status', rawurlencode($responseText));
     return $this->owner->getResponseNegotiator()->respond($this->owner->getRequest());
 }
 /**
  * Indicates wether business customers should be enabled.
  *
  * @return boolean
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 09.10.2012
  */
 public function EnablePackstation()
 {
     return SilvercartConfig::enablePackstation();
 }
 /**
  * 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());
         }
     }
 }