예제 #1
0
 public function anyProduct($type)
 {
     $product_type = ProductTypes::where('name', $type)->first();
     $products = NULL;
     $error_msg = [];
     $main_image = NULL;
     $product_main_image = NULL;
     if ($product_type) {
         $products = Products::where('product_type_id', $product_type->id)->get();
         foreach ($products as $product) {
             $product_main_image = ProductImages::where('product_id', $product->id)->where('is_primary', 1)->first();
         }
         if ($product_main_image) {
             $main_image = $product_main_image->url;
         }
     } else {
         $error_msg[] = 'Product type not found.';
     }
     return View::make('shop.manage_products', ['products' => $products, 'error_msg' => $error_msg, 'main_image' => '../../../storage/app/upload/' . $main_image]);
 }
예제 #2
0
 /**
  * Initialize the products form
  */
 public function initialize($entity = null, $options = array())
 {
     if (!isset($options['edit'])) {
         $element = new Text("id");
         $this->add($element->setLabel("Id"));
     } else {
         $this->add(new Hidden("id"));
     }
     $name = new Text("name");
     $name->setLabel("Name");
     $name->setFilters(array('striptags', 'string'));
     $name->addValidators(array(new PresenceOf(array('message' => 'Name is required'))));
     $this->add($name);
     $type = new Select('product_types_id', ProductTypes::find(), array('using' => array('id', 'name'), 'useEmpty' => true, 'emptyText' => '...', 'emptyValue' => ''));
     $type->setLabel('Type');
     $this->add($type);
     $price = new Text("price");
     $price->setLabel("Price");
     $price->setFilters(array('float'));
     $price->addValidators(array(new PresenceOf(array('message' => 'Price is required')), new Numericality(array('message' => 'Price is required'))));
     $this->add($price);
 }
 /**
  * Deletes a producttypes
  *
  * @param string $id
  */
 public function deleteAction($id)
 {
     $productTypes = ProductTypes::findFirstById($id);
     if (!$productTypes) {
         $this->flash->error("Product types was not found");
         return $this->forward("producttypes/index");
     }
     if (!$productTypes->delete()) {
         foreach ($productTypes->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->forward("producttypes/search");
     }
     $this->flash->success("product types was deleted");
     return $this->forward("producttypes/index");
 }