Webylon 3.2 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
  • Download
Version: current
  • 3.2
  • 3.1

Packages

  • 1c
    • exchange
      • catalog
  • auth
  • Booking
  • building
    • company
  • cart
    • shipping
    • steppedcheckout
  • Catalog
    • monument
  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • newsletter
    • publishers
    • reports
    • security
    • tasks
  • Dashboard
  • DataObjectManager
  • event
  • faq
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • googlesitemaps
  • guestbook
  • installer
  • newsletter
  • None
  • photo
    • gallery
  • PHP
  • polls
  • recaptcha
  • sapphire
    • api
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • filesystem
    • formatters
    • forms
    • i18n
    • integration
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • tools
    • validation
    • view
    • widgets
  • seo
    • open
      • graph
  • sfDateTimePlugin
  • spamprotection
  • stealth
    • captha
  • subsites
  • userform
    • pagetypes
  • userforms
  • webylon
  • widgets

Classes

  • AddressBookProfilePageExtension
  • ContactFormAddressExtension
  • CostTableShippingMethod
  • FixedShippingMethod
  • ProductShippingDecorator
  • RegionRestriction
  • RestrictionRegionCountryDropdownField
  • ShippingMemberDecorator
  • ShippingMethod
  • ShippingMethodAdmin
  • ShippingOrderDecorator
  • ShippingSiteConfig
  • TableShippingMethod
  • WeightTableShippingMethod
 1 <?php
 2 /**
 3  * Табличный метод расчета стоимости доставки (от него наследуем способы доставки)
 4  * 
 5  * @package cart_shipping
 6  * @author menedem
 7  */
 8 class TableShippingMethod extends ShippingMethod{
 9     
10     static $packageConstraints = array(); //Массив полей, по которым отбираются стоимости доставки
11     
12     static function setConstraints($val) {
13         self::$packageConstraints = $val;       
14     }
15     
16     function getConstraints() {
17         user_error("Не задано поле для отбора способа доставки в _config.php", E_USER_ERROR);  
18     }
19     
20     static $needRegionRestriction = true;
21     
22     static function setNeedRegionRestriction($val) {
23         self::$needRegionRestriction = $val;        
24     }
25     
26     static function getNeedRegionRestriction() {
27         return self::$needRegionRestriction;        
28     }
29     
30     /**
31      * Find the appropriate shipping rate from stored table range metrics
32      */
33     function calculateRate(ShippingPackage $package, Address $address) {
34         $rate = null;
35         if ($this->Rates()->exists()) {
36             $shippingRateClass = $this->Rates()->First()->ClassName;
37             $packageconstraints = $this->getConstraints();
38             $constraintfilters = array();
39             foreach($packageconstraints as $pakval){            
40                 $mincol = "\"{$shippingRateClass}\".\"{$pakval}Min\"";
41                 $maxcol = "\"{$shippingRateClass}\".\"{$pakval}Max\"";
42                 $constraintfilters[] = "(".
43                     "$mincol >= 0" .
44                     " AND $mincol <= " . $package->{$pakval}() . //{$pakval}
45                     " AND $maxcol > 0". //ignore constraints with maxvalue = 0
46                     " AND $maxcol >= " . $package->{$pakval}() . //{$pakval}
47                     " AND $mincol < $maxcol" . //sanity check
48                 ")";
49             }
50             $filter = "(".implode(") AND (",array(
51                 "\"ShippingMethodID\" = ".$this->ID,
52                 (self::getNeedRegionRestriction()) ? RegionRestriction::address_filter($address) : array(), //address restriction if needed
53                 implode(" OR ",$constraintfilters) //metrics restriction
54             )).")";         
55             if ($tr = DataObject::get_one($shippingRateClass, $filter, true, "Rate ASC")) {             
56                 $rate = $tr->Rate;
57             }
58             $this->CalculatedRate = $rate;
59         }
60         return $rate;
61     }
62 }
63 
64 /**
65  * Adds extra metric ranges to restrict with, rather than just region.
66  */
67 class TableShippingRate extends RegionRestriction {
68     
69     static $db = array(
70         'Rate' => 'CatalogPrice',
71     );  
72     
73     static $summary_fields = array(
74         'Country',
75         'State',
76         'City',
77         'PostalCode',
78         'Rate'
79     );
80     
81     static $default_sort = '"Country" ASC, "State" ASC, "City" ASC, "PostalCode" ASC, "Rate" ASC';
82 }
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -
Webylon 3.2 API Docs API documentation generated by ApiGen 2.8.0