diff --git a/common/models/OrderItems.php b/common/models/OrderItems.php index a950826..11dc3c8 100644 --- a/common/models/OrderItems.php +++ b/common/models/OrderItems.php @@ -14,7 +14,7 @@ use Yii; * @property double $price * * @property Orders $order - * @property Product $item + * @property ProductVariant $item */ class OrderItems extends \yii\db\ActiveRecord { @@ -35,7 +35,7 @@ class OrderItems extends \yii\db\ActiveRecord [['order_id', 'item_id', 'item_count'], 'integer'], [['price'], 'number'], [['order_id'], 'exist', 'skipOnError' => true, 'targetClass' => Orders::className(), 'targetAttribute' => ['order_id' => 'order_id']], - [['item_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => ['item_id' => 'product_id']], + [['item_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductVariant::className(), 'targetAttribute' => ['item_id' => 'product_variant_id']], ]; } @@ -66,6 +66,6 @@ class OrderItems extends \yii\db\ActiveRecord */ public function getItem() { - return $this->hasOne(Product::className(), ['product_id' => 'item_id']); + return $this->hasOne(ProductVariant::className(), ['product_variant_id' => 'item_id']); } } diff --git a/common/models/Orders.php b/common/models/Orders.php index 4d74b91..4c6afe0 100644 --- a/common/models/Orders.php +++ b/common/models/Orders.php @@ -3,7 +3,7 @@ namespace common\models; use Yii; - +use yii\behaviors\TimestampBehavior; /** * This is the model class for table "orders". * @@ -31,6 +31,7 @@ class Orders extends \yii\db\ActiveRecord return 'orders'; } + /** * @inheritdoc */ @@ -38,7 +39,7 @@ class Orders extends \yii\db\ActiveRecord { return [ [['customer_id', 'delivery', 'payment', 'status', 'created_at', 'updated_at'], 'integer'], - [['name', 'email', 'phone', 'created_at', 'updated_at'], 'required'], + [['name', 'email', 'phone'], 'required'], [['name', 'email', 'code'], 'string', 'max' => 255], [['phone'], 'string', 'max' => 32], ]; @@ -47,6 +48,16 @@ class Orders extends \yii\db\ActiveRecord /** * @inheritdoc */ + public function behaviors() + { + return [ + TimestampBehavior::className(), + ]; + } + + /** + * @inheritdoc + */ public function attributeLabels() { return [ diff --git a/common/models/ProductVariant.php b/common/models/ProductVariant.php new file mode 100644 index 0000000..8de21d3 --- /dev/null +++ b/common/models/ProductVariant.php @@ -0,0 +1,78 @@ + 255], + [['product_unit_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductUnit::className(), 'targetAttribute' => ['product_unit_id' => 'product_unit_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'product_variant_id' => Yii::t('app', 'Product Variant ID'), + 'product_id' => Yii::t('app', 'Product ID'), + 'name' => Yii::t('app', 'Name'), + 'sku' => Yii::t('app', 'Sku'), + 'price' => Yii::t('app', 'Price'), + 'price_old' => Yii::t('app', 'Price Old'), + 'stock' => Yii::t('app', 'Stock'), + 'product_unit_id' => Yii::t('app', 'Product Unit ID'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getOrderItems() + { + return $this->hasMany(OrderItems::className(), ['item_id' => 'product_variant_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProductUnit() + { + return $this->hasOne(ProductUnit::className(), ['product_unit_id' => 'product_unit_id']); + } +} diff --git a/common/modules/product/models/ProductVariant.php b/common/modules/product/models/ProductVariant.php index a748284..e63190a 100644 --- a/common/modules/product/models/ProductVariant.php +++ b/common/modules/product/models/ProductVariant.php @@ -68,6 +68,14 @@ class ProductVariant extends \yii\db\ActiveRecord } /** + * @return \yii\db\ActiveQuery + */ + public function getProduct() + { + return $this->hasOne(Product::className(), ['product_id' => 'product_id']); + } + + /** * @inheritdoc * @return ProductVariantQuery the active query used by this AR class. */ diff --git a/common/widgets/BasketModal.php b/common/widgets/BasketModal.php index 6c4821a..8649b5c 100644 --- a/common/widgets/BasketModal.php +++ b/common/widgets/BasketModal.php @@ -1,6 +1,7 @@ session->get('order'); + unset($sessionData['order_id']); $count = count($sessionData); + $price = 0; if(is_array($sessionData) && !empty($sessionData)){ + + $variant = ProductVariant::find()->where(['product_variant_id'=>array_keys($sessionData)])->indexBy('product_variant_id')->all(); + + + foreach ($sessionData as $k => $item) { + $sessionData[$k]['item'] = $variant[$k]; + $price += $variant[$k]->price * $sessionData[$k]['num']; + } + + return $this->render('busket_modal',[ 'items'=>$sessionData, - 'count' => $count + 'count' => $count, + 'price' => $price ]); + } } diff --git a/common/widgets/views/busket_modal.php b/common/widgets/views/busket_modal.php index 6c9885b..90cb99f 100644 --- a/common/widgets/views/busket_modal.php +++ b/common/widgets/views/busket_modal.php @@ -3,30 +3,38 @@ * @var $items array data from session * @var $count integer count items in basket */ +use yii\helpers\Html; ?>
diff --git a/console/migrations/m160304_065108_product.php b/console/migrations/m160304_065108_product.php index 17dc750..48100e3 100644 --- a/console/migrations/m160304_065108_product.php +++ b/console/migrations/m160304_065108_product.php @@ -96,19 +96,30 @@ class m160304_065108_product extends Migration 'code' => $this->string(50)->notNull(), 'is_default' => $this->boolean() ], $tableOptions); - +// $this->addForeignKey('product_variant_product_unit_fkey', 'product_variant', 'product_unit_id', 'product_unit', 'product_unit_id', 'CASCADE', 'NO ACTION'); $this->addForeignKey('category_product_unit_fkey', 'category', 'product_unit_id', 'product_unit', 'product_unit_id', 'NO ACTION', 'NO ACTION'); } public function down() { + $this->dropForeignKey('category_name_fkey', 'category'); + $this->dropForeignKey('category_name_category_fkey', 'category_name'); + $this->dropForeignKey('brand_name_fkey', 'brand'); + $this->dropForeignKey('brand_name_brand_fkey', 'brand_name'); + $this->dropForeignKey('fki_product_id', 'product_category'); + $this->dropForeignKey('fki_category_id', 'product_category'); + $this->dropForeignKey('fki_brand_id', 'product'); + $this->dropForeignKey('product_variant_product_unit_fkey', 'product_variant'); + $this->dropForeignKey('category_product_unit_fkey', 'category'); $this->dropTable('{{%category}}'); $this->dropTable('{{%category_name}}'); $this->dropTable('{{%product_category}}'); $this->dropTable('{{%product}}'); $this->dropTable('{{%product_variant}}'); $this->dropTable('{{%product_unit}}'); + $this->dropTable('{{%brand_name}}'); + $this->dropTable('{{%brand}}'); } /* diff --git a/console/migrations/m160324_114404_orders_items_items_fk.php b/console/migrations/m160324_114404_orders_items_items_fk.php new file mode 100644 index 0000000..e8a32cc --- /dev/null +++ b/console/migrations/m160324_114404_orders_items_items_fk.php @@ -0,0 +1,21 @@ +dropForeignKey('orders_items_items_fk', '{{%order_items}}'); + $this->addForeignKey('orders_items_items_fk', '{{%order_items}}', 'item_id', '{{%product_variant}}', 'product_variant_id', 'RESTRICT', 'RESTRICT'); + } + + public function down() + { + $this->dropForeignKey('orders_items_items_fk', '{{%order_items}}'); + $this->addForeignKey('orders_items_items_fk', '{{%order_items}}', 'item_id', '{{%product}}', 'product_id', 'RESTRICT', 'RESTRICT'); + + } + +} diff --git a/frontend/assets/AppAsset.php b/frontend/assets/AppAsset.php index 40de0f5..c8d1046 100644 --- a/frontend/assets/AppAsset.php +++ b/frontend/assets/AppAsset.php @@ -41,7 +41,8 @@ class AppAsset extends AssetBundle 'js/jquery.jcarousellite-1.0.1.js', 'js/owl.carousel.js', 'js/script.js', - 'js/my_scripts.js' + 'js/my_scripts.js', + 'js/basket.js', ]; public $depends = [ diff --git a/frontend/controllers/OrdersController.php b/frontend/controllers/OrdersController.php index 4df7352..ab576bd 100644 --- a/frontend/controllers/OrdersController.php +++ b/frontend/controllers/OrdersController.php @@ -2,6 +2,10 @@ namespace frontend\controllers; +use common\models\Customers; +use common\models\OrderItems; +use common\models\Orders; +use common\modules\product\models\ProductVariant; use common\widgets\BasketModal; use Yii; @@ -27,78 +31,183 @@ class OrdersController extends Controller return true; } - /** - * Lists all Order models. - * @return mixed - */ - public function actionIndex() - { + public function actionFirst(){ - if (Yii::$app->request->post()) { - $item = $items_id = array(); + $array = Yii::$app->session->get('order'); - $i = 0; - $order = Yii::$app->request->post(); + if(isset($array['order_id']) ) { + $model = Orders::findOne($array['order_id']); + }else { + $model = new Orders(); + } - $orderData['Order'] = $order['OrderForm']; - foreach($order['OrderForm']['one_item'] as $k => $v ){ - $item[$k]['num'] = $v['num']; - $items_id[] = $k; - $i++; - } + if(Yii::$app->request->post() && $model->load(Yii::$app->request->post())){ - $items = Items::find()->where(['id'=>$items_id])->all(); + if($model->save()){ + $array['order_id'] = $model->order_id; - $orderModel = new Order(); - $orderModel->load($orderData); - $orderModel->save(); + Yii::$app->session->set('order', $array ); + return $this->redirect(['orders/second']); + } - foreach($items as $one_item){ - $ItemOrderModel = new ItemOrder(); - $ItemOrderModel->order_id = $orderModel->id; - $ItemOrderModel->num = $item[$one_item->id]['num']; - $ItemOrderModel->item_id = $one_item->id; - $ItemOrderModel->price = $one_item->price * $item[$one_item->id]['num']; - $ItemOrderModel->item_name = $one_item->name; - $ItemOrderModel->save(); + } else { + if (!Yii::$app->user->isGuest) { + $customer = Yii::$app->user->identity; + $model->name = $customer->name; + $model->email = $customer->email; + $model->phone = $customer->phone; } - Yii::$app->session->set('order', [] ); - return $this->redirect(['order/complete']); } - $total_price = 0; - $items_id = []; - $orders = Yii::$app->session->get('order'); + return $this->render('basket-step-01',[ + 'model' => $model + ]); + } - if(!empty($orders)){ - foreach($orders as $k => $v) { - $items_id[] = $k; - } - } + public function actionSecond(){ + $sessionData = \Yii::$app->session->get('order'); - $items = Items::find()->where(['id'=>$items_id])->all(); + $order_id = $sessionData['order_id']; - foreach($items as $item) { - $total_price += $orders[$item['id']]['num'] * $item['price']; + if(!empty($order_id)){ + $order_model = Orders::findOne($order_id); + } else{ + $order_model = new Orders; } + unset($sessionData['order_id']); - $dataProvider = new ArrayDataProvider([ - 'allModels' => $items - ]); + $variant = ProductVariant::find()->where(['product_variant_id'=>array_keys($sessionData)])->indexBy('product_variant_id')->all(); + + + if(Yii::$app->request->post()){ + + foreach ($sessionData as $k => $item) { + $itemModel = OrderItems::find()->where(['order_id'=>$order_id, 'item_id'=> $variant[$k]->product_variant_id])->one(); + if($itemModel instanceof OrderItems){ + $itemModel->order_id = $order_id; + $itemModel->item_id = $variant[$k]->product_variant_id; + $itemModel->item_count = $sessionData[$k]['num']; + $itemModel->price = $variant[$k]->price; + $itemModel->save(); + } else { + $itemModel = new OrderItems(); + $itemModel->order_id = $order_id; + $itemModel->item_id = $variant[$k]->product_variant_id; + $itemModel->item_count = $sessionData[$k]['num']; + $itemModel->price = $variant[$k]->price; + $itemModel->save(); + } - return $this->render('index', [ - 'dataProvider' => $dataProvider, - 'total_price'=> $total_price, - 'model' => new OrderForm() + } + Yii::$app->session->set('order', [] ); + return $this->redirect(['orders/third']); + + } else { + + $price = 0; + + $count = count($sessionData); + + foreach ($sessionData as $k => $item) { + $sessionData[$k]['item'] = $variant[$k]; + $price += $variant[$k]->price * $sessionData[$k]['num']; + } + + } + + return $this->render('basket-step-02',[ + 'items'=>$sessionData, + 'count' => $count, + 'price' => $price, + 'order_id' => $order_id, + 'order_model' => $order_model, ]); + } + public function actionThird(){ + return $this->render('basket-step-03'); + } + + +// /** +// * Lists all Order models. +// * @return mixed +// */ +// public function actionIndex() +// { +// +// if (Yii::$app->request->post()) { +// $item = $items_id = array(); +// +// $i = 0; +// $order = Yii::$app->request->post(); +// +// $orderData['Order'] = $order['OrderForm']; +// +// foreach($order['OrderForm']['one_item'] as $k => $v ){ +// $item[$k]['num'] = $v['num']; +// $items_id[] = $k; +// $i++; +// } +// +// $items = Items::find()->where(['id'=>$items_id])->all(); +// +// +// $orderModel = new Order(); +// $orderModel->load($orderData); +// $orderModel->save(); +// +// +// foreach($items as $one_item){ +// $ItemOrderModel = new ItemOrder(); +// $ItemOrderModel->order_id = $orderModel->id; +// $ItemOrderModel->num = $item[$one_item->id]['num']; +// $ItemOrderModel->item_id = $one_item->id; +// $ItemOrderModel->price = $one_item->price * $item[$one_item->id]['num']; +// $ItemOrderModel->item_name = $one_item->name; +// $ItemOrderModel->save(); +// } +// Yii::$app->session->set('order', [] ); +// return $this->redirect(['order/complete']); +// } +// $total_price = 0; +// +// $items_id = []; +// +// $orders = Yii::$app->session->get('order'); +// +// if(!empty($orders)){ +// foreach($orders as $k => $v) { +// $items_id[] = $k; +// } +// } +// +// +// $items = Items::find()->where(['id'=>$items_id])->all(); +// +// foreach($items as $item) { +// $total_price += $orders[$item['id']]['num'] * $item['price']; +// } +// +// +// $dataProvider = new ArrayDataProvider([ +// 'allModels' => $items +// ]); +// +// return $this->render('index', [ +// 'dataProvider' => $dataProvider, +// 'total_price'=> $total_price, +// 'model' => new OrderForm() +// ]); +// } + public function actionComplete() { diff --git a/frontend/controllers/PuttyController.php b/frontend/controllers/PuttyController.php index 5103c6e..a066df0 100644 --- a/frontend/controllers/PuttyController.php +++ b/frontend/controllers/PuttyController.php @@ -27,13 +27,7 @@ class PuttyController extends Controller return $this->render('manufacturers'); } - public function actionBasketStepFirst(){ - return $this->render('basket-step-01'); - } - public function actionBasketStepSecond(){ - return $this->render('basket-step-02'); - } public function actionContacts(){ diff --git a/frontend/views/catalog/product_item.php b/frontend/views/catalog/product_item.php index fa90e92..9d64e84 100644 --- a/frontend/views/catalog/product_item.php +++ b/frontend/views/catalog/product_item.php @@ -1,5 +1,6 @@
diff --git a/frontend/views/orders/basket-step-01.php b/frontend/views/orders/basket-step-01.php new file mode 100644 index 0000000..bf6d4a7 --- /dev/null +++ b/frontend/views/orders/basket-step-01.php @@ -0,0 +1,98 @@ +title = 'Оформление заказа'; +$this->params['breadcrumbs'][] = $this->title; + +?> + + +

Оформление заказа

+ + + 'basket_order_01_form' + ]); ?> + + +
+ +

Личные данные

+ +
+ field($model, 'name',[ + 'template' => '', + ])->textInput() ?> +
+ +
+ field($model, 'email',[ + 'template' => '', + ])->textInput() ?> +
+ +
+ field($model, 'phone',[ + 'template' => '', + ])->textInput() ?> +
+ +
+ +
+ +
+

Доставка

+ +
+ +

Курьерска доставка по Киеву и области

+
+ +
+ +

В любой регион Украины

+
+ +
+ +

Самовывоз (бесплатно)

+ уточните подробности по телефону 044 ХХХ-ХХ-ХХ +
+
+ +
+ +
+

Оплата

+ +
+ +

Оплата наличными

+
+ +
+ +

Оплата по безналичному расчету. Код ЕГРПОУ

+
+ +
+ +

Приват 24

+
+ +
+ +

Согласовать с менеджером

+
+ +
+ +
+ 'order_01_btn', 'name' => 'signup-button']) ?> +
+ + \ No newline at end of file diff --git a/frontend/views/orders/basket-step-02.php b/frontend/views/orders/basket-step-02.php new file mode 100644 index 0000000..beaf0b4 --- /dev/null +++ b/frontend/views/orders/basket-step-02.php @@ -0,0 +1,83 @@ +title = 'Оформление заказа'; +$this->params['breadcrumbs'][] = $this->title; + +?> +
+ 'basket_order_01_form' + ]); ?> + +

