سلام
من می خواهم از پکیج bumbummen99/shoppingcart" برای ایجاد سبد خرید استفاده کنم اطلاعات رو با api به کنترولر ارسال می کنم و سشن ایجاد میشه اما وقتی به متد های دیگه کنترولر میرم اطلاعات سشن موجود نیست
@amirfaqihi
خیلی ممنون از راهنمایی تون من همون جوری که گفتین تست کردم اما بازم جواب نداد راه حلی هست که این مشکل رو بشه حلش کرد
شاید پاسخ شما همینجا باشد
@MAJIDKALI
شاید به تنظیمات سشنتون ارتباط پیدا کنه.
نکته جالبی که هست اینه که اگر شما در کنترلر ریدایرکت کنید بعد از اضافه به سبد خرید به روت سبد خرید نمیتونید بهش دسترسی پیدا کنید.
اگر احتمالا این کار رو کردید بدون ریدایرکت تست کنید.
و اینکه حتما به نظر من از کارت یه instance بگیرید من یادم هست بعد از instance مشکل حادی نداشتم.
@MAJIDKALI
کد ارسال اطلاعات کارت از ویو و کد بکند رو لطفا بزارید.
$product = Product::find($request->products[0]['id']);
Cart::instance('shopping')->add($product->id, $product->title, 1, $product->final_price,0);
return response()->json([
'cart' => Cart::content()
]);
<template>
<v-layout row wrap class="pa-10">
<v-container>
<v-alert
v-for="error in errors"
:key="error[0]"
border="left"
colored-border
dense
type="error"
>
<span>{{ error[0] }}</span>
</v-alert>
<v-row wrap>
<!-- card with select item & card with save info -->
<v-col xs="12" sm="12" md="3">
<!-- menu -->
<v-card flat class="border-radius-3">
<v-list>
<v-list-item-group v-model="selectedItem" color="primary">
<v-list-item
v-for="item in menuType"
:key="item.id"
@click="selected(item.id)"
>
<v-list-item-icon>
<v-icon v-text="item.icon"></v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title v-text="item.text"></v-list-item-title>
</v-list-item-content>
<v-list-item-icon> </v-list-item-icon>
</v-list-item>
</v-list-item-group>
</v-list>
</v-card>
<!-- card with save info -->
<v-card flat class="border-radius-3 mt-2">
<v-card-title>مشخصات</v-card-title>
<div class="pa-6">
<v-row class="d-flex justify-space-between py-2">
<span> وضعیت </span>
<span class="grey--text"> پیش نویس </span>
</v-row>
<v-row class="d-flex justify-space-between py-2">
<span> تاریخ </span>
<span class="grey--text">1400-10-02</span>
</v-row>
<v-divider class="ma-4"></v-divider>
<v-row class="d-flex justify-end py-2">
<v-btn color="primary" @click="published()"> انتشار </v-btn>
</v-row>
</div>
</v-card>
<!-- end card save info -->
</v-col>
<!-- card with select item & card with save info -->
<v-col class="text-center" xs="12" md="9" sm="12">
<v-card v-if="selectedId === 1" jucstify-center class="pa-4" flat>
<v-container>
<v-row>
<v-col md="6" sm="12">
<v-text-field
v-model.lazy.trim="formData.name"
filled
dense
label="نام و نام خانوادگی"
required
></v-text-field>
</v-col>
<v-col md="6" sm="12">
<v-text-field
v-model.lazy.trim="formData.mobile"
filled
dense
label="شماره همراه"
required
></v-text-field>
</v-col>
<v-col md="12" sm="12">
<v-text-field
v-model.lazy.trim="formData.email"
filled
dense
label="ایمیل"
required
></v-text-field>
</v-col>
<v-col md="12" sm="12">
<v-text-field
v-model.lazy.trim="formData.password"
filled
dense
label="گذرواژه"
required
:append-icon="showPasswordSwap ? 'mdi-eye' : 'mdi-eye-off'"
:type="showPasswordSwap ? 'text' : 'password'"
@click:append="showPasswordSwap = !showPasswordSwap"
></v-text-field>
</v-col>
</v-row>
</v-container>
</v-card>
<v-card v-if="selectedId === 2" jucstify-center class="pa-4" flat>
<v-container>
<v-row>
<v-col cols="12" md="4" sm="12">
<v-text-field
v-model.lazy.trim="formData.province"
filled
dense
label="استان"
required
></v-text-field>
</v-col>
<v-col cols="12" md="4" sm="12">
<v-text-field
v-model.lazy.trim="formData.city"
filled
dense
label="شهر"
required
></v-text-field>
</v-col>
<v-col cols="12" md="4" sm="12">
<v-text-field
v-model.lazy.trim="formData.phone"
filled
dense
label="تلفن"
required
></v-text-field>
</v-col>
<v-col cols="12" md="12" sm="12">
<v-text-field
v-model.lazy.trim="formData.address"
filled
dense
label="آدرس"
required
></v-text-field>
</v-col>
</v-row>
</v-container>
</v-card>
<v-card v-if="selectedId === 3" jucstify-center class="pa-4" flat>
<v-row class="d-flex justify-space-between pa-3 align-center">
<span class="blue-grey--text text--lighten-3">
افزودن محصولات برای ثبت سفارش محصول
</span>
<div>
<v-btn class="ma-2" small outlined fab @click="dialog = true">
<v-icon>mdi-basket-plus-outline</v-icon>
</v-btn>
</div>
</v-row>
<v-card-text>
<OrderCreateTableShowCart
:cart-item="cartItem"
@update-quantity="quantityUpdated"
/>
</v-card-text>
</v-card>
</v-col>
</v-row>
<v-row justify="center">
<v-dialog v-model="dialog" persistent max-width="550">
<v-card>
<v-toolbar class="elevation-0">
<v-btn icon @click="dialog = false">
<v-icon>mdi-close</v-icon>
</v-btn>
<v-row justify="center">
<v-toolbar-title class="text-center">{{
dialogHeader
}}</v-toolbar-title>
</v-row>
</v-toolbar>
<v-divider class="mx-auto" width="90%"></v-divider>
<v-list>
<v-container grid-list-xs>
<order-create-table
:selected="formData.selected"
@data-selected="dataSelected"
/>
<v-row class="d-flex justify-center mt-5">
<v-col cols="5" md="5">
<v-btn block depressed color="primary" @click="addToCart()"
>تایید
</v-btn>
</v-col>
</v-row>
</v-container>
</v-list>
</v-card>
</v-dialog>
</v-row>
<helper-notify
:text="notificationData.text"
:snackbar="notificationData.snackbar"
@hideNotify="hideNotify"
/>
</v-container>
</v-layout>
</template>
<script>
export default {
data() {
return {
notificationData: {
text: '',
snackbar: false,
},
errors: [],
showPasswordSwap: false,
formData: {
selected: [],
name: '',
mobile: '',
password: '',
email: '',
city: '',
province: '',
address: '',
phone: '',
role: '',
status: 0,
},
roleItems: [
{
text: 'کارمند',
value: 'staff',
},
{
text: 'مدیر',
value: 'admin',
},
],
statusItems: [
{
text: 'فعال',
value: 1,
},
{
text: 'غیر فعال',
value: 0,
},
],
selectedItem: 0,
selectedId: 1,
menuType: [
{ id: 1, text: 'مشخصات', icon: 'mdi-clipboard-list-outline' },
{ id: 2, text: 'آدرس ', icon: 'mdi-image-text' },
{ id: 3, text: 'صورت حساب ', icon: 'mdi-cube-outline' },
],
dialog: false,
dialogHeader: 'افزودن مورد جدید',
cartItem: [],
}
},
methods: {
// this method fix bug unselected menu
selected(selected) {
this.selectedId = selected
},
dataSelected(data) {
this.formData.selected = data.selected
},
published() {
this.$axios
.$post('/api/v1/user/create', this.formData)
.then((response) => {
this.clear()
this.errors = []
this.notificationData.text = response.message
this.notificationData.snackbar = true
console.log('response', response)
})
.catch((errors) => {
this.errors = []
this.errors = errors.response.data.errors
})
},
clear() {
this.formData.name = ''
this.formData.mobile = ''
this.formData.password = ''
this.formData.email = ''
this.formData.city = ''
this.formData.province = ''
this.formData.address = ''
this.formData.phone = ''
this.formData.role = ''
this.formData.status = 0
},
hideNotify() {
this.notificationData.snackbar = false
},
async addToCart() {
await this.$axios
.$post('/api/v1/order/addToCart', {
products: this.formData.selected,
})
.then((response) => {
console.log('cartitem', response)
this.dialog = false
this.cartItem = response.cart
})
.catch((error) => {
console.log('error', error)
})
},
quantityUpdated(items) {
console.log('update', items)
this.cartItem = items
},
},
}
</script>
[2021-10-09 11:54:45] local.INFO: array (
'cart' =>
Illuminate\Support\Collection::__set_state(array(
'items' =>
array (
'027c91341fd5cf4d2579b49c4b6a90da' =>
Gloudemans\Shoppingcart\CartItem::__set_state(array(
'rowId' => '027c91341fd5cf4d2579b49c4b6a90da',
'id' => 1,
'qty' => 1,
'name' => 'product title',
'price' => 550.0,
'weight' => 0.0,
'options' =>
Gloudemans\Shoppingcart\CartItemOptions::__set_state(array(
'items' =>
array (
),
)),
'taxRate' => 21,
'associatedModel' => NULL,
'discountRate' => 0,
)),
),
)),
)
[2021-10-09 11:54:49] local.INFO: array (
'cart update' =>
Illuminate\Support\Collection::__set_state(array(
'items' =>
array (
),
)),
)
```