/** * Edit the set * @param integer $id The ID Of The Set To Edit * @access public * @return View */ public function getEdit($id = null) { $set = $this->attribute_sets->find($id); if (!$set) { return Redirect::to('manage/attribute-sets'); } $assignedAttributes = $set->attributes()->lists('key', 'key'); return View::make('ProductCatalog::attribute_sets.edit')->with('assignedAttributes', $assignedAttributes)->with('attributes', $this->attributes->getAll())->with('set', $set); }
/** * Edit the product * @param string $sku The SKU Of The Product To Edit * @access public * @return View */ public function getEdit($id = null) { $product = $this->products->with('categories')->with('attributeSet')->find($id); // Redirect all requests where the product doesn't exist back to the main products dashboard if (!$product) { return Redirect::to('manage/products'); } // Get the top level categories only, we nest from the view itself $categories = $this->categories->getTopLevel(); $attribute_sets = [0 => 'None'] + $this->attribute_sets->getAll()->lists('name', 'id'); $collections = [0 => 'None'] + $this->collections->getAll()->lists('name', 'id'); // Setup the old data so it's easy to find $mainImage = Input::old('mainImage', false); if ($mainImage === false and $product->getMainImage()) { $mainImage = $product->getMainImage()->id; } // Setup the old data so it's easy to find $thumbnailImage = Input::old('thumbnailImage', false); if ($thumbnailImage === false and $product->getThumbnailImage()) { $thumbnailImage = $product->getThumbnailImage()->id; } // We need to render the attribute views that we can edit for the product, lets see if our product actually has attributes first $attributeViews = []; if ($product->getAvailableAttributes()) { // Setup our old data $oldData = Input::old('attributes', []); // Loop through the attributes foreach ($product->getAvailableAttributes() as $attribute) { // Get the attribute object so we can access certain methods $attr = $this->attributes->find($attribute->id); if ($attr) { // Old data should override stored data, lets ensure that happens here $old = array_key_exists($attribute->id, $oldData) ? $oldData[$attribute->id] : null; if ($old === null) { $saved_value = $product->getAttrValue($attribute->id); if (!$saved_value or $saved_value == '') { $value = $attribute->default; } else { $value = $saved_value; } } else { $value = $old; } // Render the resulting view into an array that we eventually render $attributeViews[] = View::make('ProductCatalog::products.partials.attributes.' . $attr->type()->getViewName())->with('attribute', $attr)->with('value', $value); } } } // Make the end view, whoop! return View::make('ProductCatalog::products.edit')->with('product', $product)->with('attributeViews', $attributeViews)->with('mainImageId', $mainImage)->with('attribute_sets', $attribute_sets)->with('collections', $collections)->with('thumbnailImageId', $thumbnailImage)->with('categories', $categories); }