Оформление заказа

+
+

Номер заказа

+
    + + +
  • +
    +
    +
    + product->image)) :?> + + + <?= $item['item']->product->image->alt ? $item['item']->product->image->alt : $item['item']->product->name?> + +
    +
    + name?> + Код: 45885-01016049 +
    +
    +
    + +
    +
    +
    +
    -
    +
    +
    +
    price * $item['num'] ?>грн.
    +
    +
    +
  • + + +
+
+
+

Всего товаров:

+

Сумма: грн.

+
+
+
+ +
+

Детали

+
+ Имяname ?> +
+
+ E-mailemail ?> +
+
+ Телефонphone ?> +
+

Способ оплаты

+
Оплата наличными
+

Доставка

+
Курьерска доставка по Киеву и области
+
+ +
+ 'order_01_btn', 'name' => 'signup-button']) ?> +
+ + +
+ diff --git a/frontend/views/orders/basket-step-03.php b/frontend/views/orders/basket-step-03.php new file mode 100644 index 0000000..0c6deaf --- /dev/null +++ b/frontend/views/orders/basket-step-03.php @@ -0,0 +1,10 @@ +title = 'Оформление заказа'; +$this->params['breadcrumbs'][] = $this->title; + +?> +

Спасибо за ваш заказ!

diff --git a/frontend/views/putty/basket-step-01.php b/frontend/views/putty/basket-step-01.php deleted file mode 100644 index 2f5ea67..0000000 --- a/frontend/views/putty/basket-step-01.php +++ /dev/null @@ -1,93 +0,0 @@ -title = 'Оформление заказа'; -$this->params['breadcrumbs'][] = $this->title; - -?> - - -

