/** * Update the category tree * * @throws \AjaxException * @return void */ public function onUpdateTree() { try { Category::updateInheritanceTree(input('tree')); } catch (Exception $e) { throw new AjaxException(Lang::get('bedard.shop::lang.category.popup.failed')); } Flash::success(Lang::get('bedard.shop::lang.category.popup.success')); }
public function test_discount_inheritance_is_updated_when_the_tree_is_updated() { $product = Factory::create(new Product()); $parent = Factory::create(new Category(), ['is_inheriting' => true]); $child = Factory::create(new Category(), ['is_inheriting' => true]); $grandchild = Factory::create(new Category(), ['is_inheriting' => true]); $grandchild->products()->attach($product); $discount = Factory::create(new Discount()); $discount->categories()->attach($parent); $discount->save(); $this->assertEquals(0, Price::where('discount_id', $discount->id)->count()); $tree = [['id' => $parent->id, 'parent_id' => null], ['id' => $child->id, 'parent_id' => $parent->id], ['id' => $grandchild->id, 'parent_id' => $child->id]]; Category::updateInheritanceTree($tree); $this->assertEquals(1, Price::where('discount_id', $discount->id)->count()); }