Esempio n. 1
0
 public function modifyItemOption(OrderedItem $item, ProductOption $option, Request $request, $varName)
 {
     if ($option->isBool() && $request->isValueSet('checkbox_' . $varName)) {
         if ($request->get($varName)) {
             $item->addOptionChoice($option->defaultChoice->get());
         } else {
             $item->removeOption($option);
         }
     } else {
         if ($option->isFile()) {
             if (isset($_FILES['upload_' . $varName])) {
                 $file = $_FILES['upload_' . $varName];
                 if (!empty($file['name'])) {
                     $item->removeOption($option);
                     $choice = $item->addOptionChoice($option->defaultChoice->get());
                     $choice->setFile($_FILES['upload_' . $varName]);
                 }
             }
         } else {
             if ($request->get($varName)) {
                 if ($option->isSelect()) {
                     $item->addOptionChoice($option->getChoiceByID($request->get($varName)));
                 } else {
                     if ($option->isText()) {
                         $text = $request->get($varName);
                         if ($text) {
                             $choice = $item->addOptionChoice($option->defaultChoice->get());
                             $choice->optionText->set($text);
                         } else {
                             $item->removeOption($option);
                         }
                     }
                 }
             }
         }
     }
 }