public static function setValuesForTemplate($module_srl)
 {
     $productRepo = new ProductRepository();
     $maxPrice = $productRepo->getMaxPrice($module_srl);
     $minPrice = 0;
     $priceFilter = array($minPrice, Context::get(self::TO_PRICE_MIN) ? Context::get(self::TO_PRICE_MIN) : $minPrice, Context::get(self::TO_PRICE_MAX) ? Context::get(self::TO_PRICE_MAX) : $maxPrice, $maxPrice);
     Context::set('priceFilter', $priceFilter);
     $attributeRepo = new AttributeRepository();
     $catSrls = array();
     if (is_numeric($catSrl = Context::get('category_srl'))) {
         $catSrls[] = $catSrl;
     } elseif (Context::get('type') == 'category' && ($slug = Context::get('identifier'))) {
         //friendly url
         $cRepo = new CategoryRepository();
         $cat = $cRepo->getCategoryByFriendlyUrl($slug);
         $catSrls[] = $cat->category_srl;
     }
     $attrs = $attributeRepo->getFilterAttributes($module_srl, $catSrls);
     foreach ($attrs as $i => $attribute) {
         /** @var $attribute Attribute */
         if ($attribute->isNumeric()) {
             $min = $attribute->getMinValue();
             $min |= 0;
             //if there is no max value for this attribute unset it
             if (!($max = (int) $attribute->getMaxValue())) {
                 unset($attrs[$i]);
                 continue;
             }
             $attribute->setMeta('min', $min);
             $attribute->setMeta('max', $max);
             $minKey = str_replace('SRL', $attribute->attribute_srl, self::TO_ATTRIBUTE_NUMERIC_MIN);
             if (isset($_GET[$minKey]) && is_numeric($minValue = $_GET[$minKey])) {
                 $attribute->setMeta('minValue', $minValue);
             }
             $maxKey = str_replace('SRL', $attribute->attribute_srl, self::TO_ATTRIBUTE_NUMERIC_MAX);
             if (isset($_GET[$maxKey]) && is_numeric($maxValue = $_GET[$maxKey])) {
                 $attribute->setMeta('maxValue', $maxValue);
             }
         } elseif ($attribute->isSelect()) {
             $key = str_replace('SRL', $attribute->attribute_srl, self::TO_ATTRIBUTE_SELECT);
             if (isset($_GET[$key]) && ($val = $_GET[$key])) {
                 $attribute->setMeta('filterValue', $val);
             }
         } elseif ($attribute->isMultipleSelect()) {
             $key = str_replace('SRL', $attribute->attribute_srl, self::TO_ATTRIBUTE_SELECT_MULTIPLE);
             if (isset($_GET[$key]) && ($val = $_GET[$key])) {
                 $values = explode(self::SEPARATOR_MULTIPLE, $val);
                 $attribute->setMeta('filterValues', $values);
             }
         }
     }
     Context::set('filter_attributes', $attrs);
 }
 /**
  * Test when getting products from multiple categories.
  */
 public function testGettingProductsFromMultipleCategories()
 {
     /**
      * @var $rootCategory CategoryInterface
      */
     $rootCategory = $this->categoryRepository->findOneBy(['slug' => 'root-category']);
     $category = $this->categoryRepository->findOneBy(['slug' => 'category']);
     $products = $this->productRepository->getAllFromCategories([$rootCategory, $category]);
     $this->assertCount(3, $products, 'It should only return one product on the root category');
 }
 /**
  * Remove the specified Category from storage.
  *
  * @param  int $id
  *
  * @return Response
  */
 public function destroy($id)
 {
     $category = $this->conceptocategoryRepository->find($id);
     if (empty($category)) {
         Flash::error('Category not found');
         return redirect(route('conceptos.categorias.index'));
     }
     $this->conceptocategoryRepository->delete($id);
     Flash::success('Category deleted successfully.');
     return redirect(route('conceptos.categorias.index'));
 }
 public static function getfood($food_id)
 {
     global $db;
     $query = "SELECT * FROM foods WHERE foodID = {$food_id}";
     $result = $db->query($query);
     $row = $result->fetch();
     $category = CategoryRepository::getCategory($row['categoryID']);
     $food = new Food($row['calories'], $row['foodTitle'], $row['foodPrice'], $category);
     $food->setId($row['foodID']);
     return $food;
 }
 /**
  * {@inheritdoc}
  */
 public function move($categoryId, $parentId, $afterId = null)
 {
     $model = $this->categoryRepository->get($categoryId);
     $parentCategory = $this->categoryRepository->get($parentId);
     if ($parentCategory->hasChildren()) {
         $parentChildren = $parentCategory->getChildren();
         $categoryIds = explode(',', $parentChildren);
         $lastId = array_pop($categoryIds);
         $afterId = $afterId === null || $afterId > $lastId ? $lastId : $afterId;
     }
     if (strpos($parentCategory->getPath(), $model->getPath()) === 0) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Operation do not allow to move a parent category to any of children category'));
     }
     try {
         $model->move($parentId, $afterId);
     } catch (\Exception $e) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Could not move category'));
     }
     return true;
 }
 public function destroy($id)
 {
     $this->repository->delete($id);
     return redirect()->route('admin.clients.index');
 }
