<?php

/**
 * product actions.
 *
 * @package    sf
 * @subpackage product
 * @author     Atma
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class productActions extends sfActions
{
    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
    public function executeIndex(sfWebRequest $request)
    {

    }
    public function executeShow(sfWebRequest $request)
    {
        $product = $this->getRoute()->getObject();
        $this->forward404Unless(!$product->getIsDelete() && $product->getOfferCount() > 0);
        if(!$product->getIsDetail()){
            $cats = $product->getCats();
            if(count($cats) > 0){
                $this->redirect('@catalog_show?alias=' . $cats[0]['alias'] . '&sf_culture=' . $this->getUser()->getCulture());
            }
        }
        $this->forward404Unless($product->getIsDetail());
        $this->culture = $this->getUser()->getCulture();
        $this->basket_id = $this->getUser()->getAttribute('basket_id');

        $this->product = Doctrine_Query::create()
            ->select("p.*, c.*, ct.*, o.*, ppv.*, pp.*, ppl.*, t.*, to.*, tpp.*, bo.*")
            ->from('Product p')
            ->leftJoin('p.Cats c')
            ->leftJoin("c.Translation ct")
            ->leftJoin('p.Offer o WITH o.is_delete = 0')
            ->leftJoin('o.BasketOffer bo WITH bo.basket_id = ?', $this->basket_id)
//            ->leftJoin('(SELECT * FROM Product cp LEFT JOIN Offer co ON co.id = cp.product_id WHERE co.is_delete = 0 ORDER BY co.sort ASC ) o ON o.id = p.product_id')
            ->leftJoin('p.ProductPropValue ppv')
            ->leftJoin('ppv.ProductProp pp')
            ->leftJoin('pp.ProductPropList ppl')
            ->innerJoin('p.Translation t WITH t.lang = \'' . $this->culture . '\'')
            ->leftJoin('o.Translation to WITH to.lang = \'' . $this->culture . '\'')
            ->leftJoin('pp.Translation tpp WITH tpp.lang = \'' . $this->culture . '\'')
            ->leftJoin('ppl.Translation tppl WITH tppl.lang = \'' . $this->culture . '\'')
            ->andWhere('p.id = ?', $product->getId())
            ->andWhere("p.is_delete = 0")
            ->orderBy('o.sort asc')
            ->fetchOne();


        $this->setLayout('layoutPage');

    }
}
