コード例 #1
0
 /**
  * Returns the shipping methods.
  * 
  * @return DataList
  */
 public function getShippingMethods()
 {
     if (is_null($this->shippingMethods)) {
         $shippingMethods = SilvercartShippingMethod::getAllowedShippingMethods(null, $this->getShippingAddress());
         if (!$shippingMethods instanceof ArrayList || $shippingMethods->count() == 0) {
             $shippingMethods = SilvercartShippingMethod::get();
             if (!$shippingMethods instanceof DataList) {
                 $shippingMethods = new DataList();
             }
         }
         $this->shippingMethods = $shippingMethods;
     }
     return $this->shippingMethods;
 }
コード例 #2
0
 /**
  * Returns the default shipping fee for this product
  *
  * @param SilvercartCountry $country       Country to get fee for
  * @param Group             $customerGroup Group to get fee for
  * 
  * @return SilvercartShippingFee 
  */
 public function getDefaultShippingFee(SilvercartCountry $country = null, $customerGroup = null)
 {
     $shippingFee = '';
     if (!is_null($country)) {
         if (is_null($customerGroup)) {
             $customerGroup = SilvercartCustomer::default_customer_group();
         }
         $shippingFee = SilvercartShippingMethod::getAllowedShippingFeeFor($this, $country, $customerGroup, true);
     }
     return $shippingFee;
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
 /**
  * Returns the delivery time as string.
  * 
  * @param bool $forceDisplayInDays Force displaying the delivery time in days
  * 
  * @return string
  */
 public function getDeliveryTime($forceDisplayInDays = false)
 {
     return SilvercartShippingMethod::get_delivery_time($this, $forceDisplayInDays);
 }
コード例 #5
0
 /**
  * Returns all allowed shipping methods for the this carrier
  *
  * @return SilvercartShippingMethod 
  */
 public function getAllowedSilvercartShippingMethods()
 {
     return SilvercartShippingMethod::getAllowedShippingMethodsForOverview($this);
 }
コード例 #6
0
 /**
  * Returns allowed shipping methods. Those are
  * 
  * - shipping methods which are related directly to the payment method
  * - shipping methods which are NOT related to any payment method
  *
  * @return ArrayList
  * 
  * @author Roland Lehmann <*****@*****.**>, Sascha Koehler <*****@*****.**>
  * @since 11.05.2011
  */
 public function getAllowedShippingMethods()
 {
     $allowedShippingMethods = array();
     $shippingMethods = SilvercartShippingMethod::get()->filter(array("isActive" => 1));
     if ($shippingMethods->exists()) {
         foreach ($shippingMethods as $shippingMethod) {
             // Find shippping methods that are directly related to
             // payment methods....
             if ($shippingMethod->SilvercartPaymentMethods()->exists()) {
                 // ... and exclude them, if the current payment method is
                 // not related.
                 if (!$shippingMethod->SilvercartPaymentMethods()->find('ID', $this->ID)) {
                     continue;
                 }
             }
             // If there is no shipping fee defined for this shipping
             // method we don't want to show it.
             if ($shippingMethod->getShippingFee() !== false) {
                 $allowedShippingMethods[] = $shippingMethod;
             }
         }
     }
     $allowedShippingMethods = new ArrayList($allowedShippingMethods);
     return $allowedShippingMethods;
 }
コード例 #7
0
 /**
  * Returns all allowed shipping fees in the given products, countries
  * and customer groups context.
  *
  * @param SilvercartProduct $product       Product to get fee for
  * @param SilvercartCountry $country       Country to get fee for
  * @param Group             $customerGroup Customer group to get fee for
  * @param bool              $excludePickup Set to true to exclude pickups
  * 
  * @return ArrayList
  */
 public static function getAllowedShippingFeesFor(SilvercartProduct $product, SilvercartCountry $country, Group $customerGroup, $excludePickup = false)
 {
     $extendableShippingMethod = singleton('SilvercartShippingMethod');
     $addToFilter = '';
     if ($excludePickup) {
         $addToFilter = ' AND SilvercartShippingMethod.isPickup = 0';
     }
     $filter = sprintf('"SilvercartShippingMethod"."isActive" = 1 AND ("SilvercartShippingMethod_SilvercartCustomerGroups"."GroupID" IN (%s) OR "SilvercartShippingMethod"."ID" NOT IN (%s))%s', $customerGroup->ID, 'SELECT "SilvercartShippingMethod_SilvercartCustomerGroups"."SilvercartShippingMethodID" FROM "SilvercartShippingMethod_SilvercartCustomerGroups"', $addToFilter);
     $joinTable = 'SilvercartShippingMethod_SilvercartCustomerGroups';
     $joinOnClause = '"SilvercartShippingMethod_SilvercartCustomerGroups"."SilvercartShippingMethodID" = "SilvercartShippingMethod"."ID"';
     $shippingMethods = SilvercartShippingMethod::get()->leftJoin($joinTable, $joinOnClause)->where($filter);
     $extendableShippingMethod->extend('updateAllowedShippingFeesFor', $shippingMethods, $product);
     $shippingFees = new ArrayList();
     if ($shippingMethods->exists()) {
         foreach ($shippingMethods as $shippingMethod) {
             $shippingMethod->setShippingCountry($country);
             $shippingFee = $shippingMethod->getShippingFee($product->Weight);
             if ($shippingFee) {
                 $shippingFees->push($shippingFee);
             }
         }
     }
     return $shippingFees;
 }