Closed scandella closed 11 months ago
Can you share the full stack trace for the Attempt to read property "items" on null
error? I'm struggling to get subscriptions to work correctly, as I'm no longer available to use it due to its beta-closed status.
Hi, This is the complete error log for the "Subscription" button.
yii\base\ErrorException: Attempt to read property "items" on null in /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/verbb/snipcart/src/services/Subscriptions.php:26
Stack trace:
#0 /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/craftcms/cms/src/web/ErrorHandler.php(79): yii\base\ErrorHandler->handleError(2, 'Attempt to read...', '/Users/Scandell...', 26)
#1 /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/verbb/snipcart/src/services/Subscriptions.php(26): craft\web\ErrorHandler->handleError(2, 'Attempt to read...', '/Users/Scandell...', 26)
#2 /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/verbb/snipcart/src/controllers/SubscriptionsController.php(19): verbb\snipcart\services\Subscriptions->listSubscriptions(1)
#3 [internal function]: verbb\snipcart\controllers\SubscriptionsController->actionIndex()
#4 /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#5 /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#6 /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('index', Array)
#7 /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/craftcms/cms/src/web/Application.php(305): yii\base\Module->runAction('snipcart/subscr...', Array)
#8 /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('snipcart/subscr...', Array)
#9 /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/craftcms/cms/src/web/Application.php(290): yii\web\Application->handleRequest(Object(craft\web\Request))
#10 /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#11 /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/web/index.php(12): yii\base\Application->run()
#12 {main}
1. in /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/verbb/snipcart/src/services/Subscriptions.phpat line 26
17181920212223242526272829303132333435
public function listSubscriptions(int $page = 1, int $limit = 20, array $params = []): stdClass
{
$params['offset'] = ($page - 1) * $limit;
$params['limit'] = $limit;
$response = Snipcart::$plugin->getApi()->get('subscriptions', $params);
return (object) [
'items' => ModelHelper::safePopulateArrayWithModels($response->items, Subscription::class),
'totalItems' => $response->totalItems,
'offset' => $response->offset,
'limit' => $limit,
];
}
public function getSubscription(string $subscriptionId): ?Subscription
{
if ($subscriptionData = Snipcart::$plugin->getApi()->get("subscriptions/$subscriptionId")) {
2. in /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/craftcms/cms/src/web/ErrorHandler.php at line 79– [yii\base\ErrorHandler::handleError](https://www.yiiframework.com/doc-2.0/yii-base-errorhandler.html#handleError()-detail)(2, 'Attempt to read property "items"...', '/Users/Scandella/Documents/dev_r...', 26)
73747576777879808182838485 {
// Because: https://bugs.php.net/bug.php?id=74980
if (str_contains($message, 'Narrowing occurred during type inference. Please file a bug report')) {
return true;
}
return parent::handleError($code, $message, $file, $line);
}
/**
* @inheritdoc
*/
public function getExceptionName($exception): ?string
3. in /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/verbb/snipcart/src/services/Subscriptions.php at line 26– craft\web\ErrorHandler::handleError(2, 'Attempt to read property "items"...', '/Users/Scandella/Documents/dev_r...', 26)
20212223242526272829303132 $params['offset'] = ($page - 1) * $limit;
$params['limit'] = $limit;
$response = Snipcart::$plugin->getApi()->get('subscriptions', $params);
return (object) [
'items' => ModelHelper::safePopulateArrayWithModels($response->items, Subscription::class),
'totalItems' => $response->totalItems,
'offset' => $response->offset,
'limit' => $limit,
];
}
4. in /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/verbb/snipcart/src/controllers/SubscriptionsController.php at line 19– verbb\snipcart\services\Subscriptions::listSubscriptions(1)
13141516171819202122232425 // Public Methods
// =========================================================================
public function actionIndex(): Response
{
$page = Craft::$app->getRequest()->getPageNum();
$subscriptions = Snipcart::$plugin->getSubscriptions()->listSubscriptions($page);
$totalPages = ceil($subscriptions->totalItems / $subscriptions->limit);
return $this->renderTemplate('snipcart/cp/subscriptions/index', [
'pageNumber' => $page,
'totalPages' => $totalPages,
'totalItems' => $subscriptions->totalItems,
5. verbb\snipcart\controllers\SubscriptionsController::actionIndex()
6. in /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/yiisoft/yii2/base/InlineAction.php at line 57– call_user_func_array([verbb\snipcart\controllers\SubscriptionsController, 'actionIndex'], [])
7. in /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/yiisoft/yii2/base/Controller.php at line 178– [yii\base\InlineAction::runWithParams](https://www.yiiframework.com/doc-2.0/yii-base-inlineaction.html#runWithParams()-detail)(['p' => 'admin/snipcart/subscriptions'])
8. in /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/yiisoft/yii2/base/Module.php at line 552– [yii\base\Controller::runAction](https://www.yiiframework.com/doc-2.0/yii-base-controller.html#runAction()-detail)('index', ['p' => 'admin/snipcart/subscriptions'])
9. in /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/craftcms/cms/src/web/Application.php at line 305– [yii\base\Module::runAction](https://www.yiiframework.com/doc-2.0/yii-base-module.html#runAction()-detail)('snipcart/subscriptions/index', ['p' => 'admin/snipcart/subscriptions'])
299300301302303304305306307308309310311 * @param string $route
* @param array $params
* @return Response|null The result of the action, normalized into a Response object
*/
public function runAction($route, $params = []): ?BaseResponse
{
$result = parent::runAction($route, $params);
if ($result === null || $result instanceof Response) {
return $result;
}
$response = $this->getResponse();
10. in /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/yiisoft/yii2/web/Application.php at line 103– craft\web\Application::runAction('snipcart/subscriptions/index', ['p' => 'admin/snipcart/subscriptions'])
11. in /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/craftcms/cms/src/web/Application.php at line 290– [yii\web\Application::handleRequest](https://www.yiiframework.com/doc-2.0/yii-web-application.html#handleRequest()-detail)(craft\web\Request)
284285286287288289290291292293294295296 if (($response = $this->_processActionRequest($request)) !== null) {
return $response;
}
// If we’re still here, finally let Yii do its thing.
try {
return parent::handleRequest($request);
} catch (Throwable $e) {
$this->_unregisterDebugModule();
throw $e;
}
}
12. in /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/vendor/yiisoft/yii2/base/Application.php at line 384– craft\web\Application::handleRequest(craft\web\Request)
13. in /Users/Scandella/Documents/dev_repo/dev_web/manufacture/dev/web/index.php at line 12– [yii\base\Application::run](https://www.yiiframework.com/doc-2.0/yii-base-application.html#run()-detail)()
6789101112// Load shared bootstrap
require dirname(__DIR__) . '/bootstrap.php';
// Load and run Craft
/** @var craft\web\Application $app */
$app = require CRAFT_VENDOR_PATH . '/craftcms/cms/bootstrap/web.php';
$app->run();
Should be fixed for the next release. To get this early, run composer require verbb/snipcart:"dev-craft-4 as 2.1.1"
.
Fixed in 2.1.2
Describe the bug
Clicking "Abandoned Carts" on the Dashboard page raises the following error:
Cannot assign stdClass to property verbb\snipcart\models\snipcart\AbandonedCart::$user of type ?string
Clicking "Subscriptions" on the Dashboard page raises the following error:
Attempt to read property "items" on null
Steps to reproduce
Craft CMS version
Craft Pro 4.5.13
Plugin version
2.1.1
Multi-site?
No
Additional context
No response