Source of file MemberExtension.php
Size: 0,988 Bytes - Last Modified: 2021-12-23T10:24:42+00:00
/var/www/docs.ssmods.com/process/src/src/extensions/MemberExtension.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 | <?php namespace SilverCommerce\ShoppingCart\Extensions; use SilverStripe\ORM\DataExtension; use SilverCommerce\ShoppingCart\Model\ShoppingCart; /** * Customise Member objects * */ class MemberExtension extends DataExtension { /** * Get the currenty active shopping cart on a member * * @return ShoppingCart */ public function getCart() { return $this ->getOwner() ->Contact() ->Estimates() ->find("ClassName", ShoppingCart::class); } /** * Update the current cart. Also make sure no more than one is * set at any one time. * * @return self */ public function setCart(ShoppingCart $cart) { $curr = $this->getOwner()->getCart(); $contact = $this->getOwner()->Contact(); if (isset($curr) && $curr->ID != $cart->ID) { $curr->delete(); } $cart->CustomerID = $contact->ID; return $this; } } |