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

  • Catalog
  • CatalogAdmin
  • CatalogCMSActionDecorator
  • CatalogMemberDecorator
  • CatalogPrice
  • CMSSiteTreeFilter_Catalog
  • Monument
  • MonumentCatalog
  • MonumentForm
  • Orders1CExchange_SiteConfig
  • PaymentType
  • Product
  • ProductCatalogSiteConfig
  • ProductSearchPage
  • SimpleOrderButton
  • SimpleOrderData
  • SimpleOrderForm
  • SimpleOrderPage
  • StartCatalog
  • VirtualProduct

Interfaces

  • OrderButtonInterface
  1 <?php
  2 
  3 /**
  4  * Данные клиента хранящиеся в простом заказе.
  5  * Контактная информация и т. д.
  6  * Так же содержит конечную стоимость за которую был выполнен заказ.
  7  *
  8  * @package Catalog
  9  * @author inxo, dvp
 10  */
 11 class SimpleOrderData extends DataObject {
 12 
 13     static $db = array(
 14         'Num' => 'Int', // кол-во товара
 15         'Client' => 'Varchar(255)', // Имя клиента
 16         'City' => 'Varchar', // Город клиента
 17         'Address' => 'Text', // Адрес клиента
 18         'Phone' => 'Varchar', // Телефон
 19         'Email' => 'Varchar', // Электропочта
 20         'Comment' => 'Text', // Комментарий к заказу
 21         'Status' => "Enum('new,processing,done','new')", // Статус заказа 
 22         'TotalSum' => 'CatalogPrice' // Конечная стоимость
 23     );
 24 
 25     static $defaults = array(
 26         'Status' => 'new',
 27     );
 28 
 29     static $has_one = array(
 30         'Parent' => 'SimpleOrderPage',
 31         'Product' => 'Product', // Чего заказал
 32         'PaymentType' => 'PaymentType',
 33     );
 34 
 35     static $default_sort = "ID DESC";
 36     static $searchable_fields = array('Product.Title', 'Client', 'Email', 'Phone', 'TotalSum', 'Status'); // 
 37     static $summary_fields = array('ID', 'Product.Title', 'Client', 'Email', 'Phone', 'TotalSum', 'PaymentType.Title', 'StatusText'); // 
 38 
 39     function fieldLabels($rel = true) {
 40         $labels = parent::fieldLabels($rel);
 41         //$labels['ID'] = _t('SimpleOrderData.db_ID', 'Order #');
 42         $labels['Product.Title'] = _t('SimpleOrderData.has_one_Product', 'Product title');
 43         $labels['PaymentType.Title'] = _t('SimpleOrderData.has_one_PaymentType', 'Payment type');
 44         $labels['StatusText'] = _t('SimpleOrderData.db_Status', 'Order status');
 45         return $labels;
 46     }
 47 
 48     /**
 49      * Локализованное представление статуса заказа
 50      * 
 51      * @param string $status 
 52      * 
 53      * @return string
 54      */
 55     static function text_status($status) {
 56         return _t('SimpleOrderData.Status_' . $status, $status);
 57     }
 58 
 59     /**
 60      * Список обязательных полей
 61      */
 62     static $required_fields = array('ProductID', 'Num', 'Client', 'Email', 'Phone', 'PaymentTypeID');
 63 
 64     /**
 65      * Устанавливает новый список обязательных полей
 66      * 
 67      * @param array $fields 
 68      */
 69     static function set_required_fields($fields) {
 70         self::$required_fields = $fields;
 71     }
 72 
 73     /**
 74      * Список полей которые не показываются в форме
 75      */
 76     static $hidden_fields = array('Address');
 77 
 78     /**
 79      * Устанавливает новый список скрываемых из формы полей
 80      * 
 81      * @param array $fields 
 82      */
 83     static function hide_fields($fields) {
 84         self::$hidden_fields = $fields;
 85     }
 86 
 87     /**
 88     * Возвращает список полей для формы заказа
 89     * В расширениях можно определить метод updateOrderFields() чтобы изменить список полей
 90     *
 91     * @param array $payments - способы оплаты
 92     * @param Product $item - товар
 93     * @param integer $Num - кол-во товара [1]
 94     * @result FieldSet - поля для формы заказа
 95     */
 96     function getOrderFields($payments, $item, $Num=1) {
 97         if (count($payments) == 0) {
 98             $paymentField = new HiddenField('PaymentTypeID', '', 'undefined');
 99         } elseif (count($payments) == 1) {
100             $paymentField = new HiddenField('PaymentTypeID', '', array_shift(array_keys($payments)));
101         }
102         else {
103             $paymentField = new DropdownField('PaymentTypeID', $this->fieldLabel('PaymentType'), $payments, '', null, _t('SimpleOrderData.ChoosePaymentType', ' '));
104         }
105         
106         $fields = new FieldSet(
107             new HiddenField('ProductID', '', $item->ID),
108             new HiddenField('itemId', '', $item->ID),
109             new HiddenField('Num', $this->fieldLabel('Num'), $Num),
110             
111             $nameField = new TextField('Client', _t('SimpleOrderData.db_Client_Frontend', 'Your name')),
112             $cityField = new TextField('City', $this->fieldLabel('City')),
113             $addressField = new TextField('Address', $this->fieldLabel('Address')),
114             new EmailField('Email', $this->fieldLabel('Email')),
115             new PhoneField('Phone', $this->fieldLabel('Phone')),
116             $paymentField,
117             new TextareaField('Comment', $this->fieldLabel('Comment'))
118         );
119         $nameField->setAutocomplete('name');
120         $cityField->setAutocomplete('city');
121         $addressField->setAutocomplete('street-address');
122         foreach (self::$hidden_fields as $f) {
123             $fields->removeByName($f);
124         }
125         $siteConfig = SiteConfig::current_site_config();
126         if ($siteConfig->hasMethod('SiteAgreementField') && ($rulesField = $siteConfig->SiteAgreementField())) {
127             $fields->push($rulesField);
128         }
129         $this->extend('updateOrderFields', $fields);
130         return $fields;
131     }
132 
133     /**
134     * Возвращает список обязательных полей для формы заказа
135     * В расширениях можно определить метод updateOrderRequiredFields() чтобы изменить список обязательных полей
136     *
137     * @result array - список обязательных полей
138     */
139     function getOrderRequiredFields() {
140         $fields = self::$required_fields;
141         $siteConfig = SiteConfig::current_site_config();
142         if ($siteConfig->hasMethod('SiteAgreementField') && ($rulesField = $siteConfig->SiteAgreementField())) {
143             $fields[] = $rulesField->Name();
144         }
145         $this->extend('updateOrderRequiredFields', $fields);
146         return $fields;
147     }
148     
149     function getCMSFields() {
150         $fields = parent::getCMSFields();
151         $statusValues = singleton('SimpleOrderData')->dbObject('Status')->enumValues();     
152         foreach ($statusValues as $statusItem => $statusName) {
153             $statusValues[$statusItem] = SimpleOrderData::text_status($statusItem);
154         }       
155         $fields->replaceField('Status', new DropdownField('Status', $this->fieldLabel('Status'), $statusValues));       
156         $fields->replaceField('ParentID', new HiddenField('ParentID', $this->fieldLabel('ParentID')));  
157         $fields->replaceField('ProductID', new HiddenField('ProductID', $this->fieldLabel('ProductID')));
158         return $fields;
159     }
160 
161     function getCMSField_popup() {
162         // !!! брать валюту из конфига сайта
163         $orderInfo = "<h3>" . _t('SimpleOrderData.OrderInfo', 'Order Info') . "</h3>
164             <p>
165             <a href=\"{$this->Product()->Link()}\" target=\"_blank\">{$this->Product()->Title}</a><br/>
166                 " . _t('SimpleOrderData.ItemPrice', 'Price: ') . " {$this->Product()->Price} " . _t('OrderInfo.RUR', 'RUR') . " x {$this->Num} " . _t('OrderInfo.ED', 'ED') . "
167             </p>
168             <p>" . _t('SimpleOrderData.EndPrice', 'End Price') . " " . $this->EndPrice . "</p>
169             <h3>" . _t('SimpleOrderData.OrderInfoClient', 'Client') . "</h3>
170                 <p><a href=\"mailto:{$this->Email}\">{$this->Name}</a> - {$this->Phone}</p>
171                 <p>" . _t('SimpleOrderData.Adress', 'Adress') . ":<br/> {$this->Adress}</p>
172                 <p>" . _t('SimpleOrderData.Comment', 'Comment') . ":<br/> {$this->Comment}</p>";
173 
174         $status = array();
175         foreach ($this->dbObject('Status')->enumValues() as $val) {
176             $status[$val] = self::text_status($val);
177         }
178 
179         $fields = new FieldSet(
180             new LiteralField('OrderInfo', $orderInfo),
181             new DropdownField('Status', _t('Catalog.StatusField', 'Status'), $status)
182         );
183 
184         $this->extend('updateCMSField_popup', $fields);
185         return $fields;
186     }
187 
188     /**
189      * Локализованный статус заказа
190      * 
191      * @return string
192      */
193     function StatusText() {
194         return self::text_status($this->Status);
195     }
196 }
197 
[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