I make websites for 3 restaurants, they are all located on different subdomains, the goods are added to cookies and displayed in the basket, that is, you can add goods from restaurant No. 1 and it will be visible in the basket of other restaurants, the problem is that there are very many identical goods, 1 product is added to the admin panel and it can be displayed in all restaurants, how can I delimit them in the basket, so that you can see from which site the goods came. Or can it somehow be done on js? On js it turns out to distinguish between different goods -
$(document).ready(function() { var $parent_item_bav = $('.item_cart0').parent('tbody').parent('table').parent('div'), $parent_item_jar = $('.item_cart1').parent('tbody').parent('table').parent('div'), $parent_item_erm = $('.item_cart2').parent('tbody').parent('table').parent('div'); $parent_item_bav.prepend('<h2>Ресторан Бавария</h2>'); $parent_item_jar.prepend('<h2>Ресторан Жар-Птица</h2>'); $parent_item_erm.prepend('<h2>Ресторан Эрмитаж</h2>'); }); And how to do this with products that have the same id?
Recycle Bin Controller Code -
class OrderController extends Controller { /** * Вывод корзины * @return mixed */ public function actionIndex() { $cart = Cart::get(); if ($cart->count == 0) { return $this->render('empty'); } else { return $this->render('index', [ 'content' => $cart ]); } } /** * Добавить товар * @return string * @throws NotFoundHttpException */ public function actionAdd() { if (Yii::$app->request->isAjax) { /* @var $item \app\models\Product */ $item = Product::findOne($_POST['id']); return json_encode( Cart::add([ 'id' => $_POST['id'], 'count' => 1, 'price' => $item->price, 'str1' => $item->str1, 'restaurantNum' => 1, 'restaurant' => 'Заказ с ресторана Жар-птица', 'content' => [ 'name' => $item->name, 'image' => 'http://rest.alazameb.beget.tech/uploads/img/' . $item->image, 'url' => $_POST['url'] ] ]), JSON_UNESCAPED_UNICODE ); } else { throw new NotFoundHttpException('Не найдено.'); } } /** * Удалить товар * @return string * @throws NotFoundHttpException */ public function actionDelete() { if (Yii::$app->request->isAjax) { return json_encode(Cart::delete($_POST['id']), JSON_UNESCAPED_UNICODE); } else { throw new NotFoundHttpException('Не найдено.'); } } /** * Удалить все товары * @return string * @throws NotFoundHttpException */ public function actionRemove() { if (Yii::$app->request->isAjax) { return json_encode(Cart::remove(), JSON_UNESCAPED_UNICODE); } else { throw new NotFoundHttpException('Не найдено.'); } } /** * Изменить товар * @return string * @throws NotFoundHttpException */ public function actionUpdate() { if (Yii::$app->request->isAjax) { return json_encode(Cart::update($_POST['id'], (int)$_POST['count']), JSON_UNESCAPED_UNICODE); } else { throw new NotFoundHttpException('Не найдено.'); } } /** * Изменить товар * @return string * @throws NotFoundHttpException */ public function actionGet() { if (Yii::$app->request->isAjax) { return json_encode(Cart::get(), JSON_UNESCAPED_UNICODE); } else { throw new NotFoundHttpException('Не найдено.'); } } /** * Оформление заказа * * @return string|\yii\web\Response * @throws NotFoundHttpException */ public function actionCheck() { if (Cart::get()->count !== 0) { $form = new CheckForm(); if ($form->load(Yii::$app->request->post()) && $form->validate()) { $form->check(); Yii::$app->session->setFlash('check-order'); return $this->redirect(['site/index']); } else { return $this->render('check', [ 'model' => $form, 'cart' => Cart::get() ]); } } else { throw new NotFoundHttpException('Не найдено.'); } } }site / index']);class OrderController extends Controller { /** * Вывод корзины * @return mixed */ public function actionIndex() { $cart = Cart::get(); if ($cart->count == 0) { return $this->render('empty'); } else { return $this->render('index', [ 'content' => $cart ]); } } /** * Добавить товар * @return string * @throws NotFoundHttpException */ public function actionAdd() { if (Yii::$app->request->isAjax) { /* @var $item \app\models\Product */ $item = Product::findOne($_POST['id']); return json_encode( Cart::add([ 'id' => $_POST['id'], 'count' => 1, 'price' => $item->price, 'str1' => $item->str1, 'restaurantNum' => 1, 'restaurant' => 'Заказ с ресторана Жар-птица', 'content' => [ 'name' => $item->name, 'image' => 'http://rest.alazameb.beget.tech/uploads/img/' . $item->image, 'url' => $_POST['url'] ] ]), JSON_UNESCAPED_UNICODE ); } else { throw new NotFoundHttpException('Не найдено.'); } } /** * Удалить товар * @return string * @throws NotFoundHttpException */ public function actionDelete() { if (Yii::$app->request->isAjax) { return json_encode(Cart::delete($_POST['id']), JSON_UNESCAPED_UNICODE); } else { throw new NotFoundHttpException('Не найдено.'); } } /** * Удалить все товары * @return string * @throws NotFoundHttpException */ public function actionRemove() { if (Yii::$app->request->isAjax) { return json_encode(Cart::remove(), JSON_UNESCAPED_UNICODE); } else { throw new NotFoundHttpException('Не найдено.'); } } /** * Изменить товар * @return string * @throws NotFoundHttpException */ public function actionUpdate() { if (Yii::$app->request->isAjax) { return json_encode(Cart::update($_POST['id'], (int)$_POST['count']), JSON_UNESCAPED_UNICODE); } else { throw new NotFoundHttpException('Не найдено.'); } } /** * Изменить товар * @return string * @throws NotFoundHttpException */ public function actionGet() { if (Yii::$app->request->isAjax) { return json_encode(Cart::get(), JSON_UNESCAPED_UNICODE); } else { throw new NotFoundHttpException('Не найдено.'); } } /** * Оформление заказа * * @return string|\yii\web\Response * @throws NotFoundHttpException */ public function actionCheck() { if (Cart::get()->count !== 0) { $form = new CheckForm(); if ($form->load(Yii::$app->request->post()) && $form->validate()) { $form->check(); Yii::$app->session->setFlash('check-order'); return $this->redirect(['site/index']); } else { return $this->render('check', [ 'model' => $form, 'cart' => Cart::get() ]); } } else { throw new NotFoundHttpException('Не найдено.'); } } }
View basket code -
<div class="wrap_cart"> <section id="contant" class="onlyforcart" style=""> <a id="main-content">X</a> <h1 class="page-header">Ваш заказ</h1> <div class="region region-content"> <section id="block-system-main" class="block block-system clearfix"> <div class="view view-commerce-cart-form view-id-commerce_cart_form view-display-id-default view-dom-id-cbaa018c2c2ab5ac7a6410b5fe5ad95b jquery-once-3-processed"> <div class="view-content"> <div class="commerce-line-item-views-form"><div id="dc-cart-ajax-form-wrapper"><form action="/cart" method="post" id="views-form-commerce-cart-form-default" accept-charset="UTF-8"><div><input type="hidden" name="form_build_id" value="form-BuMnhXlCP8SKma_h5bthYm841vMbViD9PNcx-Xd2Zak"> <input type="hidden" name="form_token" value="Yqj71aD5Bm-szOGiRZujYk7i52mFkrIfHkfefncPZu8"> <input type="hidden" name="form_id" value="views_form_commerce_cart_form_default"> <?php $array = array(); foreach ($content->items as $key => $item){ $array[$item['str1']][$key] = $item; } ?> <a href="" class="clear cart-remove">Очистить корзину</a> <div id="tabs"> <ul class="open_mobile"> <li><a href="#tabs-1">из "Баварии"</a></li> <li><a href="#tabs-2">из "Жар-Птицы"</a></li> <li><a href="#tabs-3">из "Эрмитажа"</a></li> </ul> <?php foreach ($array as $keys):?> <div class="table-responsive"> <table class="views-table cols-6 table table-hover table-striped"> <thead> <tr> <th class="views-field views-field-nothing">Название </th> <th></th> <th class="views-field views-field-commerce-unit-price views-align-left"> Цена </th> <th class="views-field views-field-edit-quantity"> Кол-во </th> <th class="views-field views-field-commerce-total views-align-left"> Итого </th> <th class="views-field views-field-edit-delete"> Удалить </th> </tr> </thead> <?php foreach ($keys as $item): ?> <tbody> <tr class="odd views-row-first item_cart<?= $item['restaurantNum'] ?>"> <td class="views-field views-field-nothing"> <img src="<?= $item['content']['image'] ?>" width="120" height="80"> <br> </td><td><?= $item['content']['name'] ?></td> <td class="views-field views-field-commerce-unit-price views-align-left price"> <?= $item['price']?> руб. </td> <td class="views-field views-field-edit-quantity"> <?= $item['count'] ?> </td> <td class="views-field views-field-commerce-total views-align-left price"> <span class=""><?= $item['price'] * $item['count'] /*- ceil((($item['price'] * $item['count']) * 7) / 100)*/ ?></span> </td> <td class="text-center"><span class="glyphicon glyphicon-trash trash cart-delete" data-cart="<?= $item['id'] ?>" title="Удалить"></span></td> </tr> </tbody> <?php endforeach; ?> </table> </div> <?php endforeach; ?> </div> <div class="line-item-summary"> <div class="line-item-quantity"> <span class="line-item-quantity-raw"><?= $item['count'] ?></span> <span class="line-item-quantity-label">товаров</span> </div> <div class="line-item-total"> <p>Сумма:<span class="notsale"><?= $content->notsale ?></span> руб. </p> <span class="line-item-total-label">При заказе с сайта скидка 7%, Итого:</span> <span class="line-item-total-raw cart-price-order"><?= $content->price /*- ceil(($content->price * 7) / 100)*/ ?> руб.</span> </div> <ul class="links list-inline"><li class="line-item-summary-checkout first last"><a href="/checkout" rel="nofollow">Оформление заказа</a></li> </ul></div> <div class="form-actions commerce-line-item-actions form-wrapper form-group" id="edit-actions"> <?= Html::a('Оформить заказ', ['order/check'], ['class' => 'btn btn-default form-submit']) ?> </div></div></form></div></div><div class="attachment"><div class="views-summary"><a href="#" id="dc-cart-ajax-views-form-commerce-cart-form-default"> </a></div></div> </div> </div> </section> </div> </section> </div>