Commit 48680c56 authored by Яков's avatar Яков
Browse files

first

parents
<?php
/**
* article actions.
*
* @package sf
* @subpackage article
* @author Atma
* @version SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
*/
class articleActions extends sfActions
{
public function executeIndex(sfWebRequest $request)
{
$this->culture = $this->getUser()->getCulture();
$this->articles = Doctrine_Query::create()
->select("a.id, a.alias, a.cover, a.created_at, t.*")
->from("Article a")
->innerJoin("a.Translation t")
->where("t.lang = ?", $this->culture)
->andWhere("t.available = 1")
->orderBy("a.created_at DESC")
->fetchArray();
$count_articles = count($this->articles);
if ($request->getParameter('tag_id'))
{
$this->tag_id = $request->getParameter('tag_id');
}else
{
$this->tag_id = 'all';
}
$tags = Doctrine_Query::create()
->select('t.*, tt.*, at.*')
->from('Tag t')
->leftJoin('t.Translation tt WITH tt.lang = ?', $this->culture)
->leftJoin('t.ArticleTags at WITH at.tag_id = t.id')
->fetchArray();
$this->articles_tags = array();
foreach ($tags as $tag)
{
if (count($tag['ArticleTags']) > 0 )
{
$this->articles_tags[] = $tag;
}
}
if ($request->getParameter('tag_id') && $request->getParameter('tag_id') != 'all' && $count_articles >= sfConfig::get('app_view_count_tag')) {
$articles = Doctrine_Query::create()
->select('')
->from('Tag t')
->where('t.id = ?', $request->getParameter('tag_id'))
->leftJoin('t.ArticleTags at WITH t.id = at.tag_id')
->leftJoin('at.Article a WITH at.article_id = a.id')
->innerJoin("a.Translation ta")
->andwhere("ta.lang = ?", $this->culture)
->andWhere("ta.available = 1")
->orderBy("a.created_at DESC")
->fetchArray();
$this->articles = array();
foreach ($articles[0]['ArticleTags'] as $article) {
$this->articles[] = $article['Article'];
}
$this->forward404Unless($this->articles);
}
if ($request->getParameter('tag_id') && $request->getParameter('ajax'))
{
sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');
echo include_partial('article/article', array('articles' => $this->articles, 'die' => true));
}
}
public function executeShow(sfWebRequest $request)
{
$alias = trim(strip_tags($request->getParameter('alias')));
$this->forward404Unless($alias);
$this->culture = $this->getUser()->getCulture();
$this->article = Doctrine_Query::create()
->select("a.*, t.*")
->from("Article a")
->innerJoin("a.Translation t")
->where("a.alias = ?", $alias)
->andWhere("t.lang = ?", $this->culture)
->andWhere("t.available = 1")
->fetchOne();
$this->forward404Unless($this->article);
$this->article_prev = Doctrine_Query::create()
->select("a.*, t.*")
->from("Article a")
->innerJoin("a.Translation t")
->where("t.lang = ?", $this->culture)
->andWhere("t.available = 1")
->andWhere("a.created_at > ?", $this->article->getCreatedAt())
->orderBy("a.created_at ASC")
->fetchOne();
$this->article_next = Doctrine_Query::create()
->select("a.*, t.*")
->from("Article a")
->innerJoin("a.Translation t")
->where("t.lang = ?", $this->culture)
->andWhere("t.available = 1")
->andWhere("a.created_at < ?", $this->article->getCreatedAt())
->orderBy("a.created_at DESC")
->fetchOne();
$this->setLayout('layoutPage');
$this->tags_art = Doctrine_Query::create()
->select('t.id, tt.*')
->from('Tag t')
->innerJoin('t.ArticleTags at WITH at.article_id = ?', $this->article->getId())
->leftJoin('t.Translation tt WITH tt.lang = ?', $this->culture)
->fetchArray();
}
}
<?php
class articleComponents extends sfComponents
{
public function executeArticle(sfWebRequest $request)
{
$this->culture = $this->getUser()->getCulture();
if ($request->getParameter('alias')) {
$productTags = Doctrine::getTable('Product')->findOneByAlias($request->getParameter('alias'))->getProductTags();
$idsTags = array();
foreach ($productTags as $tag) {
$idsTags[] = $tag->getTagId();
}
if (count($idsTags) > 0) {
$q = Doctrine_Query::create()
->select("a.id, a.alias, a.cover, t.id, t.title, t.description, t.lang, t.available")
->from("Article a")
->innerJoin("a.Translation t")
->where("t.lang = ?", $this->getUser()->getCulture())
->andWhere("t.available = 1")
->innerJoin('a.ArticleTags at')
->andWhereIn('at.tag_id', $idsTags);
if (isset($this->limit) && $this->limit) {
$q->limit($this->limit);
}
$this->articles = $q->fetchArray();
} else {
$q = array();
}
}else
{
$this->articles = Doctrine_Query::create()
->select("a.id, a.alias, a.cover, t.id, t.title, t.description, t.lang, t.available")
->from("Article a")
->innerJoin("a.Translation t")
->where("t.lang = ?", $this->getUser()->getCulture())
->andWhere("t.available = 1")
->limit(3)
->fetchArray();
}
}
}
\ No newline at end of file
<?php
$culture = $sf_user->getCulture();
if (isset($articles) && count($articles) > 0) {
$module_action = $sf_request->getParameter('module') . '_' . $sf_request->getParameter('action');
$html = '';
ob_start();
//
// print_r($articles);
// die();
foreach ($articles as $article) {
?>
<div class="articles_item">
<a href="<?php echo url_for('@article_show?alias=' . $article['alias']); ?>" class="anb">
<img src="/i/n.gif" class="articles_item__img" style="background-image: url(/u/i/<?php echo Page::replaceImageSize($article['cover'], 'S'); ?>)"/>
<span class="articles_item__link green_link"><?php echo $article['Translation'][$culture]['title']; ?></span>
<i class="br5"></i>
<span class="articles_item__text black_link"><?php echo $article['Translation'][$culture]['description']; ?></span>
</a>
</div>
<?php
}
$html = ob_get_contents();
ob_end_clean();
if($module_action == 'product_show'){
echo '<div class="product_section product__articles">';
echo '<div class="caption"><a class="green_link" href="/' . $culture . '/article/?tag_id=' . $tag_id . '">' . __('Статьи') . '</a></div>';
echo '<div class="max_width">' . $html . '</div>';
echo '</div>';
}else{
echo $html;
}
}
if ($die)
die();
?>
\ No newline at end of file
<?php
slot('title', __('Читать'));
include_partial('main/breadcrumbs');
echo '<h1 class="content_title">' . __('Читать') . '</h1>';
include_component('main', 'tag');
?>
<div class="article_item_gutter" style="width: 100%; text-align: center">
<?php
if (count($articles) >= sfConfig::get('app_view_count_tag'))
{
echo '<a data-tag-id="all" class="article_show_tag green_link ' . (!$tag_id || $tag_id == 'all' ? 'active' : '') . '">Все</a>';
foreach ($articles_tags as $tag)
{
echo '<a class="article_show_tag green_link ' . ($tag_id == $tag['id'] ? 'active' : '') . '" data-tag-id="' . $tag['id'] . '">' . $tag['Translation'][$culture]['title'] . '</a>';
}
}
?>
</div>
<i class="br20 mobile_hide"></i>
<div class="articles_wrap">
<?php include_partial("article/article", array('articles' => $articles)); ?>
</div>
<script>
var culture = '<?php echo $culture ?>';
$('body').on('click', '.article_show_tag', function () {
//alert('123');
_this = this;
$.ajax({
url: '/' + culture + '/article/',
type: 'get',
data: {tag_id : $(this).attr('data-tag-id'), ajax : 1},
success: function (html) {
$('.article_show_tag').removeClass('active');
$(_this).addClass('active');
$('.articles_wrap').html(html);
setUrlHash('?tag_id='+$(_this).attr('data-tag-id'));
}
});
//alert($(this).attr('data-tag-id'));
});
</script>
\ No newline at end of file
<div class="content__main">
<?php
$translation = $article->getTranslation();
slot('title', $translation[$culture]['title']);
include_partial('main/breadcrumbs');
echo '<h1 class="content_title">' . $translation[$culture]['title'] . '</h1>';
?>
<div class="article_wrap">
<div class="max_width_small">
<?php
$image = '/u/i/' . Page::replaceImageSize($article['cover'], 'M');
if (file_exists(sfConfig::get('sf_web_dir') . $image)) {
$size = getimagesize(sfConfig::get('sf_web_dir') . $image);
echo '<img ' . $size[3] . ' src="/u/i/' . Page::replaceImageSize($article['cover'], 'M') . '" />';
echo '<i class="br30"></i>';
}
echo '<div class="ftext pages">'. $article->getBody(ESC_RAW) .'</div>';
echo '<div style="position: relative">';
$counter = 0;
foreach ($tags_art as $tag)
{
if ($counter == 7)
{
break;
}
$counter++;
echo '<a href="/'.$culture.'/article/?tag_id='.$tag['id'].'" class="art_tags">' . $tag['Translation'][$culture]['title'] . '</a>';
}
echo '</div>';
if ($article_prev || $article_next) {
?>
<table class="article_wrap_arrows" cellspacing="0" cellpadding="0" width="100%">
<tbody valign="middle">
<tr>
<?php
echo '<td class="article_wrap_arrows_left" align="left" width="50%" height="70">';
if ($article_prev) {
echo '<a href="' . url_for('@article_show?alias=' . $article_prev['alias']) . '" class="green_link"><span>' . $article_prev['Translation'][$culture]['title'] . '</span>';
echo '<div class="article_wrap_arrows_left__icon"></div>';
echo '</a>';
}
echo '</td><td class="article_wrap_arrows_right" align="right" width="50%" height="70">';
if ($article_next) {
echo '<a href="' . url_for('@article_show?alias=' . $article_next['alias']) . '" class="green_link"><span>' . $article_next['Translation'][$culture]['title'] . '</span>';
echo '<div class="article_wrap_arrows_right__icon"></div>';
echo '</a>';
}
echo '</td>';
?>
</tr>
</tbody>
</table>
<?php
}
?>
</div>
</div>
<?php
/*
<div class="article_section">
<div class="max-width">
<div class="caption">Вам будут интересны эти товары</div>
<i class="br20"></i>
<div class="lending_product_area product_card_wrap">
<?php include_partial("product/product", array("count" => 4)); ?>
</div>
</div>
</div>
*/
?>
</div>
\ No newline at end of file
<?php
class basketActions extends sfActions
{
private function add($offers, $basket_id)
{
$add_ids = array();
if(is_array($offers) && count($offers) > 0 && $basket_id){
foreach ($offers as $offer_id => $offer_amount){
if(is_numeric($offer_id) && is_numeric($offer_amount) && $offer_amount > 0){
if($offer = Doctrine::getTable("Offer")->findOneByIdAndIsDelete($offer_id, false)){
$basket_offer = Doctrine::getTable("BasketOffer")->findOneByOfferIdAndBasketId($offer->getId(), $basket_id);
$amount = ($basket_offer ? $basket_offer->getAmount() : 0) + $offer_amount;
if(!$basket_offer){
$basket_offer = new BasketOffer();
}
$basket_offer->setBasketId($basket_id);
$basket_offer->setOfferId($offer->getId());
$basket_offer->setAmount($amount);
$basket_offer->setPrice(($offer->getPrice() * $amount));
$basket_offer->save();
$add_ids[] = $offer->getId();
}
}
}
}
return $add_ids;
}
function executeAjaxSetCountProduct(sfWebRequest $request)
{
if ($request->isXmlHttpRequest()) {
$prod_id = $request->getParameter('prod_id');
$value = $request->getParameter('value');
$can_new = $request->getParameter('can_new', false);
$product = Doctrine::getTable('Product')->find($prod_id);
if ($value % $product->getMinOrder() == 0) {
$basket = $this->getUser()->getBasket();
$productsInBasket = $basket->getBasketProduct();
$sets = false;
foreach ($productsInBasket as $productInBasket) {
if ($productInBasket->getProductId() == $prod_id) {
if ($value == 0) {
$productInBasket->delete();
} else {
$productInBasket->setProductCount($value);
$productInBasket->save();
}
$sets = true;
}
}
if (!$sets && $can_new) {
$newBasketProduct = new BasketProduct();
$newBasketProduct->setBasket($basket);
$newBasketProduct->setProduct($product);
$newBasketProduct->setProductCount($value);
$newBasketProduct->save();
}
}
return $this->renderComponent('basket', 'counter');
} else {
$this->forward404();
}
}
function executeAjaxUpOrDownCountProduct(sfWebRequest $request)
{
if ($request->isXmlHttpRequest()) {
$prod_id = $request->getParameter('prod_id');
$operation = $request->getParameter('operation');
$basket = $this->getUser()->getBasket();
$productsInBasket = $basket->getBasketProduct();
$sets = false;
foreach ($productsInBasket as $productInBasket) {
if ($productInBasket->getProductId() == $prod_id) {
if ($operation == 'plus') {
$product = $productInBasket->getProduct();
$value = $productInBasket->getProductCount() + $product->getMinOrder();
$productInBasket->setProductCount($value);
$productInBasket->save();
}
if ($operation == 'minus') {
$product = $productInBasket->getProduct();
$value = $productInBasket->getProductCount() - $product->getMinOrder();
if ($value == 0) {
$productInBasket->delete();
} else {
$productInBasket->setProductCount($value);
$productInBasket->save();
}
}
$sets = true;
}
}
if (!$sets) {
$product = Doctrine::getTable("Product")->findOneById($prod_id);
if ($operation == 'plus' && $product) {
$newBasketProduct = new BasketProduct();
$newBasketProduct->setProduct($product);
$newBasketProduct->setBasket($basket);
$newBasketProduct->setProductCount($product->getMinOrder());
$newBasketProduct->save();
}
}
return $this->renderComponent('basket', 'counter');
} else {
$this->forward404();
}
}
function executeAjaxAddProduct(sfWebRequest $request)
{
if ($request->isXmlHttpRequest()) {
$prod_id = $request->getParameter('prod_id');
$value = $request->getParameter('value');
$product = Doctrine::getTable('Product')->find($prod_id);
if ($product && $product->getMinOrder() > 0 && $product->getDefaultPrice() != 0) {
$basket = $this->getUser()->getBasket();
$productsInBasket = $basket->getBasketProduct();
$found = false;
foreach ($productsInBasket as $productInBasket) {
if ($productInBasket->getProductId() == $product->getId()) {
$found = true;
if ($productInBasket->getProductCount() != $value) {
if ($value % $product->getMinOrder() == 0) {
$productInBasket->setProductCount($value);
$productInBasket->save();
}
}
}
}
if (!$found) {
$newBasketProduct = new BasketProduct();
$newBasketProduct->setProduct($product);
$newBasketProduct->setBasket($basket);
$newBasketProduct->setProductCount($value);
$newBasketProduct->save();
}
return $this->renderComponent('basket', 'counter');
}
return sfView::NONE;
} else {
$this->forward404();
}
}
public function executeMake_order(sfWebRequest $request)
{
if ($request->isXmlHttpRequest() && $this->getUser()->isAuthenticated()) {
$this->setLayout(false);
$comment = false;
if ($request->hasParameter('comment')) {
$comment = strip_tags($request->getParameter('comment'));
}
$basket = $this->getUser()->getBasket();
$productsInBasket = $basket->getBasketProduct();
if (count($productsInBasket) > 0) {
$newClientOrder = new ClientOrder();
$newClientOrder->setUserId($this->getUser()->getUserId());
$newClientOrder->setOrderStatusId(1);
if ($comment) {
$newClientOrder->setComment($comment);
}
$delivery = $request->getParameter('delivery');
$delivery_address = null;
if ($delivery) {
$delivery_address = $request->getParameter('delivery_address');
} else {
$newClientOrder->setTimeToPickup($request->getParameter('time_to_pickup'));
}
$newClientOrder->save();
foreach ($productsInBasket as $products) {
$newOrderItem = new OrderItem();
$newOrderItem->setProduct_id($products->getProductId());
$newOrderItem->setProductCount($products->getProductCount());
$newOrderItem->setClientOrder($newClientOrder);
$newOrderItem->save();
}
$basket->setDelivery($delivery);
$basket->setDeliveryAddress($delivery_address);
$basket->setOrderId($newClientOrder->getId());
$basket->save();
sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');
get_component('pages', 'emailSender', array('type' => 'adminNotificationAboutOrder', 'emailTo' => 'admin', 'param' => array('delivery_address' => $delivery_address, 'delivery' => $delivery, 'order_id' => $newClientOrder->getId(), 'inn' => $this->getUser()->getUsername(), 'phone_number' => $this->getUser()->getAccount()->getPhoneNumber(), 'org' => $this->getUser()->getAccount()->getOrganization(), 'comment' => $comment, 'products_order' => $this->getUser()->getProductsNameAndCountAndSumInBasket())));
$this->getUser()->unbindBasket();
echo json_encode(array('state' => 'success', 'id' => $newClientOrder->getId()));
} else {
echo 'empty_basket';
}
} else {
$this->forward404();
}
return sfView::NONE;
}
public function executeFast_make_order(sfWebRequest $request)
{
if ($request->isXmlHttpRequest() && $request->hasParameter('phone')) {
$this->setLayout(false);
$phone = (int)str_replace(array('(', ')', '+', '-', ' '), '', $request->getParameter('phone'));
$email = $request->getParameter('email');
if (strlen($phone) == 11 && is_int($phone)) {
$comment = false;
if ($request->hasParameter('comment')) {
$comment = strip_tags($request->getParameter('comment'));
}
$basket = $this->getUser()->getBasket();
$productsInBasket = $basket->getBasketProduct();
if (count($productsInBasket) > 0) {
$user = Doctrine::getTable('user')->findOneByUsername($phone);
if (!$user) {
$user = new User();
$user->setUsername($phone);
$user->save();
}
$newClientOrder = new ClientOrder();
$newClientOrder->setUserId($user->getId());
$newClientOrder->setOrderStatusId(1);
if ($comment) {
$newClientOrder->setComment($comment);
}
$delivery = $request->getParameter('delivery');
$delivery_address = null;
if ($delivery) {
$delivery_address = $request->getParameter('delivery_address');
} else {
$newClientOrder->setTimeToPickup($request->getParameter('time_to_pickup'));
}
$newClientOrder->save();
foreach ($productsInBasket as $products) {
$newOrderItem = new OrderItem();
$newOrderItem->setProduct_id($products->getProductId());
$newOrderItem->setProductCount($products->getProductCount());
$newOrderItem->setClientOrder($newClientOrder);
$newOrderItem->save();
}
$basket->setOrderId($newClientOrder->getId());
$order_id = $newClientOrder->getId();
$basket->setDelivery($delivery);
$basket->setDeliveryAddress($delivery_address);
$basket->save();
sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');
get_component('pages', 'emailSender',
array(
'type' => 'adminNotificationAboutFastOrder',
'emailTo' => 'admin',
'param' => array(
'delivery_address' => $delivery_address,
'delivery' => $delivery, 'phone' => $phone,
'comment' => $comment,
'email' => $email,
'order_id' => $order_id,
'products_order' => $this->getUser()->getProductsNameAndCountAndSumInBasket()
)));
$this->getUser()->unbindBasket();
echo json_encode(array('state' => 'success', 'id' => $newClientOrder->getId()));
} else {
echo 'empty_basket';
}
} else {
echo 'no_valid_phone';
}
return sfView::NONE;
} else {
$this->forward404();
}
}
public function executeIndex(sfWebRequest $request)
{
$this->order_form = new wwwBasketOrderForm();
if($request->isMethod('post')){
$user = $this->getUser();
$basket = $user->getBasket();
$basket_info = $user->getBasketInfo();
if($basket_info['offerCount'] > 0){
$this->order_form->bind($request->getParameter($this->order_form->getName()));
if($this->order_form->isValid()){
$params =$request->getParameter($this->order_form->getName());
$phone = $params['phone'];
if ($this->getUser()->hasAttribute('active_discount') && $this->getUser()->getAttribute('active_discount') != false) {
$date_now = new DateTime('now');
$date_limit = new DateTime('now');
$date_limit->modify('-30 day');
$discount = Doctrine_Query::create()
->select()
->from('DiscountPhone dp')
->where('dp.phone = ?', $phone)
->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($discount) > 0) {
$discount = intval($discount->getFirst()->getActiveDiscount());
} else {
$discount = 0;
}
} else {
$discount = 0;
}
$order = $this->order_form->save();
$basket->setBasketOrderId($order->getId());
$basket->save();
$user->setAttribute('basket_complete_id', $order->getId());
$order_id = $order->getId();
$email = $order->getEmail();
$phone = $order->getPhone();
$delivery_type = $order->getDeliveryType();
$delivery_address = $order->getDeliveryAddress();
$payment_type = $order->getPaymentType();
$name = $order->getUsername();
$comment = $order->getComment();
$products['elem'] = array();
$products['sum'] = 0;
foreach ($basket->getBasketOffer() as $key => $basketOffer)
{
$offerTranslation = Doctrine_Query::create()
->select('o.*, t.*')
->from('Offer o')
->where('o.id = ?', intval($basketOffer->getOfferId()))
->leftJoin('o.Translation t')
->fetchArray();
if ($discount && $offerTranslation[0]['discount_available'] == 1) {
$basketOffer->setPrice($basketOffer->getPrice()/100*(100-$discount));
$basketOffer->save();
}
$products['elem'][$key]['name'] = $offerTranslation[0]['Translation']['ru']['title'];
$products['elem'][$key]['price'] = number_format(intval($basketOffer->getPrice())/$basketOffer->getAmount(), 0, ',', ' ');
$products['elem'][$key]['count'] = $basketOffer->getAmount();
$products['sum'] = $products['sum'] + intval($basketOffer->getPrice());
}
$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->setOrderId($order->getId());
$phone_discount->save();
}
$this->getUser()->setAttribute('active_discount', false);
$this->getUser()->setAttribute('phone', false);
$this->getUser()->setAttribute('number_of_views', false);
$emails_dirty = NotificationEmailsTable::getInstance()->createQuery('e')
->select('e.email')
->where("e.is_active = 1")
->andWhere("e.notic_type = 'order' OR e.notic_type = 'all'")
->fetchArray();
if (count($emails_dirty) > 0)
{
$emails = array();
foreach ($emails_dirty as $e)
{
// $emails[] = 'yakov@atmadev.ru';
// break;
$emails[] = $e['email'];
}
sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');
get_component('pages', 'emailSender',
array(
'type' => 'adminNotificationAboutFastOrder',
'emailTo' => $emails,
'param' => array(
'delivery_address' => $delivery_address,
'delivery_type' => $delivery_type,
'payment_type' => $payment_type,
'email' => $email,
'order_id' => $order_id,
'name' => $name,
'phone' => $phone,
'comment' => $comment,
'products_order' => $products,
'host' => $request->getHost()
)
)
);
}
$this->redirect('@basket_complete');
}
}
}
$this->setLayout('layoutFullWidth');
}
public function executeAppend(sfWebRequest $request)
{
$table = $request->getParameter('instance');
if ($table !== 'offer' && $table !== 'product') {
$result = array('status' => 'error', 'message' => 'incorrect instance');
return $this->returnSwitch($request, $result);
}
$this->setTemplate(false);
$basket = $this->getUser()->getBasket();
$elemId = $request->getParameter('id');
$elem = Doctrine_Core::getTable($table)->find($elemId);
$count = $request->getParameter('count_' . $elemId);
try {
$basket->addOrUpdate($elem, $count);
$result = array('status' => 'success');
} catch (Exception $e) {
$result = array('status' => 'error', 'message' => $e->getMessage());
}
return $this->returnSwitch($request, $result);
}
public function executeChangeProductCount(sfWebRequest $request)
{
$basket = $this->getUser()->getBasket();
$basketProduct = BasketProductTable::getInstance()->findBoundBasket($request->getParameter('bp_id'), $basket);
if (!$basketProduct instanceof BasketProduct) {
return $this->returnSwitch($request, array('status' => 'error', 'message' => 'BasketProduct not found'));
}
$count = 0;
switch ($request->getParameter('operation')) {
case 'up':
$count = 1;
break;
case 'down':
$count = -1;
break;
default:
return $this->returnSwitch($request, array('status' => 'error', 'message' => 'Broken operation'));
}
$basketProduct->addProductCount($count);
$basketProduct->save();
return $this->returnSwitch($request, array('status' => 'success', 'count' => $basketProduct->getProductCount()));
}
protected function returnSwitch(sfWebRequest $request, $data = null)
{
if ($request->isXmlHttpRequest() || $request->getReferer() == '') {
return $this->renderText(json_encode($data));
} else {
$this->redirect($request->getReferer());
}
}
public function executeRe_ordering(sfWebRequest $request)
{
if ($request->hasParameter('orderId') && $this->getUser()->isAuthenticated()) {
$orderId = $request->getParameter('orderId');
$order = Doctrine::getTable("ClientOrder")->findOneByIdAndUserId($orderId, $this->getUser()->getUserId());
if ($order) {
$order_item = Doctrine::getTable("OrderItem")->findByClientOrderId($orderId);
$this->getUser()->unbindBasket();
$new_basket = $this->getUser()->getBasket();
foreach ($order_item as $item) {
$this->addInBasket($item['product_id'], $item['product_count']);
}
$this->forward('basket', 'index');
} else {
$this->forward404();
}
} else {
$this->forward404();
}
}
public function executeAjax(sfWebRequest $request)
{
$res = array('state' => 'error');
$user = $this->getUser();
$basket = $user->getBasket();
if($request->getParameter('type') == 'add'){
$add_ids = $this->add($request->getParameter('offers'), $basket->getId());
if(count($add_ids) > 0){
$res['state'] = 'success';
$res['info'] = $user->getBasketInfo();
}
}elseif($request->getParameter('type') == 'update'){
$ids = array();
foreach ($request->getParameter('offers') as $key => $item)
{
$ids[] = $key;
}
Doctrine_Query::create()
->delete("BasketOffer")
->whereIn("offer_id", $ids)
->andWhere("basket_id = ?", $basket->getId())
->execute();
$add_ids = $this->add($request->getParameter('offers'), $basket->getId());
$res['state'] = 'success';
$res['html'] = $this->getComponent('basket', 'basket');
$res['info']= $user->getBasketInfo();
}elseif($request->getParameter('type') == 'clean'){
Doctrine_Query::create()
->delete("BasketOffer")
->where("basket_id = ?", $basket->getId())
->execute();
$res['state'] = 'success';
}
echo json_encode($res);
return sfView::NONE;
}
protected function addInBasket($productId, $setValue = false)
{
$basket = $this->getUser()->getBasket();
$product = Doctrine::getTable('Product')->find($productId);
$default_price_type = Doctrine::getTable('PriceType')->findOneByIsDefault(1);
$product = Doctrine_Query::create()->select('p.*')->addSelect("(SELECT pp.Value FROM ProductPrice pp WHERE pp.product_id = p.id AND pp.price_type_id = " . $default_price_type->getId() . ") as price")->from('Product p')->where('p.id = ' . $productId)->fetchOne();
if ($product && $basket && $product->getMinOrder() != 0 && $product->getPrice()) {
$found = false;
$productsInBasket = $basket->getBasketProduct();
$minOrder = $product->getMinOrder();
$stock = $product->getProductStockCount()->getFirst()->getValue();
foreach ($productsInBasket as $productInBasket) {
if ($productInBasket->getProductId() == $product->getId()) {
$found = true;
$count = $setValue !== false ? $setValue : $productInBasket->getProductCount() + $minOrder;
if ($count % $minOrder == 0 && $count <= $stock) {
$productInBasket->setProductCount($count);
$productInBasket->save();
}
break;
}
}
if (!$found && $stock > 0) {
$newBasketProduct = new BasketProduct();
$newBasketProduct->setProduct($product);
$newBasketProduct->setBasket($basket);
if ($setValue !== false && $setValue % $minOrder == 0) {
$newBasketProduct->setProductCount($setValue);
} else {
$newBasketProduct->setProductCount($minOrder);
}
$newBasketProduct->save();
$basket->getBasketProduct()->add($newBasketProduct);
}
}
}
protected function removeInBasket($productId, $notCountCheck = false)
{
$productsInBasket = $this->getUser()->getBasket()->getBasketProduct();
foreach ($productsInBasket as $productInBasket) {
if ($productInBasket->getProductId() == $productId) {
if ($notCountCheck) {
$count = 0;
} else {
$min_p = $productInBasket->getProduct()->getMinOrder();
$count = $productInBasket->getProductCount() - $min_p;
}
if ($count > 0) {
$productInBasket->setProductCount($count);
$productInBasket->save();
} else {
$productInBasket->delete();
}
}
}
}
public function executeComplete(sfWebRequest $request)
{
$basket_order_id = $this->getUser()->getAttribute('basket_complete_id');
$this->forward404Unless($basket_order_id && is_numeric($basket_order_id));
$this->getUser()->setAttribute('basket_complete_id', null);
$this->basket_order = Doctrine_Query::create()
->select("o.*, b.*, of.*, SUM(of.price) AS offer_price")
->from("BasketOrder o")
->innerJoin("o.Basket b")
->innerJoin("b.BasketOffer of")
->where("id = ?", $basket_order_id)
->fetchOne();
$this->forward404Unless($this->basket_order);
}
}
\ No newline at end of file
<?php
class basketComponents extends sfComponents
{
public function executeCounter(sfWebRequest $request)
{
$this->counter = $this->getUser()->getBasket()->getCount();
$this->sum = $this->getUser()->getBasket()->getSum();
}
public function executeBasket(sfWebRequest $request)
{
$user = $this->getUser();
$basket = $user->getBasket();
$this->culture = $user->getCulture();
$this->offers = Doctrine_Query::create()
->select("o.*, t.*, b.*, p.id, pt.id, p.product_img, p.alias, p.free_shipping, pt.lang, pt.title")
->from("Offer o")
->innerJoin("o.Translation t ON (t.id = o.id AND t.lang = '" . $this->culture . "')")
->innerJoin("o.BasketOffer b")
->innerJoin("o.Product p WITH p.is_delete = 0")
->innerJoin("p.Translation pt ON (pt.id = p.id AND pt.lang = '" . $this->culture . "')")
->where("b.basket_id = ?", $basket->getId())
->andWhere("o.is_delete = 0")
->fetchArray();
if(count($this->offers) > 0){
$this->info = $user->getBasketInfo();
}
if ($this->getUser()->hasAttribute('active_discount') && $this->getUser()->getAttribute('active_discount') != false) {
$this->percent = $this->getUser()->getAttribute('active_discount');
}
}
}
\ No newline at end of file
_counter:
enabled: false
with_layout: false
\ No newline at end of file
<div class="max_width">
<div class="truecount" <?php echo (count($offers) > 0 ? '' : 'style="display: none"') ?> >
<table class="basket_offers_table to_div" width="100%" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th><?php echo __('Наименование');?></th>
<th></th>
<th><?php echo __('Количество');?></th>
<th><?php echo __('Цена');?></th>
<th><?php echo __('Сумма');?></th>
<th><a onclick="basket.clean();event.stopPropagation();return false;" class="red_link bbs_d"><?php echo __('Очистить');?></a></th>
</tr>
</thead>
<tbody valign="middle">
<?php
if (!isset($percent)) {
$percent = false;
}
$summ = 0;
$productFreeShipping = 1;
foreach ($offers as $offer){
if ($offer['Product']['free_shipping'] == 0) {
$productFreeShipping = 0;
}
$quantity_type = $offer['Translation'][$culture]['quantity_type'];
if ($offer['quantity_type_select']) {
$quantity_type = (isset(Offer::$quantity_type_select_values[$offer['quantity_type_select']]) ? Offer::$quantity_type_select_values[$offer['quantity_type_select']] : '');
}
echo '<tr>';
$offer_img = $offer['img'];
if(!$offer_img && $offer['Product']['product_img']){
$offer_imgs = explode(';', $offer['Product']['product_img']);
$offer_img = $offer_imgs[0];
}
//print_r($offer['Product']);
echo '<td valign="top"><a style="border: none" href="/' . $offer['Translation'][$culture]['lang'] . '/product/' . $offer['Product']['alias'] . '/"><div class="basket_img ' . ($offer['discount_available'] == 1 ? 'discount' : '') . '" ' . ($offer_img ? 'style="background-image: url(/u/i/' . Page::replaceImageSize($offer_img, 'S') . ');"' : '') . '></div></a>';
echo '<td><div class="basket_offer_title"><a href="/' . $offer['Translation'][$culture]['lang'] . '/product/' . $offer['Product']['alias'] . '/">' . $offer['Translation'][$culture]['title'] . '</a></div></td>';
echo '</td>';
echo '<td class="align_center"><div class="product_counter" data-id="' . $offer['id'] . '">';
echo '<input type="button" class="product_counter_minus" data-symbol="-" onclick="counterLite.update($(this))">';
echo '<input autocomplete="off" type="text" class="product_counter_val" value="' . $offer['BasketOffer'][0]['amount'] . '" data-symbol="false" onkeyup="counterLite.update($(this))">';
echo '<input type="button" class="product_counter_plus" data-symbol="+" onclick="counterLite.update($(this))">';
echo '</div><span class="name_unit">' . ($quantity_type != '' ? $quantity_type : '') . '</span></td>';
if ($percent && $offer['discount_available'] == 1) {
echo '<td valign="middle" class="basket_offers_table__price align_center"><div style="position: relative"><div class="basket_discount"><span style="text-decoration: line-through">' . number_format($offer['price'], 0, ',', ' ') . '&nbsp;</span><span style="font-size: 15px" class="rub">i</span></div><div class="basket_item">' . number_format($offer['price']/100*(100-$percent), 0, ',', ' ') . '&nbsp;<span class="rub">i</span></div></div></td>';
echo '<td valign="middle" class="basket_offers_table__price align_center"><div class="basket_item"> ' . number_format($offer['BasketOffer'][0]['price']/100*(100-$percent), 0, ',', ' ') . '&nbsp;<span class="rub">i</span></div></td>';
$summ = $summ + $offer['BasketOffer'][0]['price']/100*(100-$percent);
}else {
echo '<td valign="middle" class="basket_offers_table__price align_center"><div class="basket_item">' . number_format($offer['price'], 0, ',', ' ') . '&nbsp;<span class="rub">i</span></div></td>';
echo '<td valign="middle" class="basket_offers_table__price align_center"><div class="basket_item">' . number_format($offer['BasketOffer'][0]['price'], 0, ',', ' ') . '&nbsp;<span class="rub">i</span></div></td>';
$summ = $summ + $offer['BasketOffer'][0]['price'];
}
echo '<td width="1" align="center"><div class="basket_clean" onclick="basket.delete(this);"></div></td>';
echo '</tr>';
}
?>
</tbody>
</table>
<div class="basket_total" data-delivery-info="<?php echo $productFreeShipping ?>"><?php echo __('Итого');?>:<div class="basket_total__price"><?php echo number_format($summ, 0, ',', ' ');?></div>&nbsp;<span class="rub">i</span></div>
</div>
</div>
<div class="cart_empty" <?php echo (count($offers) > 0 ? 'style="display: none"' : '' )?> >
<p>Тут пока ничего нет. Посмотри в <a href="<?php echo url_for("@catalog"); ?>">каталоге</a>, там много интересного</p>
<i class="br10"></i>
<div class="cart_empty__img"></div>
<i class="br40"></i>
</div>
<?php
if ($counter && $counter != 0)
{
echo "<div class='no_empty_basket_t'>Корзина<br><b>". $counter ." тов. на " . number_format($sum,2,',',' ') . "<span class='rub'>a</span></b></div>";
}
else
{
echo "<div class='empty_basket_t'>Корзина пуста</div>";
}
\ No newline at end of file
<div class="basket_complete_wrap">
<h1 class="basket_complete__h"><?php echo __('Готово');?>!</h1>
<div class="basket_complete__desc">
<?php echo __('Ваш заказ') . ' №' . $basket_order->getId() . ' ' . __('отправлен на обработку');?>.<br>
<?php echo __('Вы заказали на сумму') . ' ' . number_format($basket_order->getOfferPrice(),0,',',' ');?><span class="rub">a</span>.<br>
<?php
if($basket_order->getDeliveryType() == 'Самовывоз'){
echo __('Вы сможете забрать свой заказ по адресу') . ': ' . csSettings::get('pickup_address');
}else{
echo __('Доставка по адресу') . ': ' . $basket_order->getDeliveryAddress();
}
/*Скачать файл с заказом*/
?>
</div>
</div>
\ No newline at end of file
<style>
@media (min-width: 650px) {
html {
height: 100%;
}
body {
height: 100%;
}
.body_wrapper_wrapper {
height: 100%;
}
}
.root_table__bottom > table > tbody > tr:first-child {display: none;}
.footer_table_main {border-top: 1px solid rgba(150, 150, 150, 0.5);}
</style>
<div class="max_width">
<i class="br25 mobile_hide"></i>
<?php
slot('title', __('Корзина'));
include_partial('main/breadcrumbs');
echo '<h1 class="content_title">' . __('Корзина') . '</h1>';
?>
</div>
<form method="post" class="basket_wrap">
<div class="basket_refresh">
<?php
include_component('basket', 'basket');
?>
</div>
<div class="max_width">
<?php
$info = $sf_user->getBasketInfo();
echo $order_form->renderGlobalErrors();
echo $order_form->renderHiddenFields();
?>
<div class="formsuccess" <?php echo ($info['offerCount'] > 0 ) ? '' : 'style="display: none"' ?> >
<div class="basket_buyer">
<?php
echo '<h2>' . __('Контактные данные') . ':</h2>';
echo '<div class="basket_buyer__item"><input size="27" maxlength="255" required="1" placeholder="Как к вам обращаться" onchange="form_validator.check($(this))" onkeyup="form_validator.check($(this))" data-check-rule="noempty" class="basket_buyer__inp_name validate_it" name="basket_order[username]" id="basket_order_username" type="text"></div>';
echo '<div class="basket_buyer__item"><div class="phone_info"></div><input size="27" maxlength="24" required="1" placeholder="Номер телефона" onchange="form_validator.check($(this))" onkeyup="form_validator.check($(this))" data-check-rule="phone" class="basket_buyer__inp_name phone_mask validate_it" name="basket_order[phone]" id="basket_order_phone" type="text"></div>';
echo '<div class="basket_buyer__item"><input size="27" maxlength="24" required="1" placeholder="Email" onchange="form_validator.check($(this))" onkeyup="form_validator.check($(this))" data-check-rule="email" class="basket_buyer__inp_name validate_it" name="basket_order[email]" id="basket_order_email" type="text"></div>';
?>
</div>
<div class="basket_get">
<?php echo '<h2>' . __('Как получить товар') . '</h2>';?>
<div class="basket_get__pickup">
<?php
echo '<label class="radio"><input type="radio" class="not_custom" name="basket_order[delivery_type]" value="Самовывоз" required="required" autocomplete="off">';
echo '<span class="radio_span"></span>';
echo '<span class="radio_text">' . __('Самовывоз') . '</span>';
echo $order_form['delivery_type']->renderError();
echo '</label>';
?>
<div class="basket_get__desc">
<?php echo __('Вы можете забрать товар по адресу') . ':<br>' . csSettings::get('pickup_address');?>
</div>
</div>
<div class="basket_get__delivery">
<label class="radio">
<input class="not_custom" id="basket_order_delivery_type_delivery" type="radio" name="basket_order[delivery_type]" value="Доставка по адресу" required="required" autocomplete="off">
<span class="radio_span"></span>
<span class="radio_text"><?php echo __('Доставка');?></span>
</label>
<div class="basket_get__desc" style="margin-top: 10px">
<span class="basket_delivery_info">
</span>
<?php
echo $order_form['delivery_address']->render() . $order_form['delivery_address']->renderError();
?>
</div>
</div>
</div>
<div class="basket_advanced">
<?php
echo '<h2>' . __('Пожелание к заказу') . '</h2>';
echo $order_form['comment']->render() . $order_form['comment']->renderError();
?>
</div>
<div class="basket_order">
<?php
echo '<h2>' . __('Общая сумма заказа') . '</h2>';
echo '<div class="basket_order__price">' . $info['priceText'] . '&nbsp;<span class="rub">i</span></div>';
echo '<input type="submit" class="btn green_b_btn order_btn btn_disabled" value="' . __('Оформить заказ') . '" disabled>';
?>
</div>
<script type="text/javascript">
var lastvalue = '';
var lastvalueunmask = '';
function mask(str) {
var arr = str.split('');
if (str.length >= 2)
{
arr.splice(2,0," (");
if (str.length >= 5)
{
arr.splice(6,0,") ");
}
if (str.length >=8)
{
arr.splice(10,0,"-");
}
if (str.length >= 10)
{
arr.splice(13,0,"-");
}
}
return arr.join('');
}
function unmask(str) {
var rep = /[()\-\s]/g;
var value = str.replace(rep, '');
return value;
}
$('.phone_mask').on('input', function () {
var value = unmask($(this).val());
var last = value.slice(-1);
var first = value.charAt(0);
var rep = /(^\+7)(9)([0-9]{0,9})/g;
if ((value.length == 2) && (first == '+'))
{
if (value == '+9')
{
value = '+79';
lastvalue = '+79';
}else
{
value = '+7';
lastvalue = '+7';
}
}else
if ((value == '7') || (value == '8'))
{
value = '+7';
} else
if (value == '9')
{
value = '+79';
} else
{
var execval = rep.exec(value);
if (execval != null)
{
value = execval[0];
} else
{
if ((last != '9'))
{
value = value.substring(0, value.length - 1)
}
}
}
$(this).val(mask(value));
lastvalue = $(this).val();
lastvalueunmask = value;
});
$('.phone_mask').on('keydown', function (event) {
var key = event.keyCode || event.charCode;
if( key == 8 || key == 46 ){
var value = unmask($('.phone_mask').val());
value = value.substring(0, value.length - 1);
$('.phone_mask').val(mask(value));
lastvalue = $('.phone_mask').val();
return false;
}
});
$('.phone_mask').on('blur', function (e) {
if ($('.phone_mask').val().length == 18) {
$.ajax({
url: '/ru/basket/check_discount/',
dataType: 'json',
type: 'post',
data: {phone: $('.phone_mask').val()},
success: function (data) {
if (data.status == 'success' && data.active_discount > 0) {
$('.basket_refresh').html(data.body);
$($('.top_right')[1]).addClass('discount_basket');
$('.phone_info').html('На этом номере обнаружена скидка ' + data.active_discount + '%')
} else if (data.status == 'success' && data.active_discount == 0) {
$('.basket_refresh').html(data.body);
$($('.top_right')[1]).removeClass('discount_basket');
$('.phone_info').html('На этом номере скидка не обнаружена')
}
},
error: function (error) {
console.log(error);
}
})
}
})
$(document).ready(function () {
var delivery_info = $('.basket_total').data('delivery-info');
console.log(delivery_info);
if (delivery_info == '0') {
$('.basket_delivery_info').html('Свяжитесь с нами, для уточнения стоимости доставки +7 (635) 644-75-75.<br/>Или уточните у оператора, после оформления заказа');
}else {
$('.basket_delivery_info').html('Доставка бесплатная');
}
});
var delivery_type = undefined;
$('.basket_order input[type="submit"]').on('click', function () {
var cl = $('.basket_order input[type="submit"]').attr('class');
console.log(cl);
console.log(cl.indexOf('btn_disabled'));
if (cl.indexOf('btn_disabled') > 0)
{
return false
}
delivery_adr = $('#basket_order_delivery_address').val();
if(typeof delivery_type == 'undefined') {
invalid($('.basket_get'));
return false;
}
if(delivery_type == 2 && delivery_adr.length < 3) {
invalid($('#basket_order_delivery_address'));
return false;
}
return true;
});
$('.basket_get input[type="radio"]').change(function (e) {
var deliveryAddress = $('#basket_order_delivery_address');
if(e.target.value == 'Самовывоз'){
delivery_type = 1;
deliveryAddress.removeAttr('required');
}else{
delivery_type = 2;
deliveryAddress.attr('required', 'required');
}
});
$('#basket_order_delivery_address').focus(function () {
$('#basket_order_delivery_type_delivery').click();
});
function invalid(el) {
$('html, body').animate({
scrollTop: el.offset().top - 160
}, 300);
setTimeout(function() {
el.addClass('jump');
}, 300);
setTimeout(function() {
el.removeClass('jump')
}, 800);
}
var count = <?php echo $info['offerCount'] ?>;
$(document).ready(function () {
form_validator.check($('#basket_order_username'));
form_validator.check($('#basket_order_email'));
form_validator.check($('#basket_order_phone'));
})
</script>
</div>
<i class="br40"></i>
</div>
</form>
\ No newline at end of file
<?php
/**
* callback actions.
*
* @package sf
* @subpackage callback
* @author Atma
* @version SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
*/
class callbackActions extends sfActions
{
/**
* Executes index action
*
* @param sfRequest $request A request object
*/
public function executeNew(sfWebRequest $request)
{
$callback_form = new wwwCallbackForm();
$params = $request->getParameter($callback_form->getName());
$params['phone'] = preg_replace("/[^0-9]/", '', $params['phone']);
if ($params['offer_id'] == '')
{
$params['offer_id'] = null;
}
$callback_form->bind($params);
$is_valid = $callback_form->isValid();
if($is_valid){
$callback = $callback_form->save();
$mail_body = "Обратный звонок" . "\n";
$mail_body .= "Телефон: " . $callback->getPhone() . "\n";
$mail_body .= "Имя: " . $callback->getName() . "\n";
$emails_dirty = NotificationEmailsTable::getInstance()->createQuery('e')
->select('e.email')
->where("e.is_active = 1")
->andWhere("e.notic_type = 'call' OR e.notic_type = 'all'")
->fetchArray();
if (count($emails_dirty) > 0)
{
$emails = array();
foreach ($emails_dirty as $e)
{
$emails[] = $e['email'];
}
sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');
get_component('pages', 'emailSender',
array(
'type' => 'simple',
'emailTo' => $emails,
'param' => array('mailBody' => $mail_body, 'subject' => 'Обратный звонок')
)
);
}
$callback_form = new wwwCallbackForm();
}
echo $this->getPartial('callback/callback', array('callback_form' => $callback_form, 'is_valid' => $is_valid));
return sfView::NONE;
}
}
<?php
class callbackComponents extends sfComponents
{
public function executeCallback(sfWebRequest $request)
{
$this->callback_form = new wwwCallbackForm();
}
}
\ No newline at end of file
<?php
echo '<form class="callback_form' . (isset($is_valid) && $is_valid ? ' callback_form_done' : '') . '" method="post" action="' . url_for('@callback') . '" onsubmit="callback.submit(this);return false;">';
echo '<div class="callback_form_done__title"><div class="callback_form_done__title__base">Готово!</div>Оператор свяжется с вами в ближайшее время.</div>';
echo '<div class="callback_form__process">';
echo '<div id="callback" class="callback_form__title" style="display: none">' . __('Закажите звонок') . '</div>';
echo '<div id="callback_offer" class="callback_form__title" style="display: none">' . __('Оставьте свои данные и мы перезвоним в ближайшее время') . '</div>';
echo $callback_form->renderGlobalErrors();
echo $callback_form->renderHiddenFields();
echo '<div class="callback_form__inp_wrap"><input name="callback[name]" type="text" class="form_type_1__input validate_it" placeholder="Имя" onkeyup="form_validator.check($(this))" data-check-rule="noempty" autocomplete="off" required></div>';
echo '<div class="callback_form__inp_wrap"><input name="callback[phone]" type="text" class="form_type_1__input validate_it" placeholder="Телефон" onkeyup="form_validator.check($(this))" data-check-rule="phone" autocomplete="off" required></div>';
echo '<div class="callback_form__inp_wrap" style="display: none"><input id="callback_offer_id" name="callback[offer_id]" type="text" class="form_type_1__input" value=""></div>';
$culture = $sf_user->getCulture();
?>
<div class="callback_form__checkbox">
<label class="checkbox ver2">
<input type="checkbox" class="validater validate_it not_custom" onchange="form_validator.check($(this))" data-check-rule="checked" autocomplete="off" required >
<span class="checkbox_span"></span>
<span class="checkbox_text"><?php echo __('Я принимаю условия')?> <a href="<?php echo '/' . $culture . '/terms-of-use/' ?>" target="_blank"><?php echo __('пользовательского соглашения') ?></a><?php echo __(' и ') ?> <a href="<?php echo '/' . $culture . '/privacy-policy/' ?>" target="_blank"><?php echo __('политики конфиденциальности') ?></a></span>
</label>
</div>
<i class="br15"></i>
<?php
echo '<input type="submit" class="callback_form__submit green_b_btn send btn_disabled" value="' . __('Отправить') . '" disabled />';
echo '</div>';
echo '</form>';
//print_r('1234' . $sf_culture);
?>
\ No newline at end of file
<?php
class catalogActions extends sfActions
{
public function executeIndex(sfWebRequest $request)
{
$this->catalogs = Doctrine_Query::create()
->select("c.id, c.photo, c.order_id, c.alias, cc.id, cc.alias, cct.*, t.*, p.id, p.alias, p.offer_count, p.is_detail, p.is_delete, pt.id, pt.lang, pt.title")
->from("Cat c")
->leftJoin("c.Translation t")
->leftJoin("c.Children cc")
->leftJoin("cc.Translation cct")
->leftJoin("c.Products p WITH p.is_delete = 0")
->leftJoin("p.Translation pt")
->andWhere("c.parent_id IS NULL")
->orderBy("c.sort, p.sort")
->fetchArray();
$this->culture = $this->getUser()->getCulture();
}
public function executeShowCategory(sfWebRequest $request)
{
$alias = $request->getParameter('alias');
$viewType = Doctrine::getTable('Cat')->findOneByAlias($alias)->getViewType();
$category = false;
if ($viewType == 'onlyCats') {
$category = Doctrine_Query::create()
->from('Cat c')
->innerJoin('c.Translation t')
->leftJoin('c.Children ch')
->leftJoin('ch.CatProduct cp')
->leftJoin('cp.Product p')
->innerJoin('ch.Translation ch_t')
->where('t.lang = ? AND t.available = 1', $this->getUser()->getCulture())
->andWhere('ch_t.lang = ? AND ch_t.available = 1', $this->getUser()->getCulture())
->andWhere('p.deleted_at is null')
//->andWhere('c.parent_id is null')
->andWhere('c.alias = ?', $alias)
->execute()->getFirst();
$this->forward404Unless($category);
} elseif ($viewType == 'onlyProducts') {
$category = Doctrine_Query::create()
->from('Cat c')
->innerJoin('c.Translation t')
->leftJoin('c.CatProducts prod')
->innerJoin('prod.Translation prod_t')
->where('t.lang = ? AND t.available = 1', $this->getUser()->getCulture())
->andWhere('prod_t.lang = ? AND prod_t.available = 1', $this->getUser()->getCulture())
->andWhere('prod.deleted_at is null')
->andWhere('c.alias = ?', $alias)
->execute()->getFirst();
$this->viewFilter = false;
}
$this->category = $category;
$this->viewType = $viewType;
}
// public function executeShowCategoryChild(sfWebRequest $request)
// {
//
// $children_alias = $request->getParameter('child_alias');
//
// $category = Doctrine_Query::create()
// ->from('Cat c')
// ->innerJoin('c.Translation t')
// ->leftJoin('c.Parent p')
// ->leftJoin('c.CatProducts prod')
// ->innerJoin('prod.Translation prod_t')
// ->innerJoin('p.Translation p_t')
// ->where('t.lang = ? AND t.available = 1', $this->getUser()->getCulture())
// ->andWhere('p_t.lang = ? AND p_t.available = 1', $this->getUser()->getCulture())
// ->andWhere('prod_t.lang = ? AND prod_t.available = 1', $this->getUser()->getCulture())
// ->andWhere('c.parent_id is not null')
// ->andWhere('c.alias = ?', $children_alias)
// ->execute()->getFirst();
//
//
// $this->forward404Unless($category);
//
// $this->category = $category;
//
//
// }
public function executeShowProduct(sfWebRequest $request)
{
$product_alias = $request->getParameter('alias');
$this->culture = $this->getUser()->getCulture();
$this->product = Doctrine_Query::create()
->from('Product p')
->leftJoin('p.Offer o')
->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('ppv.Translation tppv WITH tppv.lang = \'' . $this->culture . '\'')
->leftJoin('pp.Translation tpp WITH tpp.lang = \'' . $this->culture . '\'')
->leftJoin('ppl.Translation tppl WITH tppv.lang = \'' . $this->culture . '\'')
->andWhere('p.alias = ?', $product_alias)
->fetchOne();
$this->setLayout('layoutPage');
}
public function executeGood_list(sfWebRequest $request)
{
$this->query = $request->getParameter('query', false);
$this->setLayout('layoutNotLeftMenuNotSearchField');
}
public function executeShow(sfWebRequest $request)
{
$this->cat = $this->getRoute()->getObject();
$this->culture = $this->getUser()->getCulture();
$this->cats = Doctrine_Query::create()
->select("c.alias, c.photo, c.parent_id, t.*")
->from("Cat c")
->innerJoin("c.Translation t")
->where("c.parent_id = ?", $this->cat->getId())
->fetchArray();
if(count($this->cats) == 0){
$products_all_q = Doctrine_Query::create()
->select("p.id, p.offer_count, p.is_delete, p.product_img, c.cat_id, c.product_id")
->from("Product p INDEXBY p.id")
->leftJoin("p.CatProduct c")
->where("c.cat_id = ?", $this->cat->getId())
->andWhere("p.offer_count > 0")
->andWhere("p.is_delete = 0")
->orderBy('p.sort asc');
//->andWhere("CHAR_LENGTH(p.product_img) > 0");
$products_q = Doctrine_Query::create()
->select("p.id, p.alias, p.product_img, p.is_detail, p.offer_count, p.is_delete, c.*, t.id, t.lang, t.title, o.id, o.product_id, o.price, o.quantity_type_select, o.discount_available, ot.*, ppv.*")
->from("Product p")
->leftJoin("p.CatProduct c")
->leftJoin("p.Translation t")
->leftJoin("p.Offer o")
->leftJoin("o.Translation ot")
->where("c.cat_id = ?", $this->cat->getId())
->andWhere("p.offer_count > 0")
->andWhere("p.is_delete = 0")
->orderBy('p.sort asc, o.sort asc');
//->andWhere("CHAR_LENGTH(p.product_img) > 0");
$filter_list = $request->getParameter('filter_list');
$filter_range = $request->getParameter('filter_range');
if($request->isXmlHttpRequest() && ($filter_list || $filter_range)){
$filter_q = array();
foreach (array('list' => $filter_list, 'range' => $filter_range) as $list_key => $list){
if(is_array($list) && count($list) > 0){
foreach ($list as $prop_id => $values){
if(is_numeric($prop_id) && is_array($values) && count($values) > 0){
$values_q = array();
foreach ($values as $value_key => $value){
if(is_numeric($value)){
if($list_key == 'list'){
$values_q[] = $value;
}elseif($list_key == 'range' && in_array($value_key, array('min', 'max'))){
$values_q[] = $value;
}
}
}
if(count($values_q) > 0){
if($list_key == 'list'){
$filter_q[] = "p.prop_id = " . $prop_id . " AND p.value IN(" . implode(',', $values_q) . ")";
}elseif($list_key == 'range' && count($values_q) == 2){
$filter_q[] = "p.prop_id = " . $prop_id . " AND p.value >= " . $values_q[0] . " AND p.value <= " . $values_q[1];
}
}
}
}
}
}
$filter_q_count = count($filter_q);
if($filter_q_count > 0){
$product_prop_value = Doctrine_Query::create()
->select("p.product_id, COUNT(*)")
->from("ProductPropValue p")
->groupBy("p.product_id")
->where("(" . implode(') OR (', $filter_q) . ")")
->fetchArray();
$product_prop_value_real = array();
if(count($product_prop_value) > 0){
foreach ($product_prop_value as $key => $value) {
if($value['COUNT'] == $filter_q_count){
$product_prop_value_real[] = $value['product_id'];
}
}
}
if(count($product_prop_value_real) == 0){
$product_prop_value_real[] = 'empty';
}
$products_q->andWhereIn("p.id", $product_prop_value_real);
$products_all_q->andWhereIn("p.id", $product_prop_value_real);
}
}
$this->products_all = $products_all_q->fetchArray();
$this->product_ids = array_keys($this->products_all);
$page = (int)$request->getParameter('page', 1);
if(!is_numeric($page) || $page <= 0){
$page = 1;
}
$this->in_page_count = 12;
$products_all_count = count($this->products_all);
if ($products_all_count == 1)
{
$product_id = array_shift($this->products_all)['id'];
$product_alias = Doctrine::getTable('Product')->findOneById($product_id)->getAlias();
$culture = $this->getUser()->getCulture();
$this->redirect('/' . $culture . '/product/' . $product_alias . '/');
}
$this->forward404Unless($products_all_count == 0 || $page <= ceil($products_all_count / $this->in_page_count));
if($page > 1){
$products_q->offset($this->in_page_count * ($page - 1));
}
$products_q->limit($this->in_page_count);
$this->products = $products_q->fetchArray();
if($request->isXmlHttpRequest()){
if (count($this->products) > 0) {
foreach ($this->products as $product) {
echo $this->getPartial("product/product", array("product" => $product));
}
echo $this->getPartial('catalog/pagination', array('count' => $products_all_count, 'in_page_count' => $this->in_page_count));
}else{
echo 'Нет товаров.';
}
return sfView::NONE;
}
}
}
public function executeShow_prod(sfWebRequest $request)
{
$this->forward404Unless($request->hasParameter('alias'));
$alias = $request->getParameter('alias');
$product = Doctrine::getTable('Product')->findOneByAlias($alias);
if ($product) {
$cat_id = $product->getCatProducts()->getFirst()->getId();
$current_category = Doctrine::getTable('Cat')->find($cat_id);
$parents = $current_category->getParents();
$breadcrumbs = array();
foreach ($parents as $parent) {
$parent_alias = Doctrine::getTable('Cat')->findOneById($parent->getParentId());
$breadcrumbs[] = array(
'title' => $parent->getTitle(),
'id' => $parent->getParentId(),
'alias' => $parent_alias->getAlias()
);
}
$breadcrumbs[] = array('title' => $current_category->getTitle(), 'id' => $current_category->getId(), 'alias' => $current_category->getAlias());
$breadcrumbs[] = array('title' => $product->getTitle(), 'id' => null);
$this->breadcrumbs = $breadcrumbs;
$this->product = $product;
}
}
public function executeSpecials(sfWebRequest $request)
{
if ($request->hasParameter('type')) {
$type = $request->getParameter('type');
$this->type = $type;
$products = false;
if ($type == 'sale') {
$default_price_type = Doctrine::getTable('PriceType')->findOneByIsDefault(1);
$products = Doctrine_Query::create()
->select("p.id, p.created_at, p.alias, p.title, p.product_code, p.sell_out, min_order, (psc.value) as stockCount")
->addSelect("(SELECT pp.Value FROM ProductPrice pp WHERE pp.product_id = p.id AND pp.price_type_id = " . $default_price_type->getId() . ") as price")
->from("Product p")
->innerJoin("p.CatProduct cp")
->innerJoin("p.ProductStockCount psc")
->where("p.sell_out = 1")
->andWhere("p.deleted_at is null");
$query = Doctrine_Query::create()
->select("COUNT(p.id)")
->from("Product p")
->innerJoin("p.CatProduct cp")
->innerJoin("p.ProductStockCount psc")
->where("p.sell_out = 1")
->andWhere('p.deleted_at is null');
$this->breadcrumbs = 'Распродажа';
}
$inPage = $request->getParameter('inPage', 10);
$this->inPage = $inPage;
$sort = $request->getParameter('sort', 'id');
$this->sort = $sort;
$order = $request->getParameter('order', 'asc');
$this->order = $order;
if ($order && $sort) {
switch ($sort) {
case 'product_code':
$products->orderBy('CAST(p.product_code AS UNSIGNED) ' . strtoupper($order));
break;
case 'title':
$products->orderBy('p.title ' . strtoupper($order));
break;
case 'price':
$products->orderBy('CAST(price AS UNSIGNED) ' . strtoupper($order));
break;
default:
$products->orderBy($sort . ' ' . strtoupper($order));
break;
}
}
$product_info = $query->fetchArray();
$productsCount = $product_info[0]['COUNT'];
$this->productCount = $productsCount;
$page = $request->getParameter('page');
$countPage = ceil($productsCount / $inPage);
if (!is_numeric($page) || $page <= 0 || $page > $countPage) {
$page = 1;
}
$this->page = $page;
$this->countPage = $countPage;
$offset = ($page - 1) * $inPage;
if ($offset >= $productsCount && $productsCount != 0) {
$offset = $productsCount - $inPage;
}
$products->limit($inPage)->offset($offset);
$this->products = $products->fetchArray();
}
}
public function executeNew_arrivals(sfWebRequest $request)
{
$default_price_type = Doctrine::getTable('PriceType')->findOneByIsDefault(1);
$this->products = Doctrine_Query::create()
->select("p.id, p.title, p.product_code, min_order, (psc.value) as stockCount")
->addSelect("(SELECT pp.Value FROM ProductPrice pp WHERE pp.product_id = p.id AND pp.price_type_id = " . $default_price_type->getId() . ") as price")
->from("Product p")
->innerJoin("p.CatProduct cp")
->innerJoin("p.ProductStockCount psc")
->orderBy('p.created_at desc')
->limit(100)
->where('p.deleted_at is null')
->fetchArray();
}
public function executeQuick_search(sfWebRequest $request)
{
if ($request->hasParameter('query')) {
$searchString = trim(preg_replace('/\s\s+/', ' ', htmlspecialchars($request->getParameter('query'))));
$default_price_type = Doctrine::getTable('PriceType')->findOneByIsDefault(1);
$search = Doctrine_Query::create()
->select("p.id, p.title, p.alias, p.sell_out, p.product_code, min_order, (psc.value) as stockCount")
->addSelect("(SELECT pp.Value FROM ProductPrice pp WHERE pp.product_id = p.id AND pp.price_type_id = " . $default_price_type->getId() . ") as price")
->from("Product p")
->innerJoin("p.CatProduct cp")
->innerJoin("p.ProductStockCount psc")
->where('p.title LIKE ?', "%" . $searchString . "%")
->andWhere('p.deleted_at is null');
$searchCount = $search->count();
if (!$request->hasParameter('full')) {
$search->limit(5);
} else {
$page = 1;
$count = $search->count();
$inPage = 5;
$countPage = ceil($count / $inPage);
$this->page = $page;
$this->countPage = $countPage;
$offset = ($page - 1) * $inPage;
if ($offset >= $count && $count != 0) {
$offset = $count - $inPage;
}
$search->limit($inPage)->offset($offset);
$this->setTemplate('quick_search_full');
}
$this->searchString = $searchString;
$this->searchCount = $searchCount;
$this->searchResult = $search->fetchArray();
}
}
}
\ No newline at end of file
<?php
class catalogComponents extends sfComponents
{
public function executeCatChildren(sfWebRequest $request)
{
if ($this->parentId)
{
$parentId = $this->parentId;
$this->alias = $request->getParameter('alias');
$this->childrens = Doctrine::getTable('Cat')->findByParentId($parentId);
}
else
{
return sfView::NONE;
}
}
public function executeLeftMenu(sfWebRequest $request)
{
$this->path = $request->getPathInfo();
$leftMenu = Doctrine_Query::create()
->from('cat c')
//->leftJoin('c.Children ch')
//->leftJoin('ch.Children ch_ch')
//->leftJoin('ch_ch.Children ch_ch_ch')
//->leftJoin('ch_ch_ch.Children ch_ch_ch_ch')
->where('c.parent_id is null')
->fetchArray();
$this->menu = $leftMenu;
$this->open = array();
$alias = $request->getParameter('alias', null);
$id = null;
if ($alias != null)
{
$idByAlias = Doctrine::getTable('Cat')->findOneByAlias($alias);
if ($idByAlias)
{
$id = $idByAlias->getId();
}
}
if ($id == null && $alias != null)
{
$product = $product = Doctrine::getTable('Product')->findOneByAlias($alias);
if ($product)
{
if (count($product->getCatProducts()) > 0)
{
$id = $product->getCatProducts()->getFirst()->getId();
}
}
}
if ($id != null)
{
$relations = Doctrine_Query::create()
->from('catParent cp')
->where('cp.cat_id = ?', $id)
->fetchArray();
$ids[] = $id;
if ($relations)
{
foreach ($relations as $relation)
{
$ids[] = $relation['parent_id'];
}
}
$this->open = $ids;
}
}
public function executeLkLeftMenu(sfWebRequest $request)
{
$this->path = $request->getPathInfo();
if ($request->hasParameter('orderId'))
{
$this->path = '/personal/profile/';
}
$this->links = array(
array(
'url' => url_for('@personal_profile'),
'anchor' => 'История заказов'
),
array(
'url' => url_for('@personal_profile_settings'),
'anchor' => 'Настройки профиля'
),
array(
'url' => url_for('@personal_profile_feedback'),
'anchor' => 'Обратная связь'
)
);
}
public function executeFilter(sfWebRequest $request)
{
if($this->cat->getIsFilter() && count($this->product_ids) > 0){
$this->culture = $this->getUser()->getCulture();
$this->lists = Doctrine_Query::create()
->select("v.id, v.product_id, v.prop_id, v.value, p.id, p.isList, pt.*, l.id, l.product_prop_id, lt.*")
->from("ProductProp p")
->innerJoin("p.Translation pt WITH pt.lang = '" . $this->culture . "'")
->innerJoin("p.ProductPropList l")
->innerJoin("l.Translation lt WITH lt.lang = '" . $this->culture . "'")
->innerJoin("p.ProductPropValue v")
->whereIn("v.product_id", $this->product_ids)
->andWhere("p.isList = 1")
->andWhere("l.id = v.value")
->fetchArray();
$this->values = Doctrine_Query::create()
->select("v.id, v.product_id, v.prop_id, v.value, MIN(v.value) AS min, MAX(v.value) AS max, p.id, p.isList, t.*")
->from("ProductPropValue v")
->innerJoin("v.ProductProp p")
->innerJoin("p.Translation t WITH t.lang = '" . $this->culture . "'")
->whereIn("v.id", $this->product_ids)
->groupBy("v.prop_id")
->fetchArray();
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment