Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

get_class() expects parameter 1 to be object, null given #15

Closed
chadcrowell opened this issue May 24, 2019 · 7 comments
Closed

get_class() expects parameter 1 to be object, null given #15

chadcrowell opened this issue May 24, 2019 · 7 comments

Comments

@chadcrowell
Copy link

On local and dev sites that have devMode on, I am getting this on any template with a product shown on it. Not cart or checkout.

yii\base\ErrorException: get_class() expects parameter 1 to be object, null given in /home/swishvps/test.stemplecreek.com/vendor/nystudio107/craft-instantanalytics/src/services/Commerce.php:477
Stack trace:
#0 /home/swishvps/test.stemplecreek.com/vendor/craftcms/cms/src/web/ErrorHandler.php(81): yii\base\ErrorHandler->handleError(2, 'get_class() exp...', '/home/swishvps/...', 477)
#1 /home/swishvps/test.stemplecreek.com/vendor/nystudio107/craft-instantanalytics/src/services/Commerce.php(477): craft\web\ErrorHandler->handleError(2, 'get_class() exp...', '/home/swishvps/...', 477, Array)
#2 /home/swishvps/test.stemplecreek.com/vendor/nystudio107/craft-instantanalytics/src/services/Commerce.php(440): nystudio107\instantanalytics\services\Commerce->pullDataFromField(Object(craft\commerce\elements\Variant), 'typeOfMeat', true)
#3 /home/swishvps/test.stemplecreek.com/vendor/nystudio107/craft-instantanalytics/src/services/Commerce.php(263): nystudio107\instantanalytics\services\Commerce->getProductDataFromProduct(Object(craft\commerce\elements\Variant))
#4 /home/swishvps/test.stemplecreek.com/vendor/nystudio107/craft-instantanalytics/src/helpers/IAnalytics.php(75): nystudio107\instantanalytics\services\Commerce->addCommerceProductImpression(Object(nystudio107\instantanalytics\helpers\IAnalytics), Object(craft\commerce\elements\Variant), 1, 'shopIndexOther', 1)
#5 /home/swishvps/test.stemplecreek.com/vendor/twig/twig/src/Extension/CoreExtension.php(1687): nystudio107\instantanalytics\helpers\IAnalytics->addCommerceProductImpression(Object(craft\commerce\elements\Variant), 1, 'shopIndexOther', 1)
#6 /home/swishvps/test.stemplecreek.com/vendor/craftcms/cms/src/helpers/Template.php(79): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(nystudio107\instantanalytics\helpers\IAnalytics), 'addCommerceProd...', Array, 'method', false, false)
#7 /home/swishvps/test.stemplecreek.com/storage/runtime/compiled_templates/1d/1d4bc127fd11e6dee056685bf5edc906bbd55874fbda683b6d05e5097064be3d.php(132): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(nystudio107\instantanalytics\helpers\IAnalytics), 'addCommerceProd...', Array, 'method')
#8 /home/swishvps/test.stemplecreek.com/storage/runtime/compiled_templates/21/215a5f933ab66982eae1513b707dd5c6e0eeeed6a9f19f06c20c747b1f2d1b58.php(632): __TwigTemplate_1121a5b26a42994a386f9a048c7cf8dd165d52d9aae6d607fa186c9adecd6dff->macro_productBlock(Object(craft\commerce\elements\Product), Array, Object(craft\commerce\elements\Order), 'shopIndexOther', 1)
#9 /home/swishvps/test.stemplecreek.com/vendor/twig/twig/src/Template.php(184): __TwigTemplate_e8d58a0d1b358ba0d0476b68af7f03d928631aa8788c86fa5e07bff2a02cad30->block_content(Array, Array)
#10 /home/swishvps/test.stemplecreek.com/storage/runtime/compiled_templates/c1/c126810e9f8c2e61f4292e1846259ec9e095490786e5d9aca625a0cf54077556.php(272): Twig\Template->displayBlock('content', Array, Array)
#11 /home/swishvps/test.stemplecreek.com/vendor/twig/twig/src/Template.php(382): __TwigTemplate_bd16f5a2e7c2451b20c4d2aa1e1684192c182430347849dd9e2eb900fb95e1cc->doDisplay(Array, Array)
#12 /home/swishvps/test.stemplecreek.com/vendor/craftcms/cms/src/web/twig/Template.php(52): Twig\Template->displayWithErrorHandling(Array, Array)
#13 /home/swishvps/test.stemplecreek.com/vendor/twig/twig/src/Template.php(359): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#14 /home/swishvps/test.stemplecreek.com/vendor/craftcms/cms/src/web/twig/Template.php(34): Twig\Template->display(Array, Array)
#15 /home/swishvps/test.stemplecreek.com/storage/runtime/compiled_templates/21/215a5f933ab66982eae1513b707dd5c6e0eeeed6a9f19f06c20c747b1f2d1b58.php(55): craft\web\twig\Template->display(Array, Array)
#16 /home/swishvps/test.stemplecreek.com/vendor/twig/twig/src/Template.php(382): __TwigTemplate_e8d58a0d1b358ba0d0476b68af7f03d928631aa8788c86fa5e07bff2a02cad30->doDisplay(Array, Array)
#17 /home/swishvps/test.stemplecreek.com/vendor/craftcms/cms/src/web/twig/Template.php(52): Twig\Template->displayWithErrorHandling(Array, Array)
#18 /home/swishvps/test.stemplecreek.com/vendor/twig/twig/src/Template.php(359): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#19 /home/swishvps/test.stemplecreek.com/vendor/craftcms/cms/src/web/twig/Template.php(34): Twig\Template->display(Array, Array)
#20 /home/swishvps/test.stemplecreek.com/vendor/twig/twig/src/Template.php(367): craft\web\twig\Template->display(Array)
#21 /home/swishvps/test.stemplecreek.com/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#22 /home/swishvps/test.stemplecreek.com/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#23 /home/swishvps/test.stemplecreek.com/vendor/craftcms/cms/src/web/View.php(343): Twig\Environment->render('shop', Array)
#24 /home/swishvps/test.stemplecreek.com/vendor/craftcms/cms/src/web/View.php(393): craft\web\View->renderTemplate('shop', Array)
#25 /home/swishvps/test.stemplecreek.com/vendor/craftcms/cms/src/web/Controller.php(161): craft\web\View->renderPageTemplate('shop', Array)
#26 /home/swishvps/test.stemplecreek.com/vendor/craftcms/cms/src/controllers/TemplatesController.php(78): craft\web\Controller->renderTemplate('shop', Array)
#27 [internal function]: craft\controllers\TemplatesController->actionRender('shop', Array)
#28 /home/swishvps/test.stemplecreek.com/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#29 /home/swishvps/test.stemplecreek.com/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#30 /home/swishvps/test.stemplecreek.com/vendor/craftcms/cms/src/web/Controller.php(109): yii\base\Controller->runAction('render', Array)
#31 /home/swishvps/test.stemplecreek.com/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('render', Array)
#32 /home/swishvps/test.stemplecreek.com/vendor/craftcms/cms/src/web/Application.php(297): yii\base\Module->runAction('templates/rende...', Array)
#33 /home/swishvps/test.stemplecreek.com/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('templates/rende...', Array)
#34 /home/swishvps/test.stemplecreek.com/vendor/craftcms/cms/src/web/Application.php(286): yii\web\Application->handleRequest(Object(craft\web\Request))
#35 /home/swishvps/test.stemplecreek.com/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#36 /home/swishvps/test.stemplecreek.com/public_html/index.php(21): yii\base\Application->run()
#37 {main}
@chadcrowell
Copy link
Author

