Skip to content

Commit

Permalink
Add flag to only persist customer session if data has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
supercid committed Aug 11, 2020
1 parent 3e4b0e0 commit 0281077
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Components/Customer.php
Expand Up @@ -86,15 +86,20 @@ public static function persistSession()
->Models()
->getRepository('\Shopware\CustomModels\Nosto\Customer\Customer')
->findOneBy(array('sessionId' => $sessionId));
$shouldPersist = false;
if (empty($customer)) {
$customer = new Customer();
$customer->setSessionId($sessionId);
$shouldPersist = true;
}
if ($nostoId !== $customer->getNostoId()) {
$customer->setNostoId($nostoId);
$shouldPersist = true;
}
if ($shouldPersist) {
Shopware()->Models()->persist($customer);
Shopware()->Models()->flush($customer);
}
Shopware()->Models()->persist($customer);
Shopware()->Models()->flush($customer);
}
}

Expand Down

0 comments on commit 0281077

Please sign in to comment.