/** * @param Category $category * @return Collection|PresenterPagination * @todo unit test */ public function create(Category $category) { $per_page = Config::get('catalog::client_per_page'); // if has childrens returns the subcategories if ($this->r->hasChildrens($category->id)) { $categories = $category->children ? $category->children()->orderBy('description')->paginate($per_page) : array(); return !empty($categories) ? new PresenterPagination('Palmabit\\Catalog\\Presenters\\PresenterCategory', $categories) : new Collection(); } else { $products = $category->products ? $category->products()->wherePublic(1)->orderBy('order', 'DESC')->orderBy('name', 'ASC')->paginate($per_page) : array(); return !empty($products) ? new PresenterPagination('Palmabit\\Catalog\\Presenters\\PresenterProducts', $products) : new Collection(); } }
function get_cat_select_arr($with_empty_field = false) { $cat_arr = $with_empty_field ? ["0" => ""] : []; Category::whereLang(L::get_admin())->get(["id", "description"])->each(function ($cat) use(&$cat_arr) { $cat_arr[$cat->id] = $cat->description; }); return $cat_arr; }
public function testDeleteWorks() { $this->createProduct(); $data = ["description" => "desc", "product_id" => 1, "featured" => 1, "image" => ""]; $obj = $this->repo->create($data); $this->repo->delete(1); $numero_cat = Category::all()->count(); $this->assertEquals(0, $numero_cat); }
public function testSearch() { $description = "description"; Category::create(array("description" => $description, "slug" => "slug", "slug_lang" => "slug")); $cat = $this->repo->search($description); $this->assertNotEmpty($cat); $cat = $this->repo->search("not found"); $this->assertEmpty($cat); }
/** * Find category by slug * @param $slug */ public function searchByCatSlug($slug) { $cat = Category::whereSlug($slug)->with('product')->orderBy('order', 'name')->get(); return $cat->isEmpty() ? null : $cat->first(); }
/** * @test * @group duplicate **/ public function it_duplicates_products_cats_imgs_accessories_and_create_unique_slug_lang() { // prepare product with related classes $this->prepareFakeData(2); $this->r->attachProduct(1, 2); Category::create(["description" => "descrizione", "slug" => "slug", "slug_lang" => "slug", "lang" => "it"]); $this->r->associateCategory(1, 1); $mock_img_repo = new ImgRepoStub(); $img_data = ["description" => "desc", "product_id" => 1, "featured" => 0, "data" => 111]; $mock_img_repo->create($img_data); $prod = $this->r->duplicate(1); // product duplicated $prod3 = $this->r->find(3); $prod1 = $this->r->find(1); // check that name contains copy $expected_name = $prod1->name . "_copia"; $this->assertEquals($prod3->name, $expected_name); // check that i return a cloned product with no slug lang $this->assertEquals($prod->id, $prod->slug_lang); // categories $cat_original = $prod3->categories()->get()->lists('id'); $cat_associated = $prod3->categories()->get()->lists('id'); $this->assertEquals($cat_original, $cat_associated); // accessories $acc_original = $prod3->accessories()->get()->lists('id'); $acc_associated = $prod3->accessories()->get()->lists('id'); $this->assertEquals($acc_original, $acc_associated); // images $image_original = App::make('product_image_repository')->getByProductId($prod1->id); $image_associated = App::make('product_image_repository')->getByProductId($prod3->id); $this->assertEquals(count($image_original), count($image_associated)); $this->assertEquals($image_original->first()->data, $image_associated->first()->data); }