actions.class.php 4.6 KB
Newer Older
Яков's avatar
first  
Яков committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?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');

Яков's avatar
test    
Яков committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
        if ($this->getUser()->hasAttribute('number_of_views') && $this->getUser()->getAttribute('number_of_views') != false) {
            $number_of_view = $this->getUser()->getAttribute('number_of_views');
            if ($this->getUser()->getAttribute('number_of_views') < 10) {
                if (!$this->getUser()->hasAttribute('ids_view_product') || $this->getUser()->getAttribute('ids_view_product') == false) {
                    $this->getUser()->setAttribute('ids_view_product', $this->product['id'] . ';');
                } else {
                    $str_ids = $this->getUser()->getAttribute('ids_view_product');
                    $ids = explode(';', $str_ids);
                    if (!in_array($this->product['id'], $ids)) {
                        $number_of_view++;
                        $this->getUser()->setAttribute('number_of_views', $number_of_view);
                        $this->getUser()->setAttribute('ids_view_product', $str_ids . $this->product['id'] . ';');
                    }
                }
            }
            if ($number_of_view == 5 || $number_of_view == 7 || $number_of_view == 10) {
                if ($this->getUser()->hasAttribute('phone_number') && $this->getUser()->getAttribute('phone_number') != false) {
                    $date_now = new DateTime('now');
                    $date_limit = new DateTime('now');
                    $date_limit->modify('-30 day');
                    $phone_discount = Doctrine_Query::create()
                        ->select()
                        ->from('DiscountPhone dp')
                        ->where('dp.phone = ?', $this->getUser()->getAttribute('phone_number'))
                        ->andWhere('dp.order_id is null')
                        ->andWhere('dp.created_at BETWEEN STR_TO_DATE(\'' . $date_limit->format('Y-m-d H:i:s') . '\', \'%Y-%m-%d %H:%i:%s\') AND STR_TO_DATE(\'' . $date_now->format('Y-m-d H:i:s') . '\', \'%Y-%m-%d %H:%i:%s\')')
                        ->execute();
                    if (count($phone_discount) > 0) {
                        $phone_discount = $phone_discount->getFirst();
                        $phone_discount->setActiveDiscount($number_of_view);
                        $phone_discount->save();
                        $this->getUser()->setAttribute('active_discount', $number_of_view);
                    }
                }
            }
        }
Яков's avatar
first  
Яков committed
95
96
    }
}