SiteController.php 7.79 KB
<?php

namespace frontend\controllers;

use common\modules\product\models\Category;
use Yii;
use yii\web\Controller;
use common\models\Page;
use common\models\News;
use common\models\Catalog;
use common\models\Products;

class SiteController extends Controller
{
    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'thumb' => 'iutbay\yii2imagecache\ThumbAction',
        ];
    }

    public function actionIndex()
    {

//            $catalogs = Catalog::find()->where(['parent_id'=>'0'])->all();
        $modelText = Page::find()->where(['translit'=>'home'])->one();
//            $news = News::find()->orderBy('id DESC')->limit(4)->all();
//            $products_new = Products::find()->where(['new'=>'1'])->orderBy('id DESC')->innerJoinWith(['cost'])->groupBy('id')->limit(4)->all();
//            //print_r($products_new);
//            $products_top = Products::find()->where(['top'=>'1'])->orderBy('id DESC')->innerJoinWith(['cost'])->groupBy('id')->limit(4)->all();
//            //print_r($products_top);
//            //$products_sale = Products::find()->where(['sale'=>'1'])->innerJoinWith(['cost'])->orderBy('id DESC')->limit(4)->all();
//            $products_akciya = Products::find()->where(['akciya'=>'1'])->innerJoinWith(['cost'])->orderBy('id DESC')->limit(4)->all();
        return $this->render('index', [
            'text'=>$modelText,
//                    'catalogs'=>$catalogs,
//                    'news'=>$news,
//                    'products_new'=>$products_new,
//                    'products_top'=>$products_top,
//                    'products_akciya'=>$products_akciya,
        ]);
    }

    public function actionError(){

        return $this->render('error', [
            'code'=>Yii::$app->errorHandler->exception->statusCode,
            'message'=>Yii::$app->errorHandler->exception->getMessage(),
        ]);
    }

    public function actionPriceparam ()
    {
        if (! $catalog = Category::find ()
            ->where (['translit' => $_GET['translit']])
            ->with ('parent')
            ->one ()
        )
        {
            throw new HttpException(404, 'Данной странице не существует!');
        }

        //var_dump();die;

        $products = Products::find ()->where (['catalog_id' => $catalog->id])->all();
        if (isset($_GET['count'])){

            print (count($products));die;

        }
//var_dump($products);die();
        set_time_limit (0);
        header ("Content-Type: text/xml");
        print '<?xml version="1.0" encoding="UTF-8" ?>';
        print "<price>";
        print "<date>" . date ("Y-m-d h:m") . "</date>";
        print "<firmName>Rukzachok</firmName>";
        print "<firmId></firmId>";
        print "<rate></rate>";
        print "<categories>";

        print "<category>";
        print "<id>" . $catalog->id . "</id>";
        print "<parentId></parentId>";
        print "<name>" . $catalog->name . "</name>";
        print "</category>";


        print "</categories>";
        print "<items>";
        foreach ($products as $product)
        {
            $color = Mod::find()->where ('
                (onstock_status_id > 0  OR is_always_active > 0)
                    AND cost > 0
                    AND status = 1
				')->where(['product_id' => $product->id])->all();

            $brend = Brends::find()->where(['id' => $product->brend_id])->one();
            //$brends = Brends::find()->orderBy('sort ASC')->all();

            //var_dump($brend);die;

            foreach($color as $v) {

                $col =  $v['color'];
                $pr =  $v['cost'];
                $old_pr =  $v['old_cost'];
                print "<item>";
                print "<id>" . htmlspecialchars ($v['id']) . "</id>";
                print "<categoryId>" . htmlspecialchars ($product->catalog_id) . "</categoryId>";
                print "<vendor>".$brend['name']."</vendor>";
                print "<code>" . htmlspecialchars ($v['art']) . "</code>";
                print "<typeprefix>" . htmlspecialchars (substr($catalog->name, 0,-2)) ." </typeprefix>";
                print "<name>" . htmlspecialchars ($product->name) ."  </name>";
                print "<param>".  $col . " </param>";
                print "<description>" . htmlspecialchars ($product->body_ru) . "</description>";
                print "<url>http://rukzachok.com.ua/products/" . htmlspecialchars ($_GET['translit']) . "/" . htmlspecialchars ($product->translit). "</url>";
                print "<image>http://rukzachok.com.ua/upload/mod/big/" . $v['image'] . "</image>";
                print "<priceRUAH>" . $pr . "</priceRUAH>";
                print "<oldprice>" . $old_pr . "</oldprice>";
                print "<priceRUSD></priceRUSD>";
                print "<stock>В наличии</stock>";
                print "<guarantee></guarantee>";
                print "</item>";

            }
        }


        print "</items>";

        print "</price>";


    }

    public function actionPrice()
    {

        if (! $catalog = Category::find ()
            ->where (['translit' => $_GET['translit']])
            ->with ('parent')
            ->one ()
        )
        {
            throw new HttpException(404, 'Данной странице не существует!');
        }



        $products = Products::find ()->where (['catalog_id' => $catalog->id])->all();
        if (isset($_GET['count'])){

            print (count($products));die;

        }
//var_dump($products);die();
        set_time_limit (0);
        header ("Content-Type: text/xml");
        print '<?xml version="1.0" encoding="UTF-8" ?>';
        print "<price>";
        print "<date>" . date ("Y-m-d h:m") . "</date>";
        print "<firmName>Rukzachok</firmName>";
        print "<firmId></firmId>";
        print "<rate></rate>";
        print "<categories>";

        print "<category>";
        print "<id>" . $catalog->id . "</id>";
        print "<parentId></parentId>";
        print "<name>" . $catalog->name . "</name>";
        print "</category>";

        print "</categories>";
        print "<items>";
        foreach ($products as $product)
        {
            $color = Mod::find()->where ('
                (onstock_status_id > 0  OR is_always_active > 0)
                    AND cost > 0
                    AND status = 1
				')->where(['product_id' => $product->id])->all();

            $brend = Brends::find()->where(['id' => $product->brend_id])->one();
            //$brends = Brends::find()->orderBy('sort ASC')->all();

            //var_dump($brend);die;

            foreach($color as $v) {

                $col =  $v['color'];
                $pr =  $v['cost'];
                $old_pr =  $v['old_cost'];

                print "<item>";
                print "<id>" . htmlspecialchars ($v['id']) . "</id>";
                print "<categoryId>" . htmlspecialchars ($product->catalog_id) . "</categoryId>";
                print "<vendor>".$brend['name']."</vendor>";
                print "<code>" . htmlspecialchars ($v['art']) . "</code>";
                print "<name>" . htmlspecialchars ($product->name) ." ".  $col . " </name>";
                print "<description>" . htmlspecialchars ($product->body_ru) . "</description>";
                print "<url>http://rukzachok.com.ua/products/" . htmlspecialchars ($_GET['translit']) . "/" . htmlspecialchars ($product->translit) . "</url>";
                print "<image>http://rukzachok.com.ua/upload/mod/big/" . $v['image'] . "</image>";
                print "<priceRUAH>" . $pr . "</priceRUAH>";
                print "<oldprice>" . $old_pr . "</oldprice>";
                print "<priceRUSD></priceRUSD>";
                print "<stock>В наличии</stock>";
                print "<guarantee></guarantee>";
                print "</item>";

            }
        }


        print "</items>";

        print "</price>";


    }


}