chadcrowell commented Jun 3, 2019

Now seeing a similar error on the production site, 3 lines away from the error reported above. This is the log result when certain products are added to cart. The webpage shows internal server error and this is the log result:

2019-06-03 11:26:44 [-][1][8331e16132572022ca0f5dc4dc9b8466][error][yii\base\ErrorException:8] yii\base\ErrorException: Trying to get property of non-object in /home/swishvps/stemplecreek.com/vendor/nystudio107/craft-instantanalytics/src/services/Commerce.php:474
Stack trace:
#0 /home/swishvps/stemplecreek.com/vendor/craftcms/cms/src/web/ErrorHandler.php(81): yii\base\ErrorHandler->handleError(8, 'Trying to get p...', '/home/swishvps/...', 474)
#1 /home/swishvps/stemplecreek.com/vendor/nystudio107/craft-instantanalytics/src/services/Commerce.php(474): craft\web\ErrorHandler->handleError(8, 'Trying to get p...', '/home/swishvps/...', 474, Array)
#2 /home/swishvps/stemplecreek.com/vendor/nystudio107/craft-instantanalytics/src/services/Commerce.php(231): nystudio107\instantanalytics\services\Commerce->pullDataFromField(Object(craft\commerce\elements\Product), 'typeOfMeat')
#3 /home/swishvps/stemplecreek.com/vendor/nystudio107/craft-instantanalytics/src/services/Commerce.php(86): nystudio107\instantanalytics\services\Commerce->addProductDataFromLineItem(Object(nystudio107\instantanalytics\helpers\IAnalytics), Object(craft\commerce\models\LineItem))
#4 /home/swishvps/stemplecreek.com/vendor/nystudio107/craft-instantanalytics/src/InstantAnalytics.php(283): nystudio107\instantanalytics\services\Commerce->addToCart(Object(craft\commerce\elements\Order), Object(craft\commerce\models\LineItem))
#5 [internal function]: nystudio107\instantanalytics\InstantAnalytics->nystudio107\instantanalytics\{closure}(Object(craft\commerce\events\LineItemEvent))
#6 /home/swishvps/stemplecreek.com/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Object(Closure), Object(craft\commerce\events\LineItemEvent))
#7 /home/swishvps/stemplecreek.com/vendor/yiisoft/yii2/base/Component.php(636): yii\base\Event::trigger('craft\\commerce\\...', 'afterAddLineIte...', Object(craft\commerce\events\LineItemEvent))
#8 /home/swishvps/stemplecreek.com/vendor/craftcms/commerce/src/elements/Order.php(790): yii\base\Component->trigger('afterAddLineIte...', Object(craft\commerce\events\LineItemEvent))
#9 /home/swishvps/stemplecreek.com/vendor/craftcms/commerce/src/controllers/CartController.php(189): craft\commerce\elements\Order->addLineItem(Object(craft\commerce\models\LineItem))
#10 [internal function]: craft\commerce\controllers\CartController->actionUpdateCart()
#11 /home/swishvps/stemplecreek.com/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#12 /home/swishvps/stemplecreek.com/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#13 /home/swishvps/stemplecreek.com/vendor/craftcms/cms/src/web/Controller.php(109): yii\base\Controller->runAction('update-cart', Array)
#14 /home/swishvps/stemplecreek.com/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('update-cart', Array)
#15 /home/swishvps/stemplecreek.com/vendor/craftcms/cms/src/web/Application.php(297): yii\base\Module->runAction('commerce/cart/u...', Array)
#16 /home/swishvps/stemplecreek.com/vendor/craftcms/cms/src/web/Application.php(565): craft\web\Application->runAction('commerce/cart/u...', Array)
#17 /home/swishvps/stemplecreek.com/vendor/craftcms/cms/src/web/Application.php(281): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#18 /home/swishvps/stemplecreek.com/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#19 /home/swishvps/stemplecreek.com/public_html/index.php(21): yii\base\Application->run()
#20 {main}
2019-06-03 11:26:43 [-][1][8331e16132572022ca0f5dc4dc9b8466][info][application] $_GET = [
    'p' => 'shop/product/custom-order-amount'
]

