Version: current

     1 <?php
     2 /**
     3  * Расширение Member - добавление поля Избранное
     4  *
     5  * @author menedem
     6  */
     7 class FavoriteProductMemberExtention extends DataObjectDecorator {
     8
     9     function extraStatics() {
    10         return array(
    11             'db' => array(
    12                 'FavoriteProducts' => 'Text',
    13             ),
    14         );
    15     }
    16
    17     function updateCMSFields(& $fields) {
    18         $fields->removeByName('FavoriteProducts');
    19     }
    20
    21     /**
    22      * Сохранение Кук в профиль пользователя при логине
    23      *
    24      */
    25     function saveFavorites($products) {
    26         $member = Member::currentUser();
    27         if ($member) {
    28             $member->FavoriteProducts = base64_encode($products);
    29             $member->write();
    30         }
    31     }
    32
    33     function memberLoggedIn() {
    34         $member = Member::currentUser();
    35         if ($member) {
    36             $productIDs = array();
    37             if ($member->FavoriteProducts) {
    38                 $productIDs = explode(',', base64_decode($member->FavoriteProducts));
    39             }
    40             $rs = CookieExtention::add_item_to_cookie(FavoritePage::$favorite_cookie_name, $productIDs);
    41             $this->saveFavorites($rs);
    42         }
    43     }
    44
    45     function memberLoggedOut() {
    46         CookieExtention::clear_cookies(FavoritePage::$favorite_cookie_name);
    47     }
    48
    49
    50
    51 }

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -