/**
  * Create the page if needed
  */
 public function requireDefaultRecords()
 {
     if (!self::inst() && Config::inst()->get('WishListPage', 'auto_create_page')) {
         $rec = new WishListPage();
         $rec->Title = 'Wish List';
         $rec->ShowInSearch = false;
         $rec->ShowInMenu = false;
         $rec->CanViewType = 'LoggedInUsers';
         $rec->write();
         $rec->publish('Stage', 'Live');
         $rec->flushCache();
     }
 }
 /**
  * @param array $data
  */
 public function addtowishlist(array $data)
 {
     if (!class_exists('WishList')) {
         user_error('Wish List module not installed.');
     }
     $groupedProduct = $this->getController()->data();
     if (empty($data) || empty($data['Product']) || !is_array($data['Product'])) {
         $this->sessionMessage(_t('GroupedCartForm.EMPTY', 'Please select at least one product.'), 'bad');
         $this->extend('updateErrorResponse', $this->request, $response, $groupedProduct, $data, $this);
         return $response ? $response : $this->controller->redirectBack();
     }
     $list = WishList::current();
     foreach ($data['Product'] as $id => $prodReq) {
         if (!empty($prodReq['Quantity']) && $prodReq['Quantity'] > 0) {
             $prod = Product::get()->byID($id);
             if ($prod && $prod->exists()) {
                 $buyable = $prod;
                 if (isset($prodReq['Attributes'])) {
                     $buyable = $prod->getVariationByAttributes($prodReq['Attributes']);
                     if (!$buyable || !$buyable->exists()) {
                         $this->sessionMessage("{$prod->InternalItemID} is not available with the selected options.", "bad");
                         $this->extend('updateErrorResponse', $this->request, $response, $groupedProduct, $data, $this);
                         return $response ? $response : $this->controller->redirectBack();
                     }
                 }
                 $list->addBuyable($buyable);
             }
         }
     }
     $this->extend('updateGroupWishListResponse', $this->request, $response, $groupedProduct, $data, $this);
     return $response ? $response : $this->controller->redirect(WishListPage::inst()->Link());
 }
Exemplo n.º 3
0
 /**
  * @return String
  */
 public function getSetCurrentLink()
 {
     $url = WishListPage::inst()->Link('set-current-list/' . $this->ID);
     return SecurityToken::inst()->addToUrl($url);
 }
 /**
  * Add default records to database.
  * Make sure you call parent::requireDefaultRecords().
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $update = array();
     $page = DataObject::get_one("WishListPage");
     if (!$page) {
         $page = new WishListPage();
         $page->Title = "Wish List";
         $page->MetaTitle = "Wish List";
         $page->URLSegment = "wish-list";
         $page->MenuTitle = "wish list";
     }
     if ($page) {
         if (!$page->AddedToListText) {
             $page->AddedToListText = "added to wish list";
             $update[] = "updated AddedToListText";
         }
         if (!$page->AddedToListTextError) {
             $page->AddedToListTextError = "could not add to wish list";
             $update[] = "updated AddedToListTextError";
         }
         if (!$page->RemovedFromListConfirmation) {
             $page->RemovedFromListConfirmation = "are you sure you want to remove it from your wish list?";
             $update[] = "updated RemovedFromListConfirmation";
         }
         if (!$page->RetrieveListConfirmation) {
             $page->RetrieveListConfirmation = "Are you sure you would like to retrieve your saved list?  It will replace your current list.  Do you want to go ahead?";
             $update[] = "updated RetrieveListConfirmation";
         }
         if (!$page->ClearListConfirmation) {
             $page->ClearListConfirmation = "Are you sure you would like to clear your saved list? ";
             $update[] = "updated ClearListConfirmation";
         }
         if (!$page->RemovedFromListText) {
             $page->RemovedFromListText = "removed from wish list";
             $update[] = "updated RemovedFromListText";
         }
         if (!$page->RemovedFromListTextError) {
             $page->RemovedFromListTextError = "could not be removed from wish list";
             $update[] = "updated RemovedFromListTextError";
         }
         if (!$page->ClearWishList) {
             $page->ClearWishList = "cleared wish list";
             $update[] = "updated ClearWishList";
         }
         if (!$page->SavedWishListText) {
             $page->SavedWishListText = "saved wish list";
             $update[] = "updated SavedWishListText";
         }
         if (!$page->SavedWishListTextError) {
             $page->SavedWishListTextError = "could not save wish list";
             $update[] = "updated SavedWishListTextError";
         }
         if (!$page->RetrievedWishListText) {
             $page->RetrievedWishListText = "retrieved wish list";
             $update[] = "updated RetrievedWishListText";
         }
         if (!$page->RetrievedWishListTextError) {
             $page->RetrievedWishListTextError = "could not retrieve wish list";
             $update[] = "updated RetrievedWishListTextError";
         }
         if (count($update)) {
             $page->writeToStage('Stage');
             $page->publish('Stage', 'Live');
             DB::alteration_message($page->ClassName . " created/updated: <ul><li>" . implode("</li><li>", $update) . "</li></ul>", 'created');
         }
     }
 }
 /**
  * @return string
  */
 public function WishListRemoveLink()
 {
     return WishListPage::remove_item_link($this->getOwner()->ID, $this->getOwner()->ClassName);
 }