/** * Adds Spec to product. * * @param Specification $specification * * @return Result */ public function addSpecification(Specification $specification) { $result = new Result(); $validatorResult = $specification->validate(); if ($validatorResult->isOk() == false) { return $result->setError(Result::ERROR_VALIDATION_FAILED, 'Specification invalid'); } $this->getCollection()->update(['_id' => $this->getId()], ['$pull' => ['specifications' => ['property_id' => $specification->getPropertyId()]]]); // TODO: Perform next action only in previous succeeded return $this->getCollection()->update(['_id' => $this->getId()], ['$push' => ['specifications' => $specification->toArray() + ['_id' => $specification->getId()]]]); }