/** * 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()); } } }
/** * Render this step with the default template * * @return void * * @author Sascha Koehler <*****@*****.**> * @copyright 2011 pixeltricks GmbH * @since 06.04.2011 */ public function init() { $paymentConfirmationText = ''; $checkoutData = $this->controller->getCombinedStepData(); if (isset($checkoutData['PaymentMethod'])) { $this->paymentMethodObj = SilvercartPaymentMethod::get()->byID($checkoutData['PaymentMethod']); if ($this->paymentMethodObj) { if (isset($checkoutData['orderId'])) { $orderObj = SilvercartOrder::get()->byID($checkoutData['orderId']); if ($orderObj) { $paymentConfirmationText = $this->paymentMethodObj->processPaymentConfirmationText($orderObj); $this->paymentMethodObj->processPaymentAfterOrder($orderObj); } } } } $templateVariables = array('PaymentConfirmationText' => $paymentConfirmationText); $output = $this->customise($templateVariables)->renderWith('SilvercartCheckoutFormStepDefaultOrderConfirmation'); return $output; }
/** * creates default objects * * @return void * * @author Sascha Koehler <*****@*****.**> * @copyright 2011 pixeltricks GmbH * @since 05.01.2011 */ public function requireDefaultRecords() { parent::requireDefaultRecords(); $checkInfoMail = DataObject::get_one('SilvercartShopEmail', sprintf("\"Identifier\" = '%s'", 'SilvercartPaymentPrepaymentBankAccountInfo')); if (!$checkInfoMail) { $infoMail = new SilvercartShopEmail(); $infoMail->setField('Identifier', 'SilvercartPaymentPrepaymentBankAccountInfo'); $infoMail->setField('Subject', _t('SilvercartPaymentPrepayment.PAYMENT_INFO')); $infoMail->setField('EmailText', ''); $infoMail->setField('Variables', "\$SilvercartOrder"); $infoMail->write(); } }
/** * creates test configuration data on /dev/build or by adding test * configuration in ModelAdmin. * * @return bool * * @author Sebastian Diel <*****@*****.**> * @since 02.07.2011 */ public static function createTestConfiguration() { if (self::$enableTestData === true) { //create a carrier and an associated zone and shipping method $carrier = SilvercartCarrier::get()->first(); if (!$carrier) { self::createTestTaxRates(); $carrier = new SilvercartCarrier(); $carrier->Title = 'DHL'; $carrier->FullTitle = 'DHL International GmbH'; $carrier->write(); $carrierLanguages = array('en_GB' => array('Title' => 'DHL', 'FullTitle' => 'DHL International GmbH'), 'en_US' => array('Title' => 'DHL', 'FullTitle' => 'DHL International GmbH'), 'de_DE' => array('Title' => 'DHL', 'FullTitle' => 'DHL International GmbH')); $locales = array('de_DE', 'en_GB', 'en_US'); $fallbackLocale = false; if (!in_array(Translatable::get_current_locale(), $locales)) { $locales[] = Translatable::get_current_locale(); $fallbackLocale = Translatable::get_current_locale(); } if ($fallbackLocale !== false) { $carrierLanguages[$fallbackLocale] = $carrierLanguages['en_US']; } foreach ($carrierLanguages as $locale => $attributes) { $languageObj = SilvercartCarrierLanguage::get()->filter(array('SilvercartCarrierID' => $carrier->ID, 'Locale' => $locale))->first(); if (!$languageObj) { $languageObj = new SilvercartCarrierLanguage(); $languageObj->Locale = $locale; $languageObj->SilvercartCarrierID = $carrier->ID; } foreach ($attributes as $attribute => $value) { $languageObj->{$attribute} = $value; } $languageObj->write(); } //relate carrier to zones $zoneDomestic = SilvercartZone::get()->first(); if (!$zoneDomestic) { $zones = array(array('en_GB' => 'Domestic', 'en_US' => 'Domestic', 'de_DE' => 'Inland'), array('en_GB' => 'EU', 'en_US' => 'European Union', 'de_DE' => 'EU')); $locales = array('de_DE', 'en_GB', 'en_US'); $fallbackLocale = false; if (!in_array(Translatable::get_current_locale(), $locales)) { $locales[] = Translatable::get_current_locale(); $fallbackLocale = Translatable::get_current_locale(); } if ($fallbackLocale !== false) { $zones[0][$fallbackLocale] = $zones[0]['en_US']; $zones[1][$fallbackLocale] = $zones[1]['en_US']; } foreach ($zones as $zone) { $zoneObj = new SilvercartZone(); $zoneObj->write(); $zoneObj->SilvercartCarriers()->add($carrier); $zoneObj->write(); foreach ($zone as $locale => $title) { $zoneLanguage = SilvercartZoneLanguage::get()->filter(array('SilvercartZoneID' => $zoneObj->ID, 'Locale' => $locale))->first(); if (!$zoneLanguage) { $zoneLanguage = new SilvercartZoneLanguage(); $zoneLanguage->SilvercartZoneID = $zoneObj->ID; $zoneLanguage->Locale = $locale; } $zoneLanguage->Title = $title; $zoneLanguage->write(); } } } //Retrieve the active country if exists $country = SilvercartCountry::get()->filter('Active', '1')->first(); if (!$country) { //Retrieve the country dynamically depending on the installation language $installationLanguage = i18n::get_locale(); $ISO2 = substr($installationLanguage, -2); $country = SilvercartCountry::get()->filter('ISO2', $ISO2)->first(); if (!$country) { $country = new SilvercartCountry(); $country->Title = 'Testcountry'; $country->ISO2 = $ISO2; $country->ISO3 = $ISO2; } $country->Active = true; $country->write(); } $zoneDomestic = DataObject::get_by_id('SilvercartZone', 1); $zoneDomestic->SilvercartCountries()->add($country); // create if not exists, activate and relate payment method $paymentMethod = SilvercartPaymentPrepayment::get()->first(); if (!$paymentMethod) { $paymentMethodHandler = new SilvercartPaymentMethod(); $paymentMethodHandler->requireDefaultRecords(); } $paymentMethod = SilvercartPaymentPrepayment::get()->first(); $paymentMethod->isActive = true; $orderStatusPending = SilvercartOrderStatus::get()->filter('Code', 'pending')->first(); if ($orderStatusPending) { $paymentMethod->orderStatus = $orderStatusPending->Code; } $paymentMethod->write(); $country->SilvercartPaymentMethods()->add($paymentMethod); // create a shipping method $shippingMethod = SilvercartShippingMethod::get()->first(); if (!$shippingMethod) { $shippingMethod = new SilvercartShippingMethod(); //relate shipping method to carrier $shippingMethod->SilvercartCarrierID = $carrier->ID; } $shippingMethod->isActive = 1; $shippingMethod->write(); $shippingMethod->SilvercartZones()->add($zoneDomestic); //create the language objects for the shipping method $shippingMethodTranslations = array('de_DE' => 'Paket', 'en_GB' => 'Package', 'en_US' => 'Package'); $locales = array('de_DE', 'en_GB', 'en_US'); $fallbackLocale = false; if (!in_array(Translatable::get_current_locale(), $locales)) { $locales[] = Translatable::get_current_locale(); $fallbackLocale = Translatable::get_current_locale(); } if ($fallbackLocale !== false) { $shippingMethodTranslations[$fallbackLocale] = $shippingMethodTranslations['en_US']; } foreach ($shippingMethodTranslations as $locale => $title) { $shippingMethodLanguage = SilvercartShippingMethodLanguage::get()->filter(array('Locale' => $locale, 'SilvercartShippingMethodID' => $shippingMethod->ID))->first(); if (!$shippingMethodLanguage) { $shippingMethodLanguage = new SilvercartShippingMethodLanguage(); $shippingMethodLanguage->Locale = $locale; $shippingMethodLanguage->SilvercartShippingMethodID = $shippingMethod->ID; } $shippingMethodLanguage->Title = $title; $shippingMethodLanguage->write(); } // create a shipping fee and relate it to zone, tax and shipping method $shippingFee = SilvercartShippingFee::get()->first(); if (!$shippingFee) { $shippingFee = new SilvercartShippingFee(); $shippingFee->MaximumWeight = '100000'; $shippingFee->UnlimitedWeight = true; $shippingFee->Price = new Money(); $shippingFee->Price->setAmount('3.9'); $shippingFee->Price->setCurrency('EUR'); } $shippingFee->SilvercartShippingMethodID = $shippingMethod->ID; $shippingFee->SilvercartZoneID = $zoneDomestic->ID; $higherTaxRate = SilvercartTax::get()->filter('Rate', '19')->first(); $shippingFee->SilvercartTaxID = $higherTaxRate->ID; $shippingFee->write(); return true; } } return false; }
/** * Returns the active payment methods. * * @return DataList|ArrayList */ public function getActivePaymentMethods() { if (is_null($this->activePaymentMethods)) { $activePaymentMethods = SilvercartPaymentMethod::getActivePaymentMethods(); if (!$activePaymentMethods instanceof DataList) { $activePaymentMethods = new ArrayList(); } $this->setActivePaymentMethods($activePaymentMethods); } return $this->activePaymentMethods; }
/** * Creates the upload folder for payment images if it doesn't exist. * * @param array $paymentLogos The payment logos as associative array: * ['LogoName' => 'PATH_TO_FILE', ....] * @param string $paymentModuleName The name of the payment module * * @return void * * @author Sebastian Diel <*****@*****.**>, * Sascha Koehler <*****@*****.**> * @since 16.06.2014 */ public function createLogoImageObjects($paymentLogos, $paymentModuleName) { //make sure that the folder "Uploads" exists Folder::find_or_make('Uploads'); $paymentModule = SilvercartPaymentMethod::get()->filter(array("ClassName" => $paymentModuleName))->sort(array("ID" => "ASC"))->first(); if ($paymentModule) { if (count($this->getPossiblePaymentChannels()) > 0) { // Multiple payment channels foreach ($paymentLogos as $paymentChannel => $logos) { $paymentChannelMethod = DataObject::get_one($paymentModuleName, sprintf("\"PaymentChannel\"='%s'", $paymentChannel), true, $paymentModuleName . ".ID"); if ($paymentChannelMethod) { if (!$paymentChannelMethod->PaymentLogos()->exists()) { foreach ($logos as $title => $logo) { $paymentLogo = new SilvercartImage(); $paymentLogo->Title = $title; $storedLogo = Image::get()->filter('Name', basename($logo))->first(); if ($storedLogo) { $paymentLogo->ImageID = $storedLogo->ID; } else { file_put_contents(Director::baseFolder() . '/' . $this->uploadsFolder->Filename . basename($logo), file_get_contents(Director::baseFolder() . $logo)); $image = new Image(); $image->setFilename($this->uploadsFolder->Filename . basename($logo)); $image->setName(basename($logo)); $image->Title = basename($logo, '.png'); $image->ParentID = $this->uploadsFolder->ID; $image->write(); $paymentLogo->ImageID = $image->ID; } $paymentLogo->write(); $paymentChannelMethod->PaymentLogos()->add($paymentLogo); } } } } } else { // Single payment channels foreach ($paymentLogos as $title => $logo) { if (!$paymentModule->PaymentLogos()->exists()) { $paymentLogo = new SilvercartImage(); $paymentLogo->Title = $title; $storedLogo = Image::get()->filter('Name', basename($logo))->first(); if ($storedLogo) { $paymentLogo->ImageID = $storedLogo->ID; } else { file_put_contents(Director::baseFolder() . '/' . $this->uploadsFolder->Filename . basename($logo), file_get_contents(Director::baseFolder() . $logo)); $image = new Image(); $image->setFilename($this->uploadsFolder->Filename . basename($logo)); $image->setName(basename($logo)); $image->Title = basename($logo, '.png'); $image->ParentID = $this->uploadsFolder->ID; $image->write(); $paymentLogo->ImageID = $image->ID; } $paymentLogo->write(); $paymentModule->PaymentLogos()->add($paymentLogo); } } } } }
/** * Returns all payment methods * * @return DataList * * @author Sebastian Diel <*****@*****.**> * @since 14.05.2012 */ public function PaymentMethods() { $PaymentMethods = SilvercartPaymentMethod::getAllowedPaymentMethodsFor($this->ShippingCountry(), singleton('SilvercartShoppingCart'), true); return $PaymentMethods; }