PAYONE-GmbH / shopware-5

PAYONE Payment Plugin for shopware 5
MIT License
10 stars 24 forks source link

Call to undefined method Shopware\\Models\\Customer\\Customer::getBilling() #250

Closed Besselink closed 5 years ago

Besselink commented 5 years ago

[Sun Dec 02 23:27:21.187947 2018] [proxy_fcgi:error] [pid 14143:tid 140033227749120] [client 91.32.82.190:57535] AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Error: Call to undefined method Shopware\Models\Customer\Customer::getBilling() in /var/www/vhosts/softwarehexe.de/httpdocs/engine/Shopware/Plugins/Community/Frontend/MoptPaymentPayone/Subscribers/AddressCheck.php:881\nStack trace:\n#0 /var/www/vhosts/softwarehexe.de/httpdocs/engine/Library/Enlight/Event/Handler/Default.php(91): Shopware\Plugins\MoptPaymentPayone\Subscribers\AddressCheck->onUpdateAddress(Object(Enlight_Hook_HookArgs))\n#1 /var/www/vhosts/softwarehexe.de/httpdocs/engine/Library/Enlight/Event/EventManager.php(304): Enlight_Event_Handler_Default->execute(Object(Enlight_Hook_HookArgs))\n#2 /var/www/vhosts/softwarehexe.de/httpdocs/engine/Library/Enlight/Hook/HookExecutionContext.php(115): Enlight_Event_EventManager->filter('Shopware_Contro...', NULL, Object(Enlight_Hook_HookArgs))\n#3 /var/www/vhosts/softwarehexe.de/httpdocs/engine/Library/Enlight/Hook/HookManager.php(179): Enlight_Hook_HookExecutionContext->execute()\n#4 /var/www/vhosts/softwarehexe.de/httpdo...\n', referer: https://www.softwarehexe.de/checkout/confirm

is now fixed by myself in /engine/Shopware/Plugins/Community/Frontend/MoptPaymentPayone/Subscribers:

/**
 * invalidate all check results on address change
 *
 * @param \Enlight_Hook_HookArgs $arguments
 */
public function onUpdateAddress(\Enlight_Hook_HookArgs $arguments)
{
    try {
        /** @var \Mopt_PayoneMain $moptPayoneMain */
        $userId = Shopware()->Session()->sUserId;
        $moptPayoneMain = $this->container->get('MoptPayoneMain');
        $user = Shopware()->Models()->getRepository('Shopware\Models\Customer\Customer')->find($userId);
        $userAttribute = $moptPayoneMain->getHelper()->getOrCreateUserAttribute($user);
        $userAttribute->setMoptPayoneConsumerscoreDate(0);
        Shopware()->Models()->persist($userAttribute);
        Shopware()->Models()->flush();
        // <OLD>
        // $billing = $user->getBilling();
        // </OLD>
        // <NEW>
        if (\Shopware::VERSION === '___VERSION___' || version_compare(\Shopware::VERSION, '5.2.0', '>=')) {
            $billing = $user->getDefaultBillingAddress();
        } else {
            $billing = $user->getBilling();
        }
        // </NEW>
        $billingAttribute = $moptPayoneMain->getHelper()->getOrCreateBillingAttribute($billing);
        $billingAttribute->setMoptPayoneAddresscheckDate(0);
        Shopware()->Models()->persist($billingAttribute);
        Shopware()->Models()->flush();
        // <OLD>
        // $shipping = $user->getShipping();
        // </OLD>
        // <NEW>
        if (\Shopware::VERSION === '___VERSION___' || version_compare(\Shopware::VERSION, '5.2.0', '>=')) {
            $shipping = $user->getDefaultShippingAddress();
        } else {
            $shipping = $user->getShipping();
        }
        // </NEW>
        $shippingAttribute = $moptPayoneMain->getHelper()->getOrCreateShippingAttribute($shipping);
        $shippingAttribute->setMoptPayoneAddresscheckDate(0);
        Shopware()->Models()->persist($shippingAttribute);
        Shopware()->Models()->flush();
    } catch (\Exception $exception) {
        unset($exception); // Ignore errors
    }
}
Besselink commented 5 years ago

We use Shopware 5.5.1 and Payone 3.11.0

fjbender commented 5 years ago

This was fixed with 6215bde09614634b9b4c945ed30effdbb956b35d