Example #1
0
 public function ajaxRecount($data)
 {
     if (!is_array($data) || empty($data)) {
         return;
     }
     $currentData = $this->getData();
     foreach ($data as $index => $quantity) {
         if ((int) $quantity < 1) {
             $quantity = 1;
         }
         if (isset($currentData[$index])) {
             $currentData[$index]['quantity'] = (int) $quantity;
             $data = $currentData[$index];
             //print_r($currentData[$index]);die;
             if ($data['configurable_id']) {
                 $productModel = ShopProduct::model()->findByPk($index);
                 $rowTotal = $data['quantity'] * ShopProduct::calculatePrices($productModel, $data['variants'], $data['configurable_id']);
             } else {
                 if (Yii::app()->settings->get('shop', 'wholesale')) {
                     $rowTotal = $data['quantity'] * $data['pcs'] * $data['price'];
                 } else {
                     $rowTotal = $data['quantity'] * $data['price'];
                 }
             }
         }
     }
     $this->session['cart_data'] = $currentData;
     echo CJSON::encode(array('rowTotal' => ShopProduct::formatPrice(Yii::app()->currency->convert($rowTotal)), 'totalPrice' => ShopProduct::formatPrice(Yii::app()->currency->convert(Yii::app()->cart->getTotalPrice()))));
 }
Example #2
0
}
?>
        </div>
    </a>
    <?php 
if ($items) {
    ?>
        <ul class="dropdown-menu">
            <li>
                <?php 
    $i = 0;
    foreach ($items as $index => $product) {
        $i++;
        ?>
                    <?php 
        $price = ShopProduct::calculatePrices($product['model'], $product['variant_models'], $product['configurable_id']);
        // Display image
        $thumbSize = '50x50';
        if (isset($product['model']->mainImage)) {
            $imgSource = $product['model']->mainImage->getUrl($thumbSize);
            $img = Html::link(Html::image($imgSource, ''), $product['model']->mainImage->getUrl($thumbSize), array('class' => ''));
        } else {
            $imgSource = 'http://placehold.it/' . $thumbSize;
            $img = Html::link(Html::image($imgSource, ''), '#', array('class' => ''));
        }
        ?>
                    <div class="cart-item product-summary">
                        <div class="row" style="margin: 5px 0;">
                            <div class="col-xs-4" style="padding:0;">
                                <div class="image">
                                    <?php 
 /**
  * Create new order
  * @return Order
  */
 public function createOrder()
 {
     if (Yii::app()->cart->countItems() == 0) {
         return false;
     }
     Yii::import('mod.cart.models.Order');
     Yii::import('mod.cart.models.OrderProduct');
     $order = new Order();
     // Set main data
     $order->user_id = Yii::app()->user->isGuest ? null : Yii::app()->user->id;
     $order->user_name = $this->form->name;
     $order->user_email = $this->form->email;
     $order->user_phone = $this->form->phone;
     $order->user_address = $this->form->address;
     $order->user_comment = $this->form->comment;
     $order->delivery_id = $this->form->delivery_id;
     $order->payment_id = $this->form->payment_id;
     if ($order->validate()) {
         if ($order->save()) {
         }
     } else {
         throw new CHttpException(503, Yii::t('CartModule.default', 'ERROR_CREATE_ORDER'));
     }
     // Process products
     foreach (Yii::app()->cart->getDataWithModels() as $item) {
         $ordered_product = new OrderProduct();
         $ordered_product->order_id = $order->id;
         $ordered_product->product_id = $item['model']->id;
         $ordered_product->configurable_id = $item['configurable_id'];
         $ordered_product->currency_id = $item['model']->currency_id;
         $ordered_product->supplier_id = $item['model']->supplier_id;
         $ordered_product->name = $item['model']->name;
         $ordered_product->quantity = $item['quantity'];
         $ordered_product->sku = $item['model']->sku;
         $ordered_product->date_create = $order->date_create;
         // if($item['currency_id']){
         //     $currency = ShopCurrency::model()->findByPk($item['currency_id']);
         //$ordered_product->price = ShopProduct::calculatePrices($item['model'], $item['variant_models'], $item['configurable_id']) * $currency->rate;
         // }else{
         $ordered_product->price = ShopProduct::calculatePrices($item['model'], $item['variant_models'], $item['configurable_id']);
         // }
         // Process configurable product
         if (isset($item['configurable_model']) && $item['configurable_model'] instanceof ShopProduct) {
             $configurable_data = array();
             $ordered_product->configurable_name = $item['configurable_model']->name;
             // Use configurable product sku
             $ordered_product->sku = $item['configurable_model']->sku;
             // Save configurable data
             $attributeModels = ShopAttribute::model()->cache($this->cacheTime)->findAllByPk($item['model']->configurable_attributes);
             foreach ($attributeModels as $attribute) {
                 $method = 'eav_' . $attribute->name;
                 $configurable_data[$attribute->title] = $item['configurable_model']->{$method};
             }
             $ordered_product->configurable_data = serialize($configurable_data);
         }
         // Save selected variants as key/value array
         if (!empty($item['variant_models'])) {
             $variants = array();
             foreach ($item['variant_models'] as $variant) {
                 $variants[$variant->attribute->title] = $variant->option->value;
             }
             $ordered_product->variants = serialize($variants);
         }
         $ordered_product->save();
     }
     // Reload order data.
     $order->refresh();
     //@todo panix text email tpl
     // All products added. Update delivery price.
     $order->updateDeliveryPrice();
     // Send email to user.
     $this->sendClientEmail($order);
     // Send email to admin.
     $this->sendAdminEmail($order);
     if (Yii::app()->hasModule('sms')) {
         /* $this->widget('mod.sms.widgets.SMSWidget', array(
                'key' => 'ADMIN_ORDER_BEFORE',
                'model' => $order
            ));*/
         $this->widget('mod.sms.widgets.SMSWidget', array('key' => 'CLIENT_ORDER_BEFORE', 'model' => $order));
     }
     return $order;
 }
Example #4
0
 /**
  * @param array $products
  */
 public function renderProducts(array $products)
 {
     foreach ($products as $p) {
         if (!count($p->variants)) {
             $this->renderOffer($p, array('url' => Yii::app()->createAbsoluteUrl('/shop/product/view', array('seo_alias' => $p->seo_alias)), 'price' => Yii::app()->currency->convert($p->price, $this->_config['yandexMarket_currency_id']), 'currencyId' => $this->currencyIso, 'categoryId' => $p->mainCategory->id, 'picture' => $p->mainImage ? Yii::app()->createAbsoluteUrl($p->mainImage->getUrl()) : null, 'name' => CHtml::encode($p->name), 'description' => $this->clearText($p->short_description)));
         } else {
             foreach ($p->variants as $v) {
                 $name = strtr('{product}({attr} {option})', array('{product}' => $p->name, '{attr}' => $v->attribute->title, '{option}' => $v->option->value));
                 $hashtag = '#' . $v->attribute->name . ':' . $v->option->id;
                 $this->renderOffer($p, array('url' => Yii::app()->createAbsoluteUrl('/shop/product/view', array('seo_alias' => $p->seo_alias)) . $hashtag, 'price' => Yii::app()->currency->convert(ShopProduct::calculatePrices($p, $p->variants, 0), $this->_config['yandexMarket_currency_id']), 'currencyId' => $this->currencyIso, 'categoryId' => $p->mainCategory->id, 'picture' => $p->mainImage ? Yii::app()->createAbsoluteUrl($p->mainImage->getUrl()) : null, 'name' => CHtml::encode($name), 'description' => $this->clearText($p->short_description)));
             }
         }
     }
 }