Permalink
Browse files

catalog with category list and category content

  • Loading branch information...
1 parent c7ed631 commit c2d03e970fabccf9df6be5fe3f2d74cb1245a45b @havvg committed Sep 9, 2011
@@ -1,3 +1,7 @@
+_catalog:
+ resource: "@AcmeDemoBundle/Controller/CatalogController.php"
+ type: annotation
+
_welcome:
pattern: /
defaults: { _controller: AcmeDemoBundle:Welcome:index }
@@ -0,0 +1,2 @@
+_main:
+ resource: routing_dev.yml
@@ -0,0 +1,49 @@
+<?php
+
+namespace Acme\DemoBundle\Controller;
+
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
+
+use Acme\DemoBundle\Entity\Category;
+
+use \Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+
+class CatalogController extends Controller
+{
+ /**
+ * @Route("/categories", name="_catalog_categories")
+ * @Template()
+ */
+ public function categoriesAction()
+ {
+ $categories = $this->getDoctrine()
+ ->getRepository('AcmeDemoBundle:Category')
+ ->findAll();
+
+ return array(
+ 'categories' => $categories,
+ );
+ }
+
+ /**
+ * @Route("/catagories/{name}", name="_catalog_category_content")
+ * @Template()
+ */
+ public function categoryContentAction($name)
+ {
+ $category = $this->getDoctrine()
+ ->getRepository('AcmeDemoBundle:Category')
+ ->findOneByName($name);
+
+ if (!$category instanceof Category) {
+ throw new NotFoundHttpException(sprintf('The category "%s" could not be found.', $name));
+ }
+
+ return array(
+ 'products' => $category->getProducts()
+ );
+ }
+}
@@ -0,0 +1,30 @@
+Feature: Navigating the categories within the catalog
+ In order to view the products within the catalog
+ As a visitor
+ I want to browse the categories
+
+ Background:
+ Given There is no "Product" in database
+ And There is no "Category" in database
+ And I have a category "Underwear"
+ And I have a category "Shoes"
+
+ Scenario: The categories are being listed
+ Given I am on "/categories"
+ Then I should see a "ul#category-list" element
+ And I should see "Shoes" in the "#category-list" element
+ And I should see "Underwear" in the "#category-list" element
+
+ Scenario: The categories link to their products list
+ Given I am on "/categories"
+ And I have a product "Calvin Klein Black, 5"
+ And I add product "Calvin Klein Black, 5" to category "Underwear"
+ And I have a product "Converse All Star, 8"
+ And I add product "Converse All Star, 8" to category "Shoes"
+ When I follow "Underwear"
+ Then I should see "Calvin Klein Black, 5" in the "#product-list li" element
+ And I should not see "Converse All Star, 8"
+ When I move backward one page
+ And I follow "Shoes"
+ Then I should see "Converse All Star, 8" in the "#product-list li" element
+ And I should not see "Calvin Klein Black, 5"
@@ -0,0 +1,14 @@
+{% extends "AcmeDemoBundle::layout.html.twig" %}
+
+{% block title "Catalog - Category List" %}
+
+{% block content_header '' %}
+
+{% block content %}
+ <h1>Category List</h1>
+ <ul id="category-list">
+ {% for category in categories %}
+ <li><a href="{{ path('_catalog_category_content', {'name': category.name}) }}">{{ category.name }}</a></li>
+ {% endfor %}
+ </ul>
+{% endblock %}
@@ -0,0 +1,14 @@
+{% extends "AcmeDemoBundle::layout.html.twig" %}
+
+{% block title "Catalog - Product List" %}
+
+{% block content_header '' %}
+
+{% block content %}
+ <h1>Product List</h1>
+ <ul id="product-list">
+ {% for product in products %}
+ <li>{{ product.name }}</li>
+ {% endfor %}
+ </ul>
+{% endblock %}

0 comments on commit c2d03e9

Please sign in to comment.