Beispiel #7
0
<?php

/*
 * Student Info: Name=Tsai-Chang Mai, ID=10010
 * Subject: CS526(C)_HW5_Spring_2016
 * Author: Arvin-tcm 
 * Filename: list_foods.php 
 * Date and Time: Mar 24, 2016 4:29:17 PM 
 * Project Name: TsaiChangMai_10010_CS526A_HW5 
 */
$category_id = 1;
if (isset($_GET['category_id'])) {
    $category_id = $_GET['category_id'];
}
$categories = CategoryRepository::getCategories();
$category = CategoryRepository::getCategory($category_id);
$foods = FoodRepository::getFoodsByCategory($category_id);
return 'views/manage_food_list_view.php';
Beispiel #8
0
 public function update()
 {
     $this->repository->flush();
 }
 public function update(AdminCupomRequest $request, $id)
 {
     $data = $request->all();
     $this->repository->update($data, $id);
     return redirect()->route('admin.cupoms.index');
 }
Beispiel #10
0
	/**
	 * Frontend shop product page
	 */
	public function dispShopProduct()
	{
        /** @var $product Product */
        if ($product = Context::get('product')) {
            //came from from routing
            if (!($product instanceof Product) || !$product->isPersisted()) throw new ShopException('Wrong product');
        }
		else {
            if (!$product_srl = Context::get('product_srl')) throw new ShopException('Could not identify product');
            $product_repository = new ProductRepository();
            $product = $product_repository->getProduct($product_srl);
            if (!$product instanceof Product) throw new ShopException('Product does not exist');
            Context::set('product', $product);
        }

        //add product document if it does not exist  (link to comments)
        if(!isset($product->document_srl)){
            $documentController = getController('document');
            $document = new stdClass();
            $document->title = $product->product_srl;
            $document->commentStatus = 'ALLOW';
            $document->module_srl = $product->module_srl;
            $output = $documentController->insertDocument($document);
            $product->document_srl = $output->variables['document_srl'];
            unset($product->images);
            $product->repo->updateProduct($product);
        }
        $documentModel = getModel('document');
        $product->document = $documentModel->getDocument($product->document_srl);
        $product->comment_list = $_comment_list = $product->document->getComments();
        if (is_array($_comment_list)) {
            foreach ($product->comment_list as $comment){
                $comment->variables['relativeDate'] = $this->model->zdateRelative($comment->getRegdateTime());
            }
        }

		// Setup Javscript datasource for linked dropdowns
		$datasourceJS = $this->getAssociatedProductsAttributesAsJavascriptArray(array($product));
		Context::set('datasourceJS', $datasourceJS);

		// Setup attributes names for display
		if(count($product->attributes))
		{
			$attribute_repository = new AttributeRepository();
			$attributes = $attribute_repository->getAttributes(array_keys($product->attributes));
			Context::set('attributes', $attributes);
		}

		// Categories left tree
		// Retrieve existing categories
		$category_repository = new CategoryRepository();
		$tree = $category_repository->getNavigationCategoriesTree($this->module_srl);

		// Prepare tree for display
		$tree_config = new HtmlCategoryTreeConfig();
		$tree_config->linkCategoryName = TRUE;
		$tree_config->linkGetUrlParams = array('vid', $this->mid, 'act', 'dispShop');
		$tree_config->selected = $product->categories;
		$HTML_tree = $tree->toHTML($tree_config);
		Context::set('HTML_tree', $HTML_tree);

        $this->loadShopCategoryTree();

		$this->setTemplateFile('product.html');
	}
Beispiel #11
0
<?php

include_once ROOT_PATH . "system/models/category.class.php";
include_once ROOT_PATH . "system/repository/category_repository.class.php";
$category_repository = new CategoryRepository();
if (isset($_GET['id']) && isset($_GET['action']) && $_GET['action'] == 'delete') {
    $category_repository->delete($_GET['id']);
    header("location:index.php");
}
?>


<?php 
if (isset($_GET['success']) && $_GET['success'] == "true") {
    ?>
<div class="alert alert-success alert-dismissible fade in" role="alert">
      <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
      <strong>Holy guacamole!</strong> Best check yo self, you're not looking too good.
</div>
<?php 
}
?>

