Ejemplo n.º 1
0
 /**
  * Obtains featured image
  * @return null
  * @return String|null
  */
 public function features()
 {
     $featured = $this->resource->product_images()->where("featured", "=", 1)->get();
     if ($featured->isEmpty()) {
         return ["data" => "data:image;base64," . base64_encode(ProductImage::getImageFromUrl($this->default_img_path)), "alt" => ""];
     } else {
         $featured = $featured->first();
     }
     return array("data" => $featured ? "data:image;base64,{$featured->data}" : null, "alt" => $featured->descrizione);
 }
 public function testChangeFeaturedWorks()
 {
     $this->createProduct();
     // create cats
     $data = ["description" => "desc1", "product_id" => 1, "featured" => 1, "image" => ""];
     $this->repo->create($data);
     $data = ["description" => "desc2", "product_id" => 1, "featured" => 0, "image" => ""];
     $this->repo->create($data);
     // creazione prodotto
     $faker = $this->faker;
     Product::create(["code" => $faker->text(5), "name" => $faker->text(10), "slug" => "slug_1", "slug_lang" => "slug_lingua", "lang" => 'it', "description" => $faker->text(10), "descrizione_long" => $faker->text(100), "featured" => 1]);
     $this->repo->changeFeatured(2, 1);
     $img1 = ProductImage::find(1);
     $img2 = ProductImage::find(2);
     $this->assertEquals(0, $img1->featured);
     $this->assertEquals(1, $img2->featured);
 }
Ejemplo n.º 3
0
 /**
  * @return array
  * @todo refactor to test for default image: no statics
  */
 public function image()
 {
     $data = $this->resource->image ? "data:image;base64,{$this->resource->image}" : "data:image;base64," . base64_encode(ProductImage::getImageFromUrl($this->default_img_path));
     $alt = $this->resource->description;
     return ["data" => $data, "alt" => $alt];
 }