<commit_before><?php

namespace Store\FrontBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller
{
    /**
     * @Route("/", name="homeweb")
     * @Template()
     */
    public function indexAction()
    {
        $em = $this->getDoctrine()->getManager();

        $man = $this->get('store.store_manager');

        $masterVariants = $man->getMasterVariants(null, 20);

        $cart = $man->getCart();

        return array(
            'cart'  =>  $cart,
            'products'  =>  $masterVariants,
        );
    }

    /**
     * @Route("catalog/product/{id}/{slug}", name="product_front_show", defaults={"slug"=null})
     * @Template()
     */
    public function showProductFrontAction($id, $slug)
    {
        $manager = $this->get('store.store_manager');

        $variant = $manager->getVariant($id);
        $product = $manager->getProductForVariant($variant->getProduct()->getId());

        if(!$product){
            throw new \InvalidArgumentException("The product does not exist");
        }

        return array(
            'variant'   => $variant,
            'product'   =>  $product
        );
    }

    /**
     * @Template()
     */
    public function showMiniCartAction()
    {
        $em = $this->getDoctrine()->getManager();
        $repo = $em->getRepository('StoreProductBundle:Promotion');
        $promotions = $repo->findIfActual();
        $promotion = array();

        $storeManager = $this->get('store.store_manager');
        $cart = $storeManager->getCart();
        $total = 0;
        foreach ($cart->getItems() as $item) {
            $total = $total + ($item->getProduct()->getPrice() * $item->getQuantity());
        }

        if ($total !== 0){
        foreach($promotions as $pro){
            $promotion['detail'] = $pro;
            $promotion['discount_amount'] = (($total / 100) * $pro->getDiscount());
            $promotion['new_total'] = $total - $promotion['discount_amount'];
            break;
        }
        }

        return array(
            'cart'  =>  $cart,
            'total' => $total,
            'promotion' => $promotion,
        );
    }

    /**
     * @Template()
     */
    public function getCategoryMenuAction()
    {
        $man = $this->get('store.store_manager');
        $parcours = $man->getCategoriesWithChildren();
        $categories = $man->getCategories(true);
        $htmlTree = $man->getMyTree();

        return array(
            'categories' => $categories,
            'htmlTree'  => $htmlTree,
        );
    }

    /**
     * @Route("/catalog/category/{id}/{slug}", name="category_page")
     * @Template()
     */
    public function categoryAction($id, $slug)
    {
        $man = $this->get('store.store_manager');
        $categories = $man->getCategories(true);
        $htmlTree = $man->getMyTree();

        $category = $man->getCategory($id);
        if (!$category){
            throw new \InvalidParameterException('The category does not exist');
        }
        $products = $man->getProductsForCategory($id);
        return array(
            'category' => $category,
            'products' => $products,
            'categories' => $categories,
            'htmlTree' => $htmlTree,
        );
    }
<commit_msg>BC compat for category page<commit_after><?php

namespace Store\FrontBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller
{
    /**
     * @Route("/", name="homeweb")
     * @Template()
     */
    public function indexAction()
    {
        $em = $this->getDoctrine()->getManager();

        $man = $this->get('store.store_manager');

        $masterVariants = $man->getMasterVariants(null, 20);

        $cart = $man->getCart();

        return array(
            'cart'  =>  $cart,
            'products'  =>  $masterVariants,
        );
    }

    /**
     * @Route("catalog/product/{id}/{slug}", name="product_front_show", defaults={"slug"=null})
     * @Template()
     */
    public function showProductFrontAction($id, $slug)
    {
        $manager = $this->get('store.store_manager');

        $variant = $manager->getVariant($id);
        $product = $manager->getProductForVariant($variant->getProduct()->getId());

        if(!$product){
            throw new \InvalidArgumentException("The product does not exist");
        }

        return array(
            'variant'   => $variant,
            'product'   =>  $product
        );
    }

    /**
     * @Template()
     */
    public function showMiniCartAction()
    {
        $em = $this->getDoctrine()->getManager();
        $repo = $em->getRepository('StoreProductBundle:Promotion');
        $promotions = $repo->findIfActual();
        $promotion = array();

        $storeManager = $this->get('store.store_manager');
        $cart = $storeManager->getCart();
        $total = 0;
        foreach ($cart->getItems() as $item) {
            $total = $total + ($item->getProduct()->getPrice() * $item->getQuantity());
        }

        if ($total !== 0){
        foreach($promotions as $pro){
            $promotion['detail'] = $pro;
            $promotion['discount_amount'] = (($total / 100) * $pro->getDiscount());
            $promotion['new_total'] = $total - $promotion['discount_amount'];
            break;
        }
        }

        return array(
            'cart'  =>  $cart,
            'total' => $total,
            'promotion' => $promotion,
        );
    }

    /**
     * @Template()
     */
    public function getCategoryMenuAction()
    {
        $man = $this->get('store.store_manager');
        $parcours = $man->getCategoriesWithChildren();
        $categories = $man->getCategories(true);
        $htmlTree = $man->getMyTree();

        return array(
            'categories' => $categories,
            'htmlTree'  => $htmlTree,
        );
    }

    /**
     * @Route("/catalog/category/{id}/{slug}", name="category_page")
     * @Template()
     */
    public function categoryAction($id, $slug)
    {
        $man = $this->get('store.store_manager');
        $categories = $man->getCategories(true);
        $htmlTree = $man->getMyTree();

        $category = $man->getCategory($id);
        if (!$category){
            throw new \InvalidParameterException('The category does not exist');
        }
        $products = $man->getProductsForCategory($id);
        return array(
            'category' => $category,
            'products' => $products,
            'categories' => $categories,
            'htmlTree' => $htmlTree,
        );
    }

    /**
     * @Route("/catalog/{id}/{slug}", name="category_page_old")
     * @Template()
     */
    public function categoryOldAction($id, $slug)
    {
        $man = $this->get('store.store_manager');
        $categories = $man->getCategories(true);
        $htmlTree = $man->getMyTree();

        $category = $man->getCategory($id);
        if (!$category){
            throw new \InvalidParameterException('The category does not exist');
        }
        return $this->redirect($this->generateUrl('category_page', array('id' => $id, 'slug' => $category->getSlug())));
    }

{'fraction_non_alphanumeric': 0.1664454473055482, 'fraction_numerical': 0.0018582426333952748, 'mean_word_length': 2.221462163317657, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 98, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6267750', 'n_tokens_mistral': 2179, 'n_tokens_neox': 2140, 'n_words': 370}