I am dealing with a existing code which stores the order item details in a cookie.
in Controller:
public function actionAdd2cart($id, $url, $instructor_id, $location_id, $start_time, $date1) {
$ep = Yii::$app->getTable->settings('general','enable_payment');
$order_item = \Yii::$app->getRequest()->getCookies()->getValue('order_item');
{
$model = ClassDuration::find()->where(['id' => $id])->One();
$model1 = Instructor::find()->where(['user_id' => $instructor_id])->One();
$time = strtotime($start_time);
$duration = $model1['instructor_duration'];
$endTime = date("h:i A", strtotime('+' . $duration . ' minutes', $time));
$fees = Instructor::find()->where(['user_id' => $model['instructor_id']])->one();
$order_item[] = [
'duration' => date('h:i A', strtotime($start_time)) . '-' . $endTime,
'starttime' => $start_time,
'endtime' => $endTime,
'id' => $model->id,
//'price' => $fees['instructor_fees'], this is disabled as payment info is not needed and to increase the cookie size
'q' => 1,
'date' => $model->start_date,
'instructor_id' => $instructor_id,
'location_id' => $location_id,
'date1' => $date1,
'datetime' => $date1 . "-" . $start_time . "i" . $instructor_id,
]; //product details array
}
/********** cookies for product details **********/
$cookie = new \yii\web\Cookie([
'name' => 'order_item',
'value' => $order_item,
'expire' => time() + (60 * 60 * 24),
]);
Yii::$app->getResponse()->getCookies()->add($cookie); // add product deatils to cookies
if ($url == 'view') {
return $this->redirect(Yii::$app->request->referrer);
} else {
// echo 1;
}
}
Now the problem I am facing with this code is like while adding the item to cart, it allow for 6-8 items being added in the cart depending on diffrent browser and due to cookie size limitation, I am not able to add more items to cart beyond that.
I am looking for a way like if the cookie value can be compressed before setting the cookies and uncompressed while accessing it.
or some other suitable solution.