/**
  * @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.º 2
0
 /**
  * @return String
  */
 public function getSetCurrentLink()
 {
     $url = WishListPage::inst()->Link('set-current-list/' . $this->ID);
     return SecurityToken::inst()->addToUrl($url);
 }