<div class="pull-right">
	<a href="index.php?page=aenquiry&m=add" class="btn btn-primary">Add Enquiry</a>
</div>



<div class="row">
<table class="table table-stripped table-hover">
    /**
     * 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);

    }
		public function testProductCountUpdatesOnProductUpdate()
		{
			$module_srl = 1001;

			$product_repository = new ProductRepository();

			$product = new SimpleProduct();
			$product->product_srl = 12;
			$product->title = "Some product";
			$product->member_srl = 4;
			$product->module_srl = $module_srl;
			$product->product_type = 'simple';
			$product->sku = 'some-product';
			$product->friendly_url = $product->sku;
			$product->price = 100;
			$product->categories[] = 1000;
			$product->categories[] = 1002;
			$product_repository->insertProduct($product);

			// Check that count was increased
			$category_repository = new CategoryRepository();
			$category = $category_repository->getCategory(1000);
			$this->assertEquals(1, $category->product_count);
			// Check that count was increased
			$category = $category_repository->getCategory(1002);
			$this->assertEquals(1, $category->product_count);
			// Check that count was increased
			$category = $category_repository->getCategory(1008);
			$this->isNull($category->product_count);

			// Delete product
			$args = new stdClass();
			$args->module_srl = $module_srl;
			$products = $product_repository->getAllProducts($args);
			$this->assertNotNull($products);

			$product = array_shift($products);
			$product->categories = array(1002, 1008);
			$product_repository->updateProduct($product);

			// Check that count was decreased
			$category_repository = new CategoryRepository();
			$category = $category_repository->getCategory(1000);
			$this->assertEquals(0, $category->product_count);
			// Check that count was decreased
			$category = $category_repository->getCategory(1002);
			$this->assertEquals(1, $category->product_count);
			// Check that count was increased
			$category = $category_repository->getCategory(1008);
			$this->assertEquals(1, $category->product_count);
		}
Beispiel #14
0
 /**
  * Display a listing of the categories.
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $categories = $this->categoryRepository->getPaginated($request);
     return view('Admin::category.index', ['categories' => $categories]);
 }
 /**
  * Returns Attributes displayable for a specific category / set of categories, or for no category.
  *
  * @param $module_srl
  * @param array $category_srls
  * @param bool $withParents takes categories parents into account
  * @return mixed
  * @throws ShopException
  */
 public function getFilterAttributes($module_srl, array $category_srls = null, $withParents = true)
 {
     if (!is_numeric($module_srl)) {
         throw new ShopException('module_srl must be a valid natural number');
     }
     $catSerials = array();
     if ($withParents && !empty($category_srls)) {
         $cRepo = new CategoryRepository();
         $paths = $cRepo->getCategoryPaths($category_srls);
         foreach ($paths as $srl => $path) {
             $catSerials = array_merge($catSerials, $path, array($srl));
         }
     } else {
         $catSerials = $category_srls;
     }
     $params = array('module_srl' => $module_srl);
     if (!empty($catSerials)) {
         $params['category_srls'] = $catSerials;
     }
     $aRepo = new AttributeRepository();
     $attributes = $aRepo->get(null, 'getCategoriesAttributeFilters', null, $params);
     return $attributes;
 }
Beispiel #16
0
 /**
  * @return RouteEntity
  */
 public function getCategoryEntity()
 {
     return $this->key ? $this->categoryRepository->find($this->key) : NULL;
 }
Beispiel #17
0
<?php

/*
 * Student Info: Name=Tsai-Chang Mai, ID=10010
 * Subject: CS526(C)_HW5_Spring_2016
 * Author: Arvin-tcm 
 * Filename: view_food.php 
 * Date and Time: Mar 24, 2016 4:35:07 PM 
 * Project Name: TsaiChangMai_10010_CS526A_HW5 
 */
$food_id = 1;
if (isset($_GET['food_id'])) {
    $food_id = $_GET['food_id'];
}
$categories = CategoryRepository::getCategories();
$food_id = $_GET['food_id'];
$food = FoodRepository::getFood($food_id);
return 'views/food_view.php';
        /**
         * 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);
        }
 public function edit($id)
 {
     $client = $this->repository->find($id);
     return view('admin.clients.edit', compact('client'));
 }
Beispiel #20
0
<?php

include "../models/CategoryRepository.php";
$config = (include "../db/config.php");
$db = new PDO($config["db"], $config["username"], $config["password"]);
$db->exec("set names utf8");
$category = new CategoryRepository($db);
switch ($_SERVER["REQUEST_METHOD"]) {
    case "GET":
        $result = $category->getAll();
        break;
}
header("Content-Type: application/json");
echo json_encode($result);