S
S
Sergey Beloventsev2017-03-14 14:48:40
Yii
Sergey Beloventsev, 2017-03-14 14:48:40

How to fix Serialization of 'Closure' is not allowed?

Actually, it's best to post the log

in /var/www/cremea.lc/vendor/omnilight/yii2-shopping-cart/ShoppingCart.php
    public function getSerialized()
    {
        return serialize($this->_positions);//ошибка здесь
    }

 in /var/www/cremea.lc/vendor/omnilight/yii2-shopping-cart/ShoppingCart.php at line 120 – serialize(['a:2:{s:2:"id";i:96;s:6:"volume";s:8:"300 гр";}' => frontend\models\CartPosition]) 
    public function getSerialized()
    {
        return serialize($this->_positions);//ошибка здесь
    }

 in /var/www/cremea.lc/vendor/omnilight/yii2-shopping-cart/ShoppingCart.php at line 79 – yz\shoppingcart\ShoppingCart::getSerialized() 
    public function saveToSession()
    {
        $this->session = Instance::ensure($this->session, Session::className());
        $this->session[$this->cartId] = $this->getSerialized();// ошибка здесь
    }

 in /var/www/cremea.lc/frontend/widgets/cart/Cart.php at line 38 – yz\shoppingcart\ShoppingCart::put(frontend\models\CartPosition, 1) 
            $prise= Price::find()->where("price=".$post['Carts']['price'])->andWhere("product_id=".$post['productId'])->one();
            $prises=$prise->price;
            $volume=$prise->volume;
            $country=$prise->countryid;
            $cartPosition = new CartPosition($position->id, $prises, $country, $volume);
            if ($position) {
                \Yii::$app->cart->put($cartPosition, 1);//ошибка здесь

Where did I make a mistake do not tell me and what is it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Bukharev, 2017-03-14
@Sergalas

The error is that objects that have closures cannot be serialized and, accordingly, unserialized.
i.e. $this->_positions should not contain closures

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question