Пример #1
0
 /**
  * Fetch the category and products
  *
  * @return void
  */
 public function onRun()
 {
     try {
         if ($slug = $this->property('slug')) {
             $slug = $this->property('slug');
             $this->category = $this->repository->findBySlug($slug);
         } else {
             $default = $this->property('default');
             $this->category = $this->repository->findById($default);
         }
         $page = 1;
         $this->products = $this->repository->getProducts($this->category, $page, $this->property('load_thumbnails'), $this->property('load_gallery'), $this->property('load_inventories'));
     } catch (ModelNotFoundException $e) {
         return $this->controller->run('404');
     }
 }
 public function test_fetching_a_page_of_products()
 {
     $parent = Factory::create(new Category(), ['is_inheriting' => true, 'page_rows' => 2, 'page_columns' => 2]);
     $child = Factory::create(new Category(), ['parent_id' => $parent->id]);
     $parent->products()->attach(Factory::create(new Product(), ['name' => 'one']));
     $parent->products()->attach(Factory::create(new Product(), ['name' => 'two']));
     $child->products()->attach(Factory::create(new Product(), ['name' => 'three']));
     $child->products()->attach(Factory::create(new Product(), ['name' => 'four']));
     $child->products()->attach(Factory::create(new Product(), ['name' => 'five']));
     $child->products()->attach(Factory::create(new Product(), ['name' => 'six']));
     $child->products()->attach(Factory::create(new Product(), ['name' => 'seven', 'is_enabled' => false]));
     $repo = new CategoryRepository();
     $page1 = $repo->getProducts($parent, 1, true, true, true);
     $page2 = $repo->getProducts($parent, 2);
     $page3 = $repo->getProducts($parent, 3);
     $this->assertEquals(4, $page1->count());
     $this->assertEquals(2, $page2->count());
     $this->assertEquals(0, $page3->count());
     $this->assertNotNull($page1->first()->inventory);
 }
Пример #3
0
 /**
  * Fetch the categories
  *
  * @return void
  */
 public function onRun()
 {
     $this->categories = $this->repository->getAllCategories();
 }