function ApplicableProductQuestions() { $productQuestions = $this->owner->ProductQuestions(); $productQuestionsArray = array(0 => 0); if ($productQuestions && $productQuestions->count()) { $productQuestionsArray = $productQuestions->map("ID", "ID")->toArray(); } $productQuestionsForAll = ProductQuestion::get()->filter(array("ApplyToAllProducts" => 1)); if ($productQuestionsForAll && $productQuestionsForAll->count()) { $productQuestionsForAllArray = $productQuestionsForAll->map("ID", "ID")->toArray(); $productQuestionsArray += $productQuestionsForAllArray; } return ProductQuestion::get()->filter(array("ID" => $productQuestionsArray)); }
protected function createObjects() { $this->objects = new ArrayList(); if ($this->options && is_array($this->options) && count($this->options)) { foreach ($this->options as $option) { $imageOptions = ProductQuestion::create_file_array_from_option($option); $image = Image::get()->filter(array("ParentID" => $this->folderID, "Name" => $imageOptions))->First(); if ($image) { $image->Key = $option; $image->Value = $option; $this->objects->push($image); } } } }
/** * returns the applicable Product Questions * @return DataList */ function ProductQuestions() { if (!isset(self::$_product_questions_cache[$this->owner->ID])) { $product = $this->owner->Product(); $productQuestions = $product->ApplicableProductQuestions(); $productQuestionsArray = array(0 => 0); if ($productQuestions && $productQuestions->count()) { $productQuestionsArray = $productQuestions->map("ID", "ID")->toArray(); } $ignoreProductQuestions = $this->owner->IgnoreProductQuestions(); if ($ignoreProductQuestions && $ignoreProductQuestions->count()) { foreach ($ignoreProductQuestions as $ignoreProductQuestion) { unset($productQuestionsArray[$ignoreProductQuestion->ID]); } } $additionalProductQuestions = $this->owner->AdditionalProductQuestions(); if ($additionalProductQuestions && $additionalProductQuestions->count()) { foreach ($additionalProductQuestions as $additionalProductQuestion) { $productQuestionsArray[$additionalProductQuestion->ID] = $additionalProductQuestion->ID; } } if (!count($productQuestionsArray)) { $productQuestionsArray = array(0 => 0); } self::$_product_questions_cache[$this->owner->ID] = ProductQuestion::get()->filter(array("ID" => $productQuestionsArray)); } return self::$_product_questions_cache[$this->owner->ID]; }
/** * * @param Array $answers * ID = ProductQuestion.ID * "ID" => "Answer" (String) * @param Boolean $write */ function updateOrderItemWithProductAnswers($answers, $write = true) { if ($this->owner->canEdit()) { $this->owner->ProductQuestionsAnswer = ""; if (is_array($answers) && count($answers)) { foreach ($answers as $productQuestionID => $productQuestionAnswer) { $question = ProductQuestion::get()->byID(intval($productQuestionID)); if ($question) { } //$form->addErrorMessage("ProductQuestions", $message, $type); } $this->owner->ProductQuestionsAnswer = $this->owner->renderWith("ProductQuestionsAnswers"); } $this->owner->JSONAnswers = json_encode($answers); if ($write) { $this->owner->write(); } } }