Basket is empty after redirect

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
krzysiekp
Posts: 97
Joined: 05 Nov 2021, 16:19

Basket is empty after redirect

Post by krzysiekp » 28 Jan 2025, 19:50

I create basket controller object

Code: Select all

 $basketCntl = \Aimeos\Controller\Frontend::create($context, 'basket');
and add product to basket

Code: Select all

$basketCntl->addProduct
Right after adding before redirecting when I execute the method

Code: Select all

dd($basketCntl->get())
I receive

Code: Select all

Aimeos\MShop\Order\Item\CustomOrderItem {#1220 ▼ // app\Http\Controllers\AimeosBasketController.php:68
  #available: true
  #modified: true
  #bprefix: "order."
  #type: null
  #bdata: array:3 [▶]
  #customer: null
  #locale: 
Aimeos\MShop\Locale\Item
\
Standard {#920 ▶}
  #price: 
Aimeos\MShop\Price\Item
\
Standard {#1012 ▶}
  #recalc: true
  #coupons: []
  #products: array:1 [▼
    0 => 
Aimeos\MShop\Order\Item\Product
\
Standard {#1381 ▼
      #available: true
      #modified: true
      #bprefix: "order.product."
      #type: null
      #bdata: array:14 [▼
        ".price" => 
Aimeos\MShop\Price\Item
\
Standard {#1416 ▶}
        "order.product.siteid" => "1."
        "order.product.prodcode" => "2230047623841"
        "order.product.productid" => "6"
        "order.product.type" => "e-card"
        "order.product.scale" => 1.0
        "order.product.target" => ""
        "order.product.name" => "Wirtualna Karta Podarunkowa CCC x HalfPrice"
        "order.product.mediaurl" => "cards/151.jpg?v=20250126182007"
        "order.product.quantity" => 1.0
        "order.product.stocktype" => "default"
        ".attributes" => 
Aimeos
\
Map {#1074 ▶}
        "order.product.vendor" => "pl"
        "order.product.timeframe" => ""
      ]
      -attributesMap: array:1 [▼
        "custom" => array:2 [▼
          "price" => array:1 [▶]
          "text" => array:1 [▶]
        ]
      ]
    }
  ]
  #services: []
  #statuses: []
  #addresses: []
  #listeners: array:13 [▶]
}
But after redirect to another page products are empty

Code: Select all

Aimeos\MShop\Order\Item\CustomOrderItem {#896 ▼ // app\Http\Controllers\AimeosCheckoutController.php:38
  #available: true
  #modified: false
  #bprefix: "order."
  #type: null
  #bdata: array:3 [▶]
  #customer: null
  #locale: 
Aimeos\MShop\Locale\Item
\
Standard {#945 ▼
      #available: true
      #modified: false
      #bprefix: "locale."
      #type: null
      #bdata: array:10 [▶]
      -siteItem: 
Aimeos\MShop\Locale\Item\Site
\
Standard {#920 ▼
        #available: true
        #modified: false
        #bprefix: "locale.site."
        #type: null
        #bdata: array:18 [▶]
      }
      -sites: array:1 [▶]
    }
  #price: 
Aimeos\MShop\Price\Item
\
Standard {#892 ▶}
  #recalc: false
  #coupons: []
  #products: []
  #services: []
  #statuses: []
  #addresses: []
  #listeners: array:12 [▼
    "addAddress.after" => array:2 [▶]
    "deleteAddress.after" => array:2 [▶]
    "setAddresses.after" => array:2 [▶]
    "addCoupon.after" => array:2 [▶]
    "deleteCoupon.after" => array:2 [▶]
    "addProduct.after" => array:2 [▶]
    "deleteProduct.after" => array:2 [▶]
    "setProducts.after" => array:2 [▶]
    "addService.after" => array:1 [▶]
    "deleteService.after" => array:1 [▶]
    "setServices.after" => array:1 [▶]
    "setOrder.before" => array:1 [▶]
  ]
}
I had earlier in .env

SESSION_DRIVER=database
and change to
SESSION_DRIVER=file

Problem still ocurring.

I think maybe problem in my extends => Aimeos\MShop\Order\Item\CustomOrderItem (in attachment is Manager and Item code in zip file)

My redirect code is

Code: Select all

 return redirect()->route('aimeos_shop_checkout', ['site' => $site, 'c_step' => 'onepage']);
"aimeos_shop_checkout" is custom controller in Laravel

I done test and before redirect was added

Code: Select all

session()->put('test', '123')
And in new page

Code: Select all

dd(session()->all());
And it showed me this value
It follows that the session itself in Laravel works correctly, only something with the Aimeos basket session

My Aimeos version
"aimeos/aimeos-laravel": "^2024.10",

Laravel framework
"laravel/framework": "^10.0",
Attachments
Order.zip
(1.59 KiB) Downloaded 2817 times

User avatar
aimeos
Administrator
Posts: 8616
Joined: 01 Jan 1970, 00:00

Re: Basket is empty after redirect

Post by aimeos » 29 Jan 2025, 10:34

You need to call save() to persist the basket:
https://github.com/aimeos/ai-controller ... hp#L45-L50
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

krzysiekp
Posts: 97
Joined: 05 Nov 2021, 16:19

Re: Basket is empty after redirect

Post by krzysiekp » 29 Jan 2025, 17:04

The basket is still empty.

Code before redirect:

Code: Select all

$context = app('aimeos.context').get(true);
$basketCntl = \Aimeos\Controller\Frontend::create($context, 'basket');
$basketCntl->addProduct(
                            $productCntl->get($values['prodid']),
                            (float) ($values['quantity'] ?? 0),
                            array_filter((array) ($values['attrvarid'] ?? [])),
                            $this->getAttributeMap((array) ($values['attrconfid'] ?? [])),
                            array_filter((array) ($values['attrcustid'] ?? [])),
                            (string) ($values['stocktype'] ?? 'default'),
                            //(string) ($values['supplier'] ?? ''),
                            $values['siteid'] ?? null
                        );
 return redirect()->route('aimeos_shop_checkout', ['site' => $site, 'c_step' => 'onepage']);                        
Before redirect:
https://prnt.sc/cTzco3ibCS2R

After redirect:
https://prnt.sc/ZJnEzfl6vV_y

Code after redirect on another page:

Code: Select all

$context = app('aimeos.context').get(true);
$basketCntl = \Aimeos\Controller\Frontend::create($context, 'basket');
dd($basketCntl->get());
In addProduct method is already exists "save" method
https://github.com/aimeos/ai-controller ... L333-#L363

I also tried to call "save" a second time but it didn't help

krzysiekp
Posts: 97
Joined: 05 Nov 2021, 16:19

Re: Basket is empty after redirect

Post by krzysiekp » 31 Jan 2025, 19:47

At this point I even disconnected my extensions and the cart is still empty.
I noticed that in the save() method, before saving to the session, the products are
https://prnt.sc/cdyi9lRn4zWk
However, in the setSession method in trait Session products is already empty
https://prnt.sc/G-Hf6Ymb87Ee

I use WampServer, PHP 8.2

My composer.json

Code: Select all

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^8.2",
        "aimeos-extensions/new-ext": "dev-main",
        "aimeos/aimeos-laravel": "^2024.10",
        "azuyalabs/yasumi": "^2.7",
        "barryvdh/laravel-snappy": "^1.0",
        "jschaedl/iban-validation": "^2.5",
        "laravel/framework": "^10.0",
        "laravel/jetstream": "^4.3",
        "phpoffice/phpspreadsheet": "^3.9",
        "picqer/php-barcode-generator": "^2.4",
        "rootinc/laravel-azure-middleware": "^0.9.10",
        "spatie/laravel-backup": "^8.8",
        "spatie/laravel-permission": "^6.10",
        "symfony/http-client": "^6.4",
        "symfony/mailgun-mailer": "^6.4"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9.1",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.2",
        "nunomaduro/collision": "^7.0",
        "phpunit/phpunit": "^10.0",
        "spatie/laravel-ignition": "^2.0"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        },
        "files": [
            "app/helpers.php"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.aimeos.org/aimeoscom"
        },
        {
            "type": "path",
            "url": "./packages/*",
            "options": {
                "symlink": false
            }
        }
    ],
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

krzysiekp
Posts: 97
Joined: 05 Nov 2021, 16:19

Re: Basket is empty after redirect

Post by krzysiekp » 01 Feb 2025, 17:36

I resolved my problem :). I used app('aimeos.context').get() in constructor of controller and I move it to action controller.

Post Reply