Ejemplo n.º 1
0
	/**
	 * Test product category tree as flat structure
	 * Used for UI, when printing nested lists
	 *
	 * @return void
	 */
	public function testCategoryFlatTreeHierarchy()
	{
		// Retrieve tree
		$repository = new CategoryRepository();

		$tree = $repository->getCategoriesTree(1001);
		$flat_tree = $tree->toFlatStructure();
//		foreach($flat_tree as $node)
//		{
//			echo $node->depth . ' ' . $node->category->category_srl . PHP_EOL;
//		}

		// Test flat structure
		$this->assertTrue(is_array($flat_tree));
		$this->assertEquals(4, count($flat_tree));

		$this->assertEquals(1000, $flat_tree[0]->category->category_srl);
		$this->assertEquals(0, $flat_tree[0]->depth);
		$this->assertEquals(1002, $flat_tree[1]->category->category_srl);
		$this->assertEquals(1, $flat_tree[1]->depth);
		$this->assertEquals(1008, $flat_tree[2]->category->category_srl);
		$this->assertEquals(1, $flat_tree[2]->depth);
		$this->assertEquals(1006, $flat_tree[3]->category->category_srl);
		$this->assertEquals(0, $flat_tree[3]->depth);
	}
    /**
     * 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);

    }
Ejemplo n.º 3
0
	/**
	 * Shop display product tool page
	 */
	public function dispShopToolManageProducts(){
		$module_srl = $this->module_info->module_srl;

		$args = new stdClass();
		$args->module_srl = $module_srl;

        if ($search = Context::get('search')) {
            $col = (Context::get('column') ? Context::get('column') : 'title');
            $args->$col = $search;
        }
        if ($cat_srl = Context::get('category_srl')) {
            if (!is_numeric($cat_srl)) throw new ShopException('invalid category srl');
            $cat = new Category($cat_srl);
            Context::set('filterCategory', $cat);
            $args->category_srls = array($cat_srl);
        }

        if ($page = Context::get('page')) $args->page = $page;

        Context::set('column_filters', array('title', 'description'));

        $pRepo = new ProductRepository();
        $output = $pRepo->getProductList($args);
        Context::set('product_list', $output->products);
        Context::set('page_navigation', $output->page_navigation);

        $category_repository = new CategoryRepository();
        $tree = $category_repository->getCategoriesTree($module_srl);
        $flat_tree = $tree->toFlatStructure();

        Context::set('productsCount', $pRepo->count('countProducts', array('module_srl' => $module_srl)));

        Context::set('category_list', $flat_tree);
    }