swipestripe - Silverstripe Model Admin for Pages -


i using silverstripe swipestripe module online store. because of number of products client has, it's not practical nave them navigate each individual product through site tree when want make changes product (which happens regularly) i'd have modeladmin list products , allow them search product name/stockcode.

i thought solvable in same way dataobjects (and searches seem suggest people have done achieved this), when navigate products in modeladmin view, get:

fatal error : call member function stat() on non-object in /path/to/folder/wwwroot/framework/model/dataobject.php on line 3192

<?php class productadmin extends modeladmin {      private static $managed_models = array('product');      private static $url_segment = 'product';      private $menu_title = 'products';  } 

interestingly, pages , other extensions of page class work.

here code product class:

class product extends page {      /**      * flag denoting if first time product being written.      *       * @var boolean      */     protected $firstwrite = false;      /**      * db fields product.      *       * @var array      */     private static $db = array(         'price'     => 'decimal(19,4)',         'currency'  => 'varchar(3)',         'stockcode' => 'varchar(255)',         'stock'     => 'int',         'featured'  => 'boolean',         'youtubeid' => 'varchar(255)'      );      /**      * actual price in base currency, can decorate apply discounts etc.      *       * @return price      */     public function amount() {          // todo: multi currency         $shopconfig = shopconfig::current_shop_config();          $amount = new price();         $amount->setamount($this->price);         $amount->setcurrency($shopconfig->basecurrency);         $amount->setsymbol($shopconfig->basecurrencysymbol);          //transform amount applying discounts etc.         $this->extend('updateamount', $amount);          return $amount;     }      /**      * display price, can decorate multiple currency etc.      *       * @return price      */     public function price() {          $amount = $this->amount();          //transform price here display in different currencies etc.         $this->extend('updateprice', $amount);          return $amount;     }      /**      * has many relations product.      *       * @var array      */     private static $has_many = array(         'attributes' => 'attribute',         'options' => 'option',         'variations' => 'variation'     );      /**      * defaults product      *       * @var array      */     private static $defaults = array(         'parentid' => -1,         'stock'     => 999     );      /**      * summary fields displaying products in cms      *       * @var array      */     private static $summary_fields = array(         'amount.nice' => 'price',         'title' => 'title'     );      private static $searchable_fields = array(         'title' => array(             'field' => 'textfield',             'filter' => 'partialmatchfilter',             'title' => 'name'         )     );      /**      * set firstwrite flag if first time product written.      *       * @see sitetree::onbeforewrite()      * @see product::onafterwrite()      */     public function onbeforewrite() {         parent::onbeforewrite();         if (!$this->id) $this->firstwrite = true;          //save in base currency         $shopconfig = shopconfig::current_shop_config();         $this->currency = $shopconfig->basecurrency;     }      /**      * unpublish products if deleted, such in product admin area      *       * @see sitetree::onafterdelete()      */     public function onafterdelete() {         parent::onafterdelete();          if ($this->ispublished()) {             $this->dounpublish();         }     }      /**      * set cms fields managing products      *       * @see page::getcmsfields()      * @return fieldlist      */     public function getcmsfields() {          $shopconfig = shopconfig::current_shop_config();         $fields = parent::getcmsfields();          //product fields         $fields->addfieldtotab('root.main', new pricefield('price'), 'content');         $fields->addfieldtotab('root.main', new textfield('stockcode'), 'price');         $fields->addfieldtotab('root.main', new textfield('stock'), 'price');         $fields->addfieldtotab('root.main', new checkboxfield('featured'), 'content');         $fields->addfieldtotab('root.images', new textfield('youtubeid', 'youtube video id (taken end of video url. ie https://www.youtube.com/watch?v=abc123 abc123)'));          //replace url segment field         if ($this->parentid == -1) {             $urlsegment = new sitetreeurlsegmentfield("urlsegment", 'urlsegment');             $baselink = controller::join_links(director::absolutebaseurl(), 'product/');             $url = (strlen($baselink) > 36) ? "..." .substr($baselink, -32) : $baselink;             $urlsegment->seturlprefix($url);             $fields->replacefield('urlsegment', $urlsegment);         }          if ($this->isindb()) {              //product attributes             $listfield = new gridfield(                 'attributes',                 'attributes',                 $this->attributes(),                 gridfieldconfig_basicsortable::create()             );             $fields->addfieldtotab('root.attributes', $listfield);              //product variations             $attributes = $this->attributes();             if ($attributes && $attributes->exists()) {                  //remove stock level field if there variations, each variation has stock field                 $fields->removebyname('stock');                  $variationfieldlist = array();                 foreach ($attributes $attribute) {                     $variationfieldlist['attributevalue_'.$attribute->id] = $attribute->title;                 }                 $variationfieldlist = array_merge($variationfieldlist, singleton('variation')->summaryfields());                  $config = gridfieldconfig_hasmanyrelationeditor::create();                 $datacolumns = $config->getcomponentbytype('gridfielddatacolumns');                 $datacolumns->setdisplayfields($variationfieldlist);                  $listfield = new gridfield(                     'variations',                     'variations',                     $this->variations(),                     $config                 );                 $fields->addfieldtotab('root.variations', $listfield);             }         }          //ability edit fields added cms here         $this->extend('updateproductcmsfields', $fields);          if ($warning = shopconfig::base_currency_warning()) {             $fields->addfieldtotab('root.main', new literalfield('basecurrencywarning',                  '<p class="message warning">'.$warning.'</p>'             ), 'title');         }          return $fields;     }      /**      * url product, products not part of sitetree       * displayed {@link product_controller}.      *       * @see sitetree::link()      * @see product_controller::show()      * @return string      */     public function link($action = null) {          if ($this->parentid > -1) {             return parent::link($action);         }         return controller::join_links(director::baseurl() . 'product/', $this->relativelink($action));     }      /**      * product required added cart variation if has attributes.      * product attributes needs have enabled {@link variation}s      *       * @return boolean      */     public function requiresvariation() {         $attributes = $this->attributes();         return $attributes && $attributes->exists();     }      /**      * options attribute of product.      *       * @param int $attributeid      * @return arraylist      */     public function getoptionsforattribute($attributeid) {          $options = new arraylist();         $variations = $this->variations();          if ($variations && $variations->exists()) foreach ($variations $variation) {              if ($variation->isenabled()) {                 $option = $variation->getoptionforattribute($attributeid);                 if ($option) $options->push($option);              }         }         $options = $options->sort('sortorder');         return $options;     }      /**      * validate product before saved in {@link shopadmin}.      *       * @see dataobject::validate()      * @return validationresult      */     public function validate() {          $result = new validationresult();           //if being published, check enabled variations exist if required         $request = controller::curr()->getrequest();         $publishing = ($request && $request->getvar('action_publish')) ? true : false;          if ($publishing && $this->requiresvariation()) {              $variations = $this->variations();              if (!in_array('enabled', $variations->map('id', 'status')->toarray())) {                 $result->error(                     'cannot publish product when no variations enabled. please enable product variations , try again.',                     'variationsdisablederror'                 );             }         }         return $result;     }  } 

can suggest i'm doing wrong here or alternative way i'm trying achieve?

cheers

just in case still having same problem. so, happens if have installed product categories module swipestripe. cause of private static $searchable_fields in productcategory_extension class in productcategory.php file in module. comment out field , work. because dataobject class tries stat category class - doesnt exist.

i fix , push github if time. wanted update here others dont waste time scratching head why doesnt work.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -