/** * Moves a category - under another node * or simply updates its order */ public function procShopServiceMoveCategory() { $source_category_srl = Context::get('source_srl'); // If parent_srl exists, be the first child $parent_category_srl = Context::get('parent_srl'); // If target_srl exists, be a sibling $target_category_srl = Context::get('target_srl'); $category_repository = new CategoryRepository(); $category_repository->moveCategory($source_category_srl, $parent_category_srl, $target_category_srl); }
/** * Move any node after another one in the middle of the list * * Input from client side tree: * parent_srl = 0 * target_srl = some_id */ public function testMoveNodeAfterAnother_ExistingSubcategoryMiddleOfList() { $category_repository = new CategoryRepository(); // At first, the tree is like this: // 1. Phones [1] // 2. Samsung [2] // 3. Nokia [3] // 4. LG [4] // We'll move LG underneath Phones (not at the end, that uses target_srl, but at the top, which uses parent_srl) $category_repository->moveCategory(self::CATEGORY_LG, 0, self::CATEGORY_SAMSUNG); // We expect the following tree: // 1. Phones [1] // 2. Samsung [2] // 4. LG [3] // 3. Nokia [4] $tree = $category_repository->getCategoriesTree(107); $phones = array_shift($tree->children); $samsung = array_shift($phones->children); $lg = array_shift($phones->children); $nokia = array_shift($phones->children); $this->assertEquals(self::CATEGORY_PHONES, $phones->category->category_srl); $this->assertEquals(1, $phones->category->list_order); $this->assertEquals(self::CATEGORY_SAMSUNG, $samsung->category->category_srl); $this->assertEquals(2, $samsung->category->list_order); $this->assertEquals(self::CATEGORY_LG, $lg->category->category_srl); $this->assertEquals(3, $lg->category->list_order); $this->assertEquals(self::CATEGORY_NOKIA, $nokia->category->category_srl); $this->assertEquals(4, $nokia->category->list_order); }