taxjar / taxjar-magento2-extension

Magento 2 Sales Tax Extension by TaxJar
http://www.taxjar.com/guides/integrations/magento2/
Open Software License 3.0
22 stars 30 forks source link

Cannot Save Customers on 2.4.6 compatible version #364

Open saderra opened 1 year ago

saderra commented 1 year ago

With your update for 2.4.6, customers cannot be saved. This is the error:

[2023-07-26T17:12:15.188870+00:00] main.CRITICAL: Error: Call to a member function getValue() on null in /var/www/mage/vendor/taxjar/module-taxjar/Observer/Customer/Save.php:55 Stack trace:

0 /var/www/mage/vendor/magento/framework/Event/Invoker/InvokerDefault.php(88): Taxjar\SalesTax\Observer\Customer\Save->execute()

1 /var/www/mage/vendor/magento/framework/Event/Invoker/InvokerDefault.php(74): Magento\Framework\Event\Invoker\InvokerDefault->_callObserverMethod()

2 /var/www/mage/vendor/magento/framework/Event/Manager.php(65): Magento\Framework\Event\Invoker\InvokerDefault->dispatch()

3 /var/www/mage/generated/code/Magento/Framework/Event/Manager/Proxy.php(95): Magento\Framework\Event\Manager->dispatch()

4 /var/www/mage/vendor/magento/module-customer/Controller/Adminhtml/Index/Save.php(360): Magento\Framework\Event\Manager\Proxy->dispatch()

5 /var/www/mage/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Customer\Controller\Adminhtml\Index\Save->execute()

6 /var/www/mage/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Customer\Controller\Adminhtml\Index\Save\Interceptor->___callParent()

7 /var/www/mage/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Customer\Controller\Adminhtml\Index\Save\Interceptor->Magento\Framework\Interception{closure}()

8 /var/www/mage/generated/code/Magento/Customer/Controller/Adminhtml/Index/Save/Interceptor.php(23): Magento\Customer\Controller\Adminhtml\Index\Save\Interceptor->___callPlugins()

9 /var/www/mage/vendor/magento/framework/App/Action/Action.php(111): Magento\Customer\Controller\Adminhtml\Index\Save\Interceptor->execute()

10 /var/www/mage/vendor/magento/module-backend/App/AbstractAction.php(151): Magento\Framework\App\Action\Action->dispatch()

11 /var/www/mage/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Backend\App\AbstractAction->dispatch()

12 /var/www/mage/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Customer\Controller\Adminhtml\Index\Save\Interceptor->___callParent()

13 /var/www/mage/vendor/magento/module-backend/App/Action/Plugin/Authentication.php(145): Magento\Customer\Controller\Adminhtml\Index\Save\Interceptor->Magento\Framework\Interception{closure}()

14 /var/www/mage/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch()

15 /var/www/mage/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Customer\Controller\Adminhtml\Index\Save\Interceptor->Magento\Framework\Interception{closure}()

16 /var/www/mage/generated/code/Magento/Customer/Controller/Adminhtml/Index/Save/Interceptor.php(32): Magento\Customer\Controller\Adminhtml\Index\Save\Interceptor->___callPlugins()

17 /var/www/mage/vendor/magento/framework/App/FrontController.php(245): Magento\Customer\Controller\Adminhtml\Index\Save\Interceptor->dispatch()

18 /var/www/mage/vendor/magento/framework/App/FrontController.php(212): Magento\Framework\App\FrontController->getActionResponse()

19 /var/www/mage/vendor/magento/framework/App/FrontController.php(147): Magento\Framework\App\FrontController->processRequest()

20 /var/www/mage/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch()

21 /var/www/mage/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent()

22 /var/www/mage/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception{closure}()

23 /var/www/mage/generated/code/Magento/Framework/App/FrontController/Interceptor.php(23): Magento\Framework\App\FrontController\Interceptor->___callPlugins()

24 /var/www/mage/vendor/magento/framework/App/Http.php(116): Magento\Framework\App\FrontController\Interceptor->dispatch()

25 /var/www/mage/generated/code/Magento/Framework/App/Http/Interceptor.php(23): Magento\Framework\App\Http->launch()

26 /var/www/mage/vendor/magento/framework/App/Bootstrap.php(264): Magento\Framework\App\Http\Interceptor->launch()

27 /var/www/mage/pub/index.php(30): Magento\Framework\App\Bootstrap->run()

