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

two

parent 48680c56
...@@ -344,30 +344,6 @@ class basketActions extends sfActions ...@@ -344,30 +344,6 @@ class basketActions extends sfActions
$this->order_form->bind($request->getParameter($this->order_form->getName())); $this->order_form->bind($request->getParameter($this->order_form->getName()));
if($this->order_form->isValid()){ 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(); $order = $this->order_form->save();
$basket->setBasketOrderId($order->getId()); $basket->setBasketOrderId($order->getId());
$basket->save(); $basket->save();
...@@ -388,45 +364,22 @@ class basketActions extends sfActions ...@@ -388,45 +364,22 @@ class basketActions extends sfActions
$products['sum'] = 0; $products['sum'] = 0;
foreach ($basket->getBasketOffer() as $key => $basketOffer) foreach ($basket->getBasketOffer()->toArray() as $key => $basketOffer)
{ {
$offerTranslation = Doctrine_Query::create() $offerTranslation = Doctrine_Query::create()
->select('o.*, t.*') ->select('o.*, t.*')
->from('Offer o') ->from('Offer o')
->where('o.id = ?', intval($basketOffer->getOfferId())) ->where('o.id = ?', intval($basketOffer['offer_id']))
->leftJoin('o.Translation t') ->leftJoin('o.Translation t')
->fetchArray(); ->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]['name'] = $offerTranslation[0]['Translation']['ru']['title'];
$products['elem'][$key]['price'] = number_format(intval($basketOffer->getPrice())/$basketOffer->getAmount(), 0, ',', ' '); $products['elem'][$key]['price'] = intval($basketOffer['price'])/$basketOffer['amount'];
$products['elem'][$key]['count'] = $basketOffer->getAmount(); $products['elem'][$key]['count'] = $basketOffer['amount'];
$products['sum'] = $products['sum'] + intval($basketOffer->getPrice()); $products['sum'] = $products['sum'] + intval($basketOffer['price']);
}
$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') $emails_dirty = NotificationEmailsTable::getInstance()->createQuery('e')
->select('e.email') ->select('e.email')
...@@ -467,6 +420,7 @@ class basketActions extends sfActions ...@@ -467,6 +420,7 @@ class basketActions extends sfActions
); );
} }
$this->redirect('@basket_complete'); $this->redirect('@basket_complete');
} }
} }
......
...@@ -24,8 +24,5 @@ class basketComponents extends sfComponents ...@@ -24,8 +24,5 @@ class basketComponents extends sfComponents
if(count($this->offers) > 0){ if(count($this->offers) > 0){
$this->info = $user->getBasketInfo(); $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
...@@ -13,15 +13,12 @@ ...@@ -13,15 +13,12 @@
</thead> </thead>
<tbody valign="middle"> <tbody valign="middle">
<?php <?php
if (!isset($percent)) {
$percent = false;
}
$summ = 0;
$productFreeShipping = 1; $productFreeShipping = 1;
foreach ($offers as $offer){ foreach ($offers as $offer){
if ($offer['Product']['free_shipping'] == 0) { if ($offer['Product']['free_shipping'] == 0) {
$productFreeShipping = 0; $productFreeShipping = 0;
} }
//print_r($offer);
$quantity_type = $offer['Translation'][$culture]['quantity_type']; $quantity_type = $offer['Translation'][$culture]['quantity_type'];
if ($offer['quantity_type_select']) { 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']] : ''); $quantity_type = (isset(Offer::$quantity_type_select_values[$offer['quantity_type_select']]) ? Offer::$quantity_type_select_values[$offer['quantity_type_select']] : '');
...@@ -33,7 +30,7 @@ ...@@ -33,7 +30,7 @@
$offer_img = $offer_imgs[0]; $offer_img = $offer_imgs[0];
} }
//print_r($offer['Product']); //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 valign="top"><a style="border: none" href="/' . $offer['Translation'][$culture]['lang'] . '/product/' . $offer['Product']['alias'] . '/"><div class="basket_img" ' . ($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><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>';
echo '<td class="align_center"><div class="product_counter" data-id="' . $offer['id'] . '">'; echo '<td class="align_center"><div class="product_counter" data-id="' . $offer['id'] . '">';
...@@ -41,22 +38,15 @@ ...@@ -41,22 +38,15 @@
echo '<input autocomplete="off" type="text" class="product_counter_val" value="' . $offer['BasketOffer'][0]['amount'] . '" data-symbol="false" onkeyup="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 '<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>'; 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">' . number_format($offer['price'], 0, ',', ' ') . '&nbsp;<span class="rub">i</span></td>';
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">' . number_format($offer['BasketOffer'][0]['price'], 0, ',', ' ') . '&nbsp;<span class="rub">i</span></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 '<td width="1" align="center"><div class="basket_clean" onclick="basket.delete(this);"></div></td>';
echo '</tr>'; echo '</tr>';
} }
?> ?>
</tbody> </tbody>
</table> </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 class="basket_total" data-delivery-info="<?php echo $productFreeShipping ?>"><?php echo __('Итого');?>:<div class="basket_total__price"><?php echo number_format($info['price'], 0, ',', ' ');?></div>&nbsp;<span class="rub">i</span></div>
</div> </div>
</div> </div>
......
...@@ -42,7 +42,7 @@ echo '<h1 class="content_title">' . __('Корзина') . '</h1>'; ...@@ -42,7 +42,7 @@ echo '<h1 class="content_title">' . __('Корзина') . '</h1>';
<?php <?php
echo '<h2>' . __('Контактные данные') . ':</h2>'; 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"><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="Номер телефона" onchange="form_validator.check($(this))" onkeyup="form_validator.check($(this))" data-check-rule="phone" class="basket_buyer__inp_name 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>'; 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>
...@@ -86,126 +86,11 @@ echo '<h1 class="content_title">' . __('Корзина') . '</h1>'; ...@@ -86,126 +86,11 @@ echo '<h1 class="content_title">' . __('Корзина') . '</h1>';
<?php <?php
echo '<h2>' . __('Общая сумма заказа') . '</h2>'; echo '<h2>' . __('Общая сумма заказа') . '</h2>';
echo '<div class="basket_order__price">' . $info['priceText'] . '&nbsp;<span class="rub">i</span></div>'; 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>'; echo '<input type="submit" class="btn green_b_btn order_btn btn_disabled" value="' . __('Оформить заказ') . '" onclick="yaCounter48466937.reachGoal(\'ORDER\')" disabled>';
?> ?>
</div> </div>
<script type="text/javascript"> <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 () { $(document).ready(function () {
var delivery_info = $('.basket_total').data('delivery-info'); var delivery_info = $('.basket_total').data('delivery-info');
console.log(delivery_info); console.log(delivery_info);
......
...@@ -141,7 +141,7 @@ class catalogActions extends sfActions ...@@ -141,7 +141,7 @@ class catalogActions extends sfActions
->orderBy('p.sort asc'); ->orderBy('p.sort asc');
//->andWhere("CHAR_LENGTH(p.product_img) > 0"); //->andWhere("CHAR_LENGTH(p.product_img) > 0");
$products_q = Doctrine_Query::create() $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.*") ->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, ot.*, ppv.*")
->from("Product p") ->from("Product p")
->leftJoin("p.CatProduct c") ->leftJoin("p.CatProduct c")
->leftJoin("p.Translation t") ->leftJoin("p.Translation t")
......
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
<tr> <tr>
<td colspan="5"> <td colspan="5">
<i class="br40"></i> <i class="br40"></i>
<a href="" class="btn green_btn calculator_table__btn">Добавить в корзину</a> <a href="" class="btn green_btn calculator_table__btn" onclick="yaCounter48466937.reachGoal('ADD');">Добавить в корзину</a>
</td> </td>
</tr> </tr>
</tbody> </tbody>
......
...@@ -50,11 +50,3 @@ echo '<h1 class="content_title">' . $translation[$culture]['title'] . '</h1>'; ...@@ -50,11 +50,3 @@ echo '<h1 class="content_title">' . $translation[$culture]['title'] . '</h1>';
} }
?> ?>
</div> </div>
<script>
$('.discount_available').on('click', function (e) {
if ($(window).width() < 650) {
$(this).toggleClass('show');
}
})
</script>
<?php
/**
* discount actions.
*
* @package sf
* @subpackage discount
* @author Atma
* @version SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
*/
class discountActions extends sfActions
{
public function executeIndex(sfWebRequest $request)
{
if ($request->hasParameter('discount')) {
$data = $request->getParameter('discount');
$discount = Doctrine::getTable('Discount')->findOneByUrl($data['url']);
if ($discount) {
$date_now = new DateTime('now');
$date_now->modify('+1 day');
$date_limit = new DateTime('now');
$date_limit->modify('-30 day');
sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');
$check_discounts = Doctrine_Query::create()
->select()
->from('DiscountPhone dp')
->where('dp.phone = ?', $data['phone'])
->andWhere('dp.discount_id != ?', $discount->getId())
->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\')')
->fetchArray();
if (count($check_discounts) == 1) {
echo include_partial('discount/form', array('status' => 'error', 'error' => 'У вас уже есть скидка ' . $check_discounts[0]["active_discount"] . '%'));
} else {
$check_phone = Doctrine_Query::create()
->select()
->from('DiscountPhone dp')
->where('dp.phone = ?', $data['phone'])
->andWhere('dp.discount_id = ?', $discount->getId())
->fetchArray();
if (count($check_phone) == 0) {
$discount_phone = new DiscountPhone();
$discount_phone->setDiscountId($discount->getId());
$discount_phone->setPhone($data['phone']);
$discount_phone->save();
$this->getUser()->setAttribute('number_of_views', 3);
$this->getUser()->setAttribute('phone_number', $data['phone']);
$this->getUser()->setAttribute('active_discount', 3);
echo include_partial('discount/form', array('status' => 'complete'));
} else {
if (is_numeric($check_phone[0]['order_id'])) {
echo include_partial('discount/form', array('status' => 'error', 'error' => 'Вы уже использовали данную скидку'));
} else {
$date_created = new DateTime($check_phone[0]['created_at']);
$interval = $date_now->diff($date_created);
$interval = $interval->format('%a');
$remained = 30 - $interval;
if (intval($remained) <= 30) {
echo include_partial('discount/form', array('status' => 'error', 'error' => "У вас уже есть данная скидка.\n Осталось " . $remained . " дней"));
} else {
echo include_partial('discount/form', array('status' => 'error', 'error' => 'Вы не можете активировать скидку второй раз'));
}
}
}
}
}
}
return sfView::NONE;
}
public function executeCheck_discount(sfWebRequest $request)
{
if ($request->hasParameter('phone') && $request->getParameter('phone') != 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 = ?', $request->getParameter('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 = $discount->getFirst();
$this->getUser()->setAttribute('active_discount', $discount->getActiveDiscount());
$this->getUser()->setAttribute('phone', $request->getParameter('phone'));
//sfContext::getInstance()->getConfiguration()->loadHelpers('Components');
//$body = include_component('basket', 'basket');
echo json_encode(array('status' => 'success', 'active_discount' => $discount->getActiveDiscount(), 'body' => $this->getComponent('basket', 'basket')));
} else {
$this->getUser()->setAttribute('active_discount', false);
$this->getUser()->setAttribute('phone', false);
echo json_encode(array('status' => 'success', 'active_discount' => 0, 'body' => $this->getComponent('basket', 'basket')));
}
}
return sfView::NONE;
}
public function executeCheck_discount_term (sfWebRequest $request) {
if ($this->getUser()->hasAttribute('active_discount') && $this->getUser()->getAttribute('active_discount') != false && $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');
$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($discount) > 0) {
$discount = $discount->getFirst();
echo json_encode(array('status' => 'success', 'active_discount' => $discount->getActiveDiscount()));
} else {
echo json_encode(array('status' => 'success', 'active_discount' => 0));
}
}else {
echo json_encode(array('status' => 'success', 'active_discount' => 0));
}
return sfView::NONE;
}
}
<?php
class discountComponents extends sfComponents
{
public function executeForm($request)
{
if ($request->hasParameter('url')) {
$discount = Doctrine::getTable('Discount')->findOneByUrl($request->getParameter('url'));
if ($discount) {
$this->status = 'success';
$this->discount = $request->getParameter('url');
} else {
$this->status = 'error';
$this->error = 'Cкидка не найдена';
$this->discount = $request->getParameter('url');
}
}
}
}
\ No newline at end of file
<?php
if ($status == 'success') {
echo '<div class="image_discount">';
echo '</div>';
echo '<div class="form_discount">';
echo '<div id="discount" class="discount_form__title">' . __('Вы получили скидку 3%') . '</div>';
echo '<div class="discount_form_text">Введите номер телефона, чтобы сохранить скидку</div>';
echo '<form class="discount_form" method="post" action="' . url_for('@discount') . '" onsubmit="discount.submit(this);return false;">';
echo '<div class="discount_form__process">';
echo '<div class="discount_form__inp_wrap"><input name="discount[phone]" type="text" id="phone_mask" class="form_type_1__input validate_it" placeholder="Номер телефона" onkeyup="form_validator.check($(this))" data-check-rule="phone" autocomplete="off" required></div>';
echo '<input name="discount[url]" type="hidden" value="' . $discount . '">';
$culture = $sf_user->getCulture();
?>
<div class="discount_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="discount_form__submit green_b_btn send btn_disabled" value="' . __('Cохранить') . '" disabled />';
echo '</div>';
echo '</form>';
echo '<div class="discount_form_head_text">Хотите скидку больше?<br>Тогда посмотрите семь товаров.</div>';
echo '<div class="discount_form_text">В течение 30 дней вы можете сделать заказ со скидкой.</div>';
echo '</div>';
} elseif ($status == 'complete') {
echo '<div class="form_discount">';
echo '<div id="discount" class="discount_form__title">' . __('Скидка успешно активирована!') . '</div>';
echo '<div class="discount_form__submit green_b_btn" onclick="discount.close();">Понятно</div>';
echo '</div>';
} elseif ($status == 'error') {
echo '<div class="form_discount">';
echo '<div id="discount" class="discount_form__title">' . __($error) . '</div>';
echo '<div class="discount_form__submit green_b_btn" onclick="discount.close();">Понятно</div>';
echo '</div>';
}
?>
<script>
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;
}
});
</script>
...@@ -17,6 +17,7 @@ class mainActions extends sfActions ...@@ -17,6 +17,7 @@ class mainActions extends sfActions
*/ */
public function executeIndex(sfWebRequest $request) public function executeIndex(sfWebRequest $request)
{ {
/**/
$this->setLayout('layoutHome'); $this->setLayout('layoutHome');
$this->video = Doctrine_Query::create() $this->video = Doctrine_Query::create()
->select("v.*, t.*") ->select("v.*, t.*")
...@@ -61,7 +62,6 @@ class mainActions extends sfActions ...@@ -61,7 +62,6 @@ class mainActions extends sfActions
->andWhere("c.is_main = 1") ->andWhere("c.is_main = 1")
->orderBy("RAND()") ->orderBy("RAND()")
->fetchOne(); ->fetchOne();
} }
public function executeDl(sfWebRequest $request) public function executeDl(sfWebRequest $request)
{ {
......
<table class="lending" style="width: 100%" cellspacing="0" cellpadding="0"> <table class="lending" style="width: 100%" cellspacing="0" cellpadding="0">
<tr> <tr>
<td> <td>
......
...@@ -56,41 +56,5 @@ class productActions extends sfActions ...@@ -56,41 +56,5 @@ class productActions extends sfActions
$this->setLayout('layoutPage'); $this->setLayout('layoutPage');
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);
}
}
}
}
} }
} }
...@@ -3,24 +3,14 @@ if (isset($product)) { ...@@ -3,24 +3,14 @@ if (isset($product)) {
$translation = $product['Translation']; $translation = $product['Translation'];
$productImg = explode(';', $product['product_img']); $productImg = explode(';', $product['product_img']);
$productImg = (count($productImg) > 0 ? $productImg[0] : false); $productImg = (count($productImg) > 0 ? $productImg[0] : false);
$q = Doctrine::getTable('Product')->findOneById($product['id'])->getOffer(); echo '<div class="catalog_category_child_item">';
$discount_available = false;
foreach ($q as $offer) {
if ($offer->getDiscountAvailable() == 1) {
$discount_available = true;
break;
}
}
echo '<div class="catalog_category_child_item ' . ($discount_available ? 'discount' : '') . '">';
if ($discount_available) {
echo '<div class="discount_available"><div class="discount_available_desc">Ищите наши QR-коды в видео и соц. сетях и забирайте скидку</div><div class="discount_available_title">Доступен со скидкой</div></div>';
}
echo '<' . ($product['is_detail'] ? 'a' : 'span') . ' href="' . url_for("@product_show?alias=" . $product['alias']) . '" class="anb">'; echo '<' . ($product['is_detail'] ? 'a' : 'span') . ' href="' . url_for("@product_show?alias=" . $product['alias']) . '" class="anb">';
if($productImg){ if($productImg){
echo '<img src="/i/n.gif" style="background-image: url(/u/i/' . Page::replaceImageSize($productImg, 'S') . ');" />'; echo '<img src="/i/n.gif" style="background-image: url(/u/i/' . Page::replaceImageSize($productImg, 'S') . ');" />';
}else }else
{ {
$offerImg = ''; $offerImg = '';
$q = Doctrine::getTable('Product')->findOneById($product['id'])->getOffer();
foreach ($q as $offer) { foreach ($q as $offer) {
if (strlen($offer->getImg()) > 3) if (strlen($offer->getImg()) > 3)
$offerImg = $offer->getImg(); $offerImg = $offer->getImg();
......
...@@ -115,7 +115,7 @@ $view = 'much'; ...@@ -115,7 +115,7 @@ $view = 'much';
<input data-initialized="1" data-id="<?php echo $offer['id']; ?>" type="radio" name="offer" onchange="counterLite.change($(this))"> <input data-initialized="1" data-id="<?php echo $offer['id']; ?>" type="radio" name="offer" onchange="counterLite.change($(this))">
<?php if ($offer['price'] > 1) { ?> <?php if ($offer['price'] > 1) { ?>
<table width="100%" cellpadding="0" cellspacing="0"> <table width="100%" cellpadding="0" cellspacing="0">
<tr <?php echo ($offer['discount_available'] == 1 ? 'class="discount' : '') ?>"> <tr>
<td><?php echo $offer['title'] . $quantity_type; ?></td> <td><?php echo $offer['title'] . $quantity_type; ?></td>
<td style="white-space: nowrap;" align="right"> <td style="white-space: nowrap;" align="right">
<?php echo $offer_str; ?> <?php echo $offer_str; ?>
...@@ -125,7 +125,7 @@ $view = 'much'; ...@@ -125,7 +125,7 @@ $view = 'much';
<div class="product_counter min" data-id="<?php echo $offer['id']; ?>" data-price="<?php echo $offer['price'];?>"> <div class="product_counter min" data-id="<?php echo $offer['id']; ?>" data-price="<?php echo $offer['price'];?>">
<input type="button" class="product_counter_minus" data-symbol="-" onclick="counterLite.update($(this))"> <input type="button" class="product_counter_minus" data-symbol="-" onclick="counterLite.update($(this))">
<input autocomplete="off" type="text" class="product_counter_val" value="<?php echo ( $infoAmount ? $infoAmount : 0 ) ?>" data-symbol="-+" onkeyup="counterLite.update($(this))"> <input autocomplete="off" type="text" class="product_counter_val" value="<?php echo ( $infoAmount ? $infoAmount : 0 ) ?>" data-symbol="-+" onkeyup="counterLite.update($(this))">
<input type="button" class="product_counter_plus" data-symbol="+" onclick="counterLite.update($(this))"> <input type="button" class="product_counter_plus" data-symbol="+" onclick="counterLite.update($(this)); yaCounter48466937.reachGoal('ADD');">
</div> </div>
</td> </td>
</tr> </tr>
......
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