Оформление заказа

- -
- -
- -

Личные данные

- -
- -
- -
- -
- -
- -
- - -
- -
- -
-

Доставка

- -
- -

Курьерска доставка по Киеву и области

-
- -
- -

В любой регион Украины

-
- -
- -

Самовывоз (бесплатно)

- уточните подробности по телефону 044 ХХХ-ХХ-ХХ -
-
- -
- -
-

Оплата

- -
- -

Оплата наличными

-
- -
- -

Оплата по безналичному расчету. Код ЕГРПОУ

-
- -
- -

Приват 24

-
- -
- -

Согласовать с менеджером

-
- -
-
- -
- -
\ No newline at end of file diff --git a/frontend/views/putty/basket-step-02.php b/frontend/views/putty/basket-step-02.php deleted file mode 100644 index 5745ee6..0000000 --- a/frontend/views/putty/basket-step-02.php +++ /dev/null @@ -1,80 +0,0 @@ -title = 'Оформление заказа'; -$this->params['breadcrumbs'][] = $this->title; - -?> - -

Оформление заказа

- -
-

Номер заказа 671

- -
-
-

Всего товаров: 3

-

Сумма: 306.15 грн.

-
-
-
- -
-

Детали

-
- ИмяАртем -
-
- E-mailartem@mail.com -
-
- Телефон050 340-34-34 -
-