28 {main} {"exception":"[object] (Error(code: 0): Call to a member function getValue() on null at /var/www/mage/vendor/taxjar/module-taxjar/Observer/Customer/Save.php:55)"} []

smolentzov-stripe commented 1 year ago

Hi @saderra, Can you please provide some more information/screenshots about what you are trying to do when you receive this error? I tested locally and was able to successfully create and save a customer in Magento Admin, as well as edit and save an existing customer. Thank you!

ankurkinex commented 1 year ago

@smolentzov-stripe I am also facing the same issue. Just try to edit and resave the customer. It will return this error.

ninjacoder30 commented 1 year ago

Even I am getting this on 2.4.6

Steps to reproduce

  1. Login to admin
  2. go to the customer section
  3. edit the customer and modify any information from the account information tab
  4. click on save and you will get the error
icecactus commented 1 year ago

I also am getting this same error.

bigredkacy commented 1 year ago

I was unable to save customers also. I debugged it and the attribute on line 80 did not exist. tj_last_sync

I created this tool to run to create the attribute and it works and am able to save customers now

`<?php

use Magento\Framework\App\Bootstrap; use Magento\Framework\Exception\LocalizedException; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Eav\Model\Config; use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface; use Magento\Customer\Api\CustomerMetadataInterface;

require '../app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager();

/* @var EavSetupFactory $eavSetupFactory / $eavSetupFactory = $objectManager->get(EavSetupFactory::class);

/* @var ModuleDataSetupInterface $moduleDataSetup / $moduleDataSetup = $objectManager->get(ModuleDataSetupInterface::class);

/* @var Config $eavConfig / $eavConfig = $objectManager->get(Config::class);

$state = $objectManager->get('Magento\Framework\App\State'); $state->setAreaCode('adminhtml');

$setup = $eavSetupFactory->create(['setup' => $moduleDataSetup]);

$attributeCode = 'tj_last_sync'; $setup->addAttribute( CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, $attributeCode, [ 'group' => 'General', 'type' => 'datetime', 'label' => 'TaxJar Last Sync Date', 'input' => 'date', 'required' => false, 'visible' => true, 'user_defined' => true, 'position' => 502, 'system' => 0, 'sort_order' => 52, 'global' => ScopedAttributeInterface::SCOPE_GLOBAL, 'is_used_in_grid' => false, 'is_visible_in_grid' => false, 'is_filterable_in_grid' => false, 'is_html_allowed_on_front' => true, 'visible_on_front' => false, ]

$attribute = $eavConfig->getAttribute(CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, $attributeCode);
$attribute->setData('used_in_forms', ['adminhtml_customer']);
$attribute->getResource()->save($attribute);

}

echo "Attribute creation complete.\n"; `

If you need help let me know

ninjacoder30 commented 1 year ago

The eav attributes related to Tax Jar are nonmandatory or with a null default value, so any customer who doesn't have this value stored against the customer data will throw this error.

Following is the patch you can use to fix this error taxjar_customersave_observer.txt change the extension to patch

icecactus commented 1 year ago

The above patch allowed me to save customers now and makes sense.

icecactus commented 1 year ago

Update: so i can save a customer, but the TaxJar Last Sync Date, TaxJar Exemption Type, TaxJar Exempt Regions do not save.

So I change them, hit save and continue and they back at default.

Update 2: TaxJar Exemption Type is available to edit in the customer grid. I can change it there and it holds, but the other two fields are not available on the grid.

bigredkacy commented 1 year ago

Update: so i can save a customer, but the TaxJar Last Sync Date, TaxJar Exemption Type, TaxJar Exempt Regions do not save.

So I change them, hit save and continue and they back at default.

Update 2: TaxJar Exemption Type is available to edit in the customer grid. I can change it there and it holds, but the other two fields are not available on the grid.

Yes, you need to add the attribute I posted above, I am able to save the data you mentioned and update it on customer save with no errors.

SecRetF commented 7 months ago

As an alternative, I add these fields to the customer_form_attribute table.

INSERT INTO customer_form_attribute (form_code, attribute_id) 
SELECT 'adminhtml_customer' AS form_code, attribute_id FROM eav_attribute WHERE attribute_code IN ('tj_exemption_type', 'tj_regions', 'tj_last_sync');

From what I can see, these fields are defined as extension_attributes, but the name of the field in the form does not use extension_attributes.*, and is obtained using getCustomAttribute. Seems to confuse extension_attributes with custom_attributes.