Skip to content

Commit 0281077

Browse files
committed
Add flag to only persist customer session if data has changed
1 parent 3e4b0e0 commit 0281077

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Components/Customer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,20 @@ public static function persistSession()
8686
->Models()
8787
->getRepository('\Shopware\CustomModels\Nosto\Customer\Customer')
8888
->findOneBy(array('sessionId' => $sessionId));
89+
$shouldPersist = false;
8990
if (empty($customer)) {
9091
$customer = new Customer();
9192
$customer->setSessionId($sessionId);
93+
$shouldPersist = true;
9294
}
9395
if ($nostoId !== $customer->getNostoId()) {
9496
$customer->setNostoId($nostoId);
97+
$shouldPersist = true;
98+
}
99+
if ($shouldPersist) {
100+
Shopware()->Models()->persist($customer);
101+
Shopware()->Models()->flush($customer);
95102
}
96-
Shopware()->Models()->persist($customer);
97-
Shopware()->Models()->flush($customer);
98103
}
99104
}
100105

0 commit comments

Comments
 (0)