Способ оплаты

-
Оплата наличными
-

Доставка

-
Курьерска доставка по Киеву и области
-
- -
- -
\ No newline at end of file diff --git a/frontend/web/css/concat_all.css b/frontend/web/css/concat_all.css index eaedebd..291bb33 100644 --- a/frontend/web/css/concat_all.css +++ b/frontend/web/css/concat_all.css @@ -2729,9 +2729,11 @@ span.red { margin-right: 130px; } -.busket_modal_header .busket_modal_02 .order_list .busket_bottom_btn button { +.busket_modal_header .busket_modal_02 .order_list .busket_bottom_btn .button { display: inline-block; padding: 10px 20px; + text-decoration: none; + margin: 0; color: white; background-color: #6aa034; border: none; @@ -2743,14 +2745,14 @@ span.red { box-shadow: 0px 2px 0px #517a27; } -.busket_modal_header .busket_modal_02 .order_list .busket_bottom_btn button:active { +.busket_modal_header .busket_modal_02 .order_list .busket_bottom_btn .button:active { position: relative; -webkit-box-shadow: none; box-shadow: none; top: 2px; } -.busket_modal_header .busket_modal_02 .order_list .busket_bottom_btn button:hover { +.busket_modal_header .busket_modal_02 .order_list .busket_bottom_btn .button:hover { background-color: #5d8d2e; } @@ -2768,7 +2770,174 @@ span.red { .busket_modal_header .busket_modal_02 .order_list .delete_item_btn:hover { color: red; } +/********************BASKET *************************/ + + +.basket_form .order_list { + /*width: auto;*/ + padding: 25px 0px; +} + +.basket_form .order_list ul { + overflow-y: overlay; + overflow-x: hidden; +} + +.basket_form .order_list h3 { + text-transform: uppercase; + font-weight: normal; + font-size: 20px; + padding: 20px 0 15px; +} + +.basket_form .order_list .order_list_li { + display: block; + max-width:440px; + overflow: hidden; +} + + +.basket_form .order_list li:nth-child(even){ + background-color:#f4f4f4; +} +.busket_modal_01 .order_list li:nth-child(even){ + background-color:#f4f4f4; +} + +.basket_form .order_list .order_list_li .little_img { + /*float: none;*/ +} + +.basket_form .order_list .order_list_li .name_and_code { + text-align: left; + /*float: none;*/ +} + +.basket_form .order_list .order_list_li .name_and_code .name { + margin-bottom: 14px; +} +.basket_form .order_list .order_list_li .price { + padding: 0; +} + +.basket_form .order_list .order_list_li .count_block_wrap { + display: inline-block; + vertical-align: top; + text-align: right; + float: left; +} + +.basket_form .order_list .count_block { + display: block; + position: relative; + margin-bottom: 30px; +} + +.basket_form .order_list .count_block .count_number { + display: inline-block; + font-size: 22px; + padding: 6px 13px 3px; + -webkit-border-radius: 3px; + border-radius: 3px; + position: relative; + /*top: -2px;*/ + background-color: #fff; +} + +.basket_form .order_list .count_block .count_buttons { + position: relative; + /*top: 4px;*/ + right: 16px; + display: inline-block; + vertical-align: bottom; +} + +.basket_form .order_list .count_block .count_buttons .button_plus { + background-color: #898b8e; + color: white; + font-weight: bold; + border-bottom: 1px solid #707274; + -webkit-border-top-right-radius: 3px; + border-top-right-radius: 3px; + font-size: 15px; + line-height: 15px; + padding: 0 7px; + cursor: pointer; +} + +.basket_form .order_list .count_block .count_buttons .button_plus:hover { + background-color: #7c7e81; +} + +.basket_form .order_list .count_block .count_buttons .button_minus { + background-color: #898b8e; + color: white; + font-weight: bold; + line-height: 16px; + text-align: center; + border-top: 1px solid #A2A2A2; + -webkit-border-bottom-right-radius: 3px; + border-bottom-right-radius: 3px; + cursor: pointer; +} + +.basket_form .order_list .count_block .count_buttons .button_minus:hover { + background-color: #7c7e81; +} + +.basket_form .order_list .busket_bottom_btn { + margin-top: 20px; + text-align: center; +} + +.basket_form .order_list .busket_bottom_btn a { + display: inline-block; + font-size: 13px; + margin-right: 130px; +} + +.basket_form .order_list .busket_bottom_btn .button { + display: inline-block; + padding: 10px 20px; + text-decoration: none; + margin: 0; + color: white; + background-color: #6aa034; + border: none; + -webkit-border-radius: 2px; + border-radius: 2px; + font-size: 13px; + font-weight: normal; + -webkit-box-shadow: 0px 2px 0px #517a27; + box-shadow: 0px 2px 0px #517a27; +} + +.basket_form .order_list .busket_bottom_btn .button:active { + position: relative; + -webkit-box-shadow: none; + box-shadow: none; + top: 2px; +} + +.basket_form .order_list .busket_bottom_btn .button:hover { + background-color: #5d8d2e; +} + +.basket_form .order_list .delete_item_btn { + display: inline-block; + vertical-align: top; + margin-top: 30px; + padding: 0 10px 0 0; + cursor: pointer; + color: #C6C7C9; + font-size: 20px; + float: left; +} + +.basket_form .order_list .delete_item_btn:hover { + color: red; +} /*=============================================== CATEGORY PAGE ================================================*/ .category_page_main_title { diff --git a/frontend/web/css/style.css b/frontend/web/css/style.css index 8b433fd..3da1752 100644 --- a/frontend/web/css/style.css +++ b/frontend/web/css/style.css @@ -866,7 +866,7 @@ padding-left:27px; left:20px; } .basket_head .bh_cell.text{ - top:8px; + top:20px; left:66px; } .basket_head .basket_head_desc{ diff --git a/frontend/web/js/basket.js b/frontend/web/js/basket.js new file mode 100644 index 0000000..80b0271 --- /dev/null +++ b/frontend/web/js/basket.js @@ -0,0 +1,115 @@ +$(document).ready(function(){ + + var result_block = $('.basket_result'); + + + function changeAjaxPrice(id, num){ + $.post( "/orders/buy-items", {id: id, num:num}, function( data ) { + }); + } + + function countPrise(block){ + var totalBlock = block.parents('.order_list'); + var total_price = 0; + totalBlock.find('.price_val').each(function(){ + total_price += +$(this).html(); + }); + $('.all_price_span').html(total_price); + } + + + $('.item').on('click', '.basket_add_but', function(e){ + var id = $(this).data('id'); + $.post( "/orders/buy-items", {id: id, num:1}, function( data ) { + $('.basket_result').each(function(){ + $(this).html(data) + }); + }); + + }); + + result_block.on('click', '.delete_item_btn', function(){ + var block = $(this).parents('.order_list_li'); + + + var id = block.data('id'); + + $.post( "/orders/delete", {id: id}, function( data ) { + }); + + $('.order_list_li[data-id='+id+']').each(function(){ + var block = $(this); + block.remove(); + }); + + countPrise(block); + + }); + + result_block.on('click', '.button_minus', function(){ + var block = $(this).parents('.order_list_li'); + var price_block = block.find('.price_val'); + var input = block.find('input'); + var number = input.val(); + var id = block.data('id'); + + if(number > 1){ + number--; + input.val(number); + var price = price_block.data('price'); + var new_price = number * +price; + price_block.html(new_price); + changeAjaxPrice(id, number); + synchronizationPriceData(id, number); + } + + countPrise(block); + }); + + + result_block.on('click', '.button_plus', function(){ + var block = $(this).parents('.order_list_li'); + var price_block = block.find('.price_val'); + var input = block.find('input'); + var number = input.val(); + var id = block.data('id'); + + number++; + input.val(number); + var price = price_block.data('price'); + var new_price = number * +price; + price_block.html(new_price); + + changeAjaxPrice(id, number); + synchronizationPriceData(id, number); + countPrise(block); + }); + + result_block.on('change', '.buy_one_item', function(){ + var block = $(this).parents('.order_list_li'); + var num = $(this).val(); + var price_block = block.find('.price_val'); + var price = price_block.data('price'); + var id = block.data('id'); + + var new_price = num * +price; + price_block.html(new_price); + changeAjaxPrice(id, num); + synchronizationPriceData(id, num); + countPrise(block); + }); + + function synchronizationPriceData(id, number){ + $('.order_list_li[data-id='+id+']').each(function(){ + var block = $(this); + block.find('input').val(number); + var price_block = block.find('.price_val'); + var price = price_block.data('price'); + var new_price = number * +price; + price_block.html(new_price); + }); + } + + + +}); \ No newline at end of file diff --git a/frontend/web/js/my_scripts.js b/frontend/web/js/my_scripts.js index a9b4694..b498f8a 100644 --- a/frontend/web/js/my_scripts.js +++ b/frontend/web/js/my_scripts.js @@ -152,8 +152,8 @@ $(document).ready(function(){ modal_busket_open = $('.basket_add_but'), // открыть модалку корзины modal_busket_header_open = $('i.head-down.bh_cell'), // открыть корзину в хедере modal_busket_header = $('.busket_modal_header'), // модальная корзина хедер - modal_busket_header_cont = $('.busket_modal_header .busket_bottom_btn a'), - modal_busket_cont = $('.busket_bottom_btn a'), // ссылка модалки корзины - продолжить покупки + modal_busket_header_cont = $('.busket_modal_header .busket_bottom_btn .close'), + modal_busket_cont = $('.busket_bottom_btn .close'), // ссылка модалки корзины - продолжить покупки forgot_pass_open_btn = $('.forgot_pass_link'), // ссылка на окно - забыли пароль close_btn = $('.modal_close_btn'), // кнопка закрыть регистрацию doc_h = $(document).height(), @@ -471,77 +471,5 @@ $(document).ready(function(){ //=============================================== BUSKET MODAL WINDOW FUNCTIONS - function all_modal_moves(){ - // BUSKET MODAL WINDOW ITEM DELETE - var delete_item_btn = $('.delete_item_btn').click(function(){ - $(this).closest('li').remove(); - }); - } - all_modal_moves(); - - - function countPrise(block){ - var total_price = 0; - block.find('.price').each(function(){ - total_price += +$(this).html(); - }); - $('.total_price').html(total_price); - $("input[name='OrderForm[total_price]']").val(total_price); - } - - - $('.item').on('click', '.basket_add_but', function(e){ - var id = $(this).parents('.item').data('id'); - console.log(id); - $.post( "/orders/buy-items", {id: id}, function( data ) { - $('.basket_result').each(function(){ - $(this).html(data) - }); - }); - - }); - - $('.basket_result').on('click', '.delete_item_btn', function(){ - var id = $(this).parents('.order_list_li').data('id'); - $(this).parents('.order_list_li').remove(); - $.post( "/orders/delete", {id: id}, function( data ) { - }); - countPrise(); - }); - - $('.basket_result').on('click', '.button_minus', function(){ - var input = $(this).parents('.order_list_li ').find('input'); - var number = input.val(); - if(number > 1){ - number--; - input.val(number); - var price = $(this).parents('.goods_data').find('.item_prise_block').find('span').html(); - var new_price = number * price; - $(this).parents('.goods_data').find('.item_prise_total_block').find('span').html(new_price); - } - countPrise(); - }); - - - $('.basket_result').on('click', '.button_plus', function(){ - var input = $(this).parents('.order_list_li ').find('input'); - var number = input.val(); - number++; - input.val(number); - var price = $(this).parents('.goods_data').find('.item_prise_block').find('span').html(); - var new_price = number * price; - $(this).parents('.goods_data').find('.item_prise_total_block').find('span').html(new_price); - countPrise(); - }); - - $('.basket_result').on('change', '.buy_one_item', function(){ - var num = $(this).val(); - var priceBlock = $(this).parents('.order_list_li').find('.price'); - var price = priceBlock.html(); - var new_price = num * price; - priceBlock.html(new_price); - countPrise(); - }); - }); \ No newline at end of file -- libgit2 0.21.4