daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Order.php
  2.  
  3. <?php
  4. class Order extends DataObject {
  5.     static $db = array(
  6.         'Title' => 'Text',
  7.         'Session' => 'Text'
  8.     );
  9.    
  10.     static $has_many = array(
  11.         "Items" => "Order_Item"
  12.     );
  13. }
  14.  
  15.  
  16. class Order_Item extends DataObject {
  17.     static $has_one = array(
  18.         "Order" => "Order", // Internal field becomes OrderID, not Order
  19.         "ProductPage" => "ProductPage",
  20.     );
  21. }
  22.  
  23.  
  24.  
  25. // ProductPage.php
  26. <?php
  27. class ProductPage extends Page {
  28.     static $icon = '/ssshop/images/product';
  29.    
  30.     static $db = array(
  31.         'Price' => 'Float'
  32.     );
  33.    
  34.     static $has_many = array(
  35.         'ProductVariations' => 'ProductVariations'
  36.     );
  37.    
  38.     static $belongs_many_many = array(
  39.         'Orders' => 'Order'
  40.     );
  41.    
  42.    
  43.     function getCMSFields() {
  44.         $f = parent::getCMSFields();
  45.         $f->addFieldToTab("Root.Content.Main", new NumericField("Price"));
  46.         $manager = new DataObjectManager(
  47.             $this, // Controller
  48.             'ProductVariations', // Source name
  49.             'ProductVariations', // Source class
  50.             array(
  51.                 'Title' => 'Title'
  52.             ), // Headings
  53.             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
  54.         );
  55.        
  56.         $f->addFieldToTab("Root.Content.ProductTypes", $manager);
  57.         return $f;
  58.     }
  59.    
  60.  
  61.    
  62. }
  63.  
  64. class ProductPage_Controller extends Page_Controller {
  65.     function CurrentSession(){
  66.         return Cookie::get('PHPSESSID');
  67.     }
  68.    
  69.     function CurrentOrder() {
  70.         return DataObject::get_one('Order', 'Session =\'' . $this->CurrentSession() . '\'');
  71.     }
  72.    
  73.     function StartOrder(){
  74.         $orderStarted = $this->CurrentOrder();
  75.         if(!$orderStarted) {
  76.             $myOrder = new Order();
  77.             $myOrder->setField('Session', $this->CurrentSession());
  78.             $myOrder->write();
  79.             echo('ok');
  80.         }
  81.     }
  82.    
  83.     function ViewOrder() {
  84.         $myOrder = DataObject::get("Order_Item", "OrderID = 1", "", "", "");
  85.         return $myOrder;
  86.     }
  87.  
  88.     function productForm(){
  89.         $fields = new FieldSet();
  90.         $fields->push(new TextField("HowMany", "HowMany", 1));
  91.         $actions = new FieldSet(
  92.             new FormAction('addProduct', _t('MemberTableField.ADD','Add'))
  93.         );
  94.         $productForm = new Form($this, "productForm", $fields, $actions);
  95.         return $productForm;
  96.     }
  97.    
  98.     function addProduct() {
  99.         $myOrderItem = new Order_Item();
  100.         $myOrder = $this->CurrentOrder();
  101.         $myOrderItem->OrderID = $myOrder->ID;
  102.         $myOrderItem->ProductPageID = $this->ID;
  103.         $myOrderItem->write();
  104.         Director::redirectBack();
  105.     }
  106.    
  107.     function doAction() {
  108.        
  109.     }
  110.    
  111.     public function init() {
  112.         parent::init();
  113.         $this->StartOrder();
  114.     }
  115.  
  116.    
  117. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top