klaviyo / magento2-klaviyo

37 stars 51 forks source link

Magento2.1.6 Klaviyo - Asymmetric transaction rollback. #19

Closed mageprashant closed 3 years ago

mageprashant commented 5 years ago

I have used your extension version 1.0.5 in Magento2.1.6. Go to Admin > Stores > Configuration > KLAVIYO > General > Settings

after Save Config

go to frontend and I try to Newsletter Subscription and getting an error > https://www.screencast.com/t/T24Ncq3T

Thank you

alisovtsev commented 5 years ago

In this case subscription creates without customer creation, but UserProfileNewsletterSubscribeObserver of Klaviyo\Reclaim request customer by customerId, which generate exception of NoSuchEntity and then happens Asymmetric transaction error. So you may fix like this: instead of ` if ($subscriber->isStatusChanged()) { $customer = $this->customer_repository_interface->getById($subscriber->getCustomerId());

      if ($subscriber->isSubscribed()) {
        $this->data_helper->subscribeEmailToKlaviyoList(
            $customer->getEmail(),
            $customer->getFirstname(),
            $customer->getLastname()
        );
      } else {
        $this->data_helper->unsubscribeEmailFromKlaviyoList($customer->getEmail());
      }
    }

`

replace to : ` if ($subscriber->isStatusChanged()) { if ($subscriber->getCustomerId()) { $object = $this->customer_repository_interface->getById($subscriber->getCustomerId()); } else { $object = $subscriber; }

        if ($subscriber->isSubscribed()) {
            $this->data_helper->subscribeEmailToKlaviyoList(
                $object->getEmail(),
                $object->getFirstname(),
                $object->getLastname()
            );
        } else {
            $this->data_helper->unsubscribeEmailFromKlaviyoList($object->getEmail());
        }
    }

`