Beispiel #1
0
 public function productAttributes()
 {
     if ($this->productAttributes == null) {
         $attributes = ProductAttributes::where('id', 'LIKE', "{$this->id}.%")->get();
         $this->productAttributes = array();
         foreach ($attributes as $attr) {
             $this->productAttributes[$attr->key] = $attr;
         }
     }
     return $this->productAttributes;
 }
 public function onSave()
 {
     $product = Product::findOrFail($this->param('id'));
     $attributes = array('category', 'quantity', 'quantity_UM');
     foreach ($attributes as $attr) {
         $key = sprintf("%s.%s", $product->id, $attr);
         $attribute = ModelProductAttributes::firstOrNew(['id' => $key]);
         $attribute->key = $attr;
         $attribute->value = post($attr);
         $attribute->save();
     }
 }
 public function onRun()
 {
     $categories = ProductAttributes::select('value')->where('key', 'category')->groupBy('value')->get();
     // @see https://octobercms.com/docs/database/collection
     $orderBy = $this->property('orderBy');
     if ($orderBy == 'slug:orderBy') {
         $orderBy = $this->param('orderBy');
     }
     switch ($orderBy) {
         case 'name':
             $categories = $categories->sort(function ($c1, $c2) {
                 return strcmp($c1->value, $c2->value);
             });
             break;
     }
     $this->categories = $categories;
     $this->addCss("styles/index.css");
     return parent::onRun();
 }