/** * Creates new relationship * * @role update */ public function add() { $productID = $this->request->get('relatedownerID'); $ownerID = $this->request->get('id'); $owner = Product::getInstanceByID($ownerID, Product::LOAD_DATA); $product = Product::getInstanceByID($productID, Product::LOAD_DATA, array('ProductImage')); if ($product->isBundle()) { return new JSONResponse(array('error' => $this->translate('_err_bundle_with_bundle'))); } if (!ProductBundle::hasRelationship($owner, $product)) { $instance = ProductBundle::getNewInstance($owner, $product); if (!$instance) { return new JSONResponse(array('error' => $this->translate('_err_add_to_itself'))); } $instance->save(); $response = new ActionResponse(); $response->set('product', $product->toArray()); $response->set('added', true); $response->set('total', $this->getTotal($owner)); return $response; } else { return new JSONResponse(array('error' => $this->translate('_err_multiple'))); } }