index.php 11.2 KB
<?php
    /**
     * @var \yii\web\View                    $this
     * @var \artbox\order\models\Basket      $basket
     * @var \artbox\catalog\models\Variant[] $variants
     * @var \artbox\catalog\models\Product[] $topItems
     */
    use artbox\core\helpers\ImageHelper;
    use yii\bootstrap\Html;
    
    $formatter = \Yii::$app->formatter;
    $sum = 0;
    $sumDiscount = 0;
    foreach ($variants as $variant) {
        $count = $basket->getItem($variant->id)[ 'count' ];
        $sum += $variant->price * $count;
        if (!empty($variant->price_old)) {
            $sumDiscount += ( $variant->price_old - $variant->price ) * $count;
        }
    }
?>
<div id="content">
  <div class="container">
    <div class="row">
      <div id="basket" class="col-xs-12 basket-container clearfix">
          <?php
              if (!empty($variants)) {
                  ?>
                  <div class="row">
                    <div class="col-md-9 clearfix">
                  <h1><?php echo \Yii::t('app', 'Ваша корзина'); ?></h1>
                  
                  <div class="box">
                    
                    <div class="table-responsive">
                      <table class="table">
                        <thead>
                          <tr>
                            <th colspan="2"><?php echo \Yii::t('app', 'Продукт'); ?></th>
                            <th><?php echo \Yii::t('app', 'Кількість'); ?></th>
                            <th><?php echo \Yii::t('app', 'Ціна за одиницю'); ?></th>
                            <th><?php echo \Yii::t('app', 'Знижка'); ?></th>
                            <th colspan="2"><?php echo \Yii::t('app', 'Всього'); ?></th>
                          </tr>
                        </thead>
                        <tbody>
                            <?php
                                foreach ($variants as $variant) {
                                    $count = $basket->getItem($variant->id)[ 'count' ];
                                    ?>
                                  <tr data-id="<?php echo $variant->id; ?>" class="product-row-basket">
                                    <td>
                                        <?php
                                            echo Html::a(
                                                ImageHelper::set($variant->product->image->getPath())
                                                           ->fillResize(50, 50)
                                                           ->renderImage(
                                                               [
                                                                   'alt'   => $variant->product->lang->title,
                                                                   'title' => $variant->product->lang->title,
                                                               ]
                                                           ),
                                                [
                                                    '/product/view',
                                                    'id' => $variant->product->id,
                                                ],
                                                [
                                                    'target' => '_blank',
                                                ]
                                            );
                                        ?>
                                    </td>
                                    <td>
                                        <?php
                                            echo Html::a(
                                                $variant->product->lang->title,
                                                [
                                                    '/product/view',
                                                    'id' => $variant->product->id,
                                                ],
                                                [
                                                    'target' => '_blank',
                                                ]
                                            );
                                        ?>
                                    </td>
                                    <td>
                                        <?php
                                            echo Html::input(
                                                'number',
                                                '',
                                                $count,
                                                [
                                                    'class' => 'form-control increase-product-basket',
                                                ]
                                            );
                                        ?>
                                    </td>
                                    <td>
                                        <?php
                                            echo $formatter->asDecimal($variant->price ? : 0, 2);
                                        ?>
                                    </td>
                                    <td>
                                        <?php
                                            if (!empty($variant->price_old)) {
                                                echo $formatter->asDecimal($variant->price_old - $variant->price, 2);
                                            } else {
                                                echo $formatter->asDecimal(0, 2);
                                            }
                                        ?>
                                    </td>
                                    <td>
                                        <?php
                                            echo $formatter->asDecimal(
                                                ( $variant->price ? : 0 ) * $count,
                                                2
                                            );
                                        ?>
                                    </td>
                                    <td><a href="#" class="remove-product-cart"><i class="fa fa-trash-o"></i></a>
                                    </td>
                                  </tr>
                                    <?php
                                }
                            ?>
                        </tbody>
                        <tfoot>
                          <tr>
                            <th colspan="5"><?php echo \Yii::t('app', 'Всього'); ?></th>
                            <th colspan="2"><?php echo $formatter->asDecimal($sum, 2); ?></th>
                          </tr>
                        </tfoot>
                      </table>
                    
                    </div>
                    <!-- /.table-responsive -->
                    
                    <div class="box-footer">
                      <div class="pull-left">
                          <?php
                              echo Html::a(
                                  Html::icon('chevron-left', [ 'prefix' => 'fa fa-' ]) . \Yii::t(
                                      'app',
                                      ' Подовжити покупки'
                                  ),
                                  [ 'site/index' ],
                                  [
                                      'class' => 'btn btn-default',
                                  ]
                              )
                          ?>
                      </div>
                      <div class="pull-right">
                          <?php
                              echo Html::a(
                                  \Yii::t(
                                      'app',
                                      ' Оформити замовлення '
                                  ) . Html::icon('chevron-right', [ 'prefix' => 'fa fa-' ]),
                                  [ 'checkout/info' ],
                                  [
                                      'class' => 'btn btn-success',
                                  ]
                              )
                          ?>
                      </div>
                    </div>
                  
                  </div>
                  <!-- /.box -->
                
                </div>
                
                
                     <div class="col-md-3">
                  <div class="box" id="order-summary">
                    <div class="box-header">
                      <h3><?php echo Yii::t('app','Total count')?></h3>
                    </div>
                    <p class="text-muted small"><?php echo \Yii::t(
                            'app',
                            'total_text'
                        ); ?></p>
                    
                    <div class="table-responsive">
                      <table class="table">
                        <tbody>
                          <tr>
                            <td><?php echo \Yii::t('app', 'Всього за товари'); ?></td>
                            <th><?php echo $formatter->asDecimal($sum, 2); ?></th>
                          </tr>
                          <tr>
                            <td><?php echo \Yii::t('app', 'Сума знижки'); ?></td>
                            <th><?php echo $formatter->asDecimal($sumDiscount, 2); ?></th>
                          </tr>
                          <tr class="total">
                            <td><?php echo \Yii::t('app', 'Всього до сплати'); ?></td>
                            <th><?php echo $formatter->asDecimal($sum, 2); ?></th>
                          </tr>
                        </tbody>
                      </table>
                    </div>
                  </div>
                </div>
                  </div>

                  <?php
              } else { ?>
<!--                  echo Html::tag('p', \Yii::t('app', 'Ваша корзина пуста!'));-->
                  <div class="empty_card">Ваша корзина пуста!</div>
              <?php }
          ?>
      </div>
        <?php
            if (!empty($topItems)) {
                ?>
       <div class="col-xs-12 heading text-center" style="margin-top: 40px;">
        <h2><?php echo \Yii::t('app', 'Дивіться також'); ?></h2>
      </div>
       <div class="col-xs-12 product-carousel">
        <div class="homepage owl-carousel">
            <?php
                $newItemsArrays = array_chunk($topItems, 4);
                foreach ($newItemsArrays as $newItemsArray) {
                    ?>
                  <div class="products">
                      <?php
                          foreach ($newItemsArray as $product) {
                              echo $this->render(
                                  '@frontend/views/site/_slider_product',
                                  [
                                      'product' => $product,
                                  ]
                              );
                          }
                      ?>
                  </div>
                    <?php
                }
            ?>
        </div>
      </div>
                <?php
            }
        ?>
    </div>
  </div>
</div>