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

Packages

  • auth
  • Booking
  • cart
    • shipping
    • steppedcheckout
  • Catalog
  • 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

  • Cart
  • CartOrderButton
  • CartPage
  • CartSiteConfig
  • CartTableListField
  • CheckoutPage
  • ExtendGroupDiscount
  • ExtendMemberCart
  • ExtendPageCart
  • ExtendPageSpecialCatalog
  • ExtendProductSpecialCatalog
  • ExtendProfilePageOrder
  • Order
  • OrderAdmin
  • OrderExporter
  • OrderItem
  • OrderItemField
  • SpecialCatalog
  • TextLiteralField
  1 <?php
  2 
  3 /**
  4  * Кнопка добавления в корзину
  5  *
  6  * @package cart
  7  * @author dvp
  8  */
  9 class CartOrderButton extends ViewableData implements OrderButtonInterface {
 10 
 11     private $product = 0;
 12     private $variation;
 13 
 14     function __construct($product, $variation="") {
 15         parent::__construct();
 16         $this->product = $product;
 17         $this->variation = $variation;
 18     }
 19 
 20     /**
 21      * Кнопка "добавить в корзину" для товаров
 22      *
 23      * @param bool $withNum - с полем для кол-ва
 24      * @param bool $hasOne - допускается тоьлко 1 такой товар в корзине
 25      *
 26      * @return Form - форму с кнопкой заказа
 27      */
 28     public function Show($withNum=false, $hasOne=false) {
 29         if ($hasOne) {
 30             $cart = Cart::get_items();
 31             if ($cart && !empty($cart))
 32                 foreach ($cart as $item) {
 33                     if ($item->getProductID() == $this->product)
 34                         return false;
 35                 }
 36         }
 37 
 38         $fields = new FieldSet(
 39             new HiddenField('itemId', '', $this->product)
 40         );
 41         
 42         if (($product = DataObject::get_by_id('Product', $this->product)) && $product->hasMethod('Variations') && $product->Variations()->exists()) {
 43             if (($availableVariations = $product->AllVariations()) && $availableVariations->Count() && $this->variation) {
 44                 $fields->push(new HiddenField('variationId', '', $this->variation));
 45                 // вместо дропдауна скрытый json с данными вариаций
 46                 //$fields->push(new DropdownField('variationId', _t('Product.Variations'), $availableVariations->map('ID', 'OrderButtonTitle', _t('CartOrderButton.SelectVatiation')), $this->variation));
 47                 // хотя, если кнопку получаем ajax-ом, то в скрытых данных нет смысла - ?? выкинуть ??
 48                 //$fields->push(new LiteralField('VariationsData', '<span class="product_variation_data" style="display: none;">' . json_encode($availableVariations->map('ID', 'VariationInfo')) . '</span>'));
 49             } else {
 50                 return false;
 51             }
 52         }
 53 
 54         if ($withNum) {
 55             $fields->push($field = new NumericField('Num', '', 1));
 56             $field->addExtraClass('AddProductNum');
 57         }
 58 
 59         $form = new Form(
 60             new Cart_Controller(),
 61             "add",
 62             $fields,
 63             new FieldSet($action = new FormAction("add", _t('Cart.OrderButtonTitle', 'Add Cart')))
 64         );
 65 
 66         $action->addExtraClass('AddProductAction');
 67         $form->setTemplate('CartOrderButton');
 68         $form->setHTMLID('AddProductForm_'. $this->product);
 69         $form->addExtraClass('AddProductForm');
 70         if ($withNum) $form->addExtraClass('AddProductForm__Num');
 71         $form->getValidator()->setJavascriptValidationHandler('none');
 72         $form->disableSecurityToken();
 73 
 74         return $form;
 75     }
 76 
 77     /**
 78      * Показывает кнопку для заказа 1 товара
 79      *
 80      * @return Form
 81      */
 82     public function One() {
 83         return $this->Show();
 84     }
 85 
 86     /**
 87      * Показывает кнопку для заказа товара с полем кол-ва
 88      *
 89      * @return Form
 90      */
 91     public function WithNum() {
 92         return $this->Show(true);
 93     }
 94 
 95     /**
 96      * Отображение кнопки в шаблонах "по-умолчанию"
 97      *
 98      * @return string
 99      */
100     public function forTemplate() {
101         if ($this->One())
102             return $this->One()->forTemplate();
103     }
104 }
105 
[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.1 API Docs API documentation generated by ApiGen 2.8.0