@chadcrowell
Copy link
Author

Hi Andrew, continuing to try to solve this issue. Again, this is happening only for products in a single product type. Other products with other product types are working. Products in this product type used to work.

This is the code in the commerce service that is having the issue. Here is the code:

        if ($productVariant && $fieldHandle) {
            $srcField = $productVariant[$fieldHandle];

            if ($srcField === null) {
                $srcField = $productVariant->product->$fieldHandle;
            }

            switch (\get_class($srcField)) {

I print_r'd areas of this, and verified that $productVariant and $fieldHandle are set correctly, though $srcField in 473 is null, so it is being set in 474 to $productVariant->product->$fieldHandle, which is showing as an object. So, I don't know why it is failing on 474. I can't figure it out.

@chadcrowell
Copy link
Author

Further testing, it doesn't appear to be product type specific. I created a new product type and moved a faulty product to it, but that didn't change anything. Same error. I guess I'll disable IA for now.

@chadcrowell
Copy link
Author

And here we go again... completely different site, same error on same area of the site. Can I please get some support on this? Its now keeping me from using IA, which I have paid for on 2 different sites, on both sites. Please help.

@chadcrowell
Copy link
Author

chadcrowell commented Jul 12, 2019

So this comes down to the brand field. it really makes no sense that the brand field is something in the IA settings that has to be assigned to products and then chosen for every single product. As I requested in this other open request, the brand setting should be able to be set to a global or a static text that applies to all products. I have over 100 products on 2 different stores, and in both cases, the brand is the same for all 100+ products. Why force me to choose/fill in a brand value on every single product?

So, to get around this error for every product, I hacked IA to provide a string for the brand value that is sent to analytics. The error, I am assuming, was coming from me not choosing/filling in a brand value on every single product. Here is the hack if you want to implement it:

/site/vendor/nystudio107/craft-instantanalytics/src/services/commerce.php
add in 3 locations in the file

FIND:

$productData['brand'] = $this->pullDataFromField(
    $productVariant,
    InstantAnalytics::$settings['productBrandField'],
    true
);

Replace:

// $productData['brand'] = $this->pullDataFromField(
//     $productVariant,
//     InstantAnalytics::$settings['productBrandField'],
//     true
// );
$productData['brand'] = 'My Brand Name';

If I am missing something or there is a non-hacky way to fix this, let me know. It would be great to get some kind of response for this Andrew.

@mcjackson18
Copy link

I'm also getting this same error (using version 1.1.0). I noticed this has been fixed in 1.1.1 but this version isn't available on packagist. Please can you give an ETA on when 1.1.1 will be available to download so we can update the plugin - thanks.

@khalwat
Copy link
Contributor

khalwat commented Sep 27, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants