Esempio n. 1
0
 protected function getTestGroup()
 {
     $group = new XLite\Module\CDev\ProductOptions\Model\OptionGroup();
     $group->setProduct($this->getProduct());
     $this->getProduct()->addOptionGroups($group);
     $group->map($this->testGroup);
     $option = new XLite\Module\CDev\ProductOptions\Model\Option();
     $option->setGroup($group);
     $group->addOptions($option);
     $option->map($this->testOption);
     $option = new XLite\Module\CDev\ProductOptions\Model\Option();
     $option->setGroup($group);
     $group->addOptions($option);
     $option->map($this->testOption);
     $option->setName('o2');
     $option = new XLite\Module\CDev\ProductOptions\Model\Option();
     $option->setGroup($group);
     $group->addOptions($option);
     $option->map($this->testOption);
     $option->setName('o3');
     $s = new XLite\Module\CDev\ProductOptions\Model\OptionSurcharge();
     $s->setOption($option);
     $s->setType('price');
     $s->setModifier(10);
     $s->setModifierType('$');
     $option->addSurcharges($s);
     $e = new XLite\Module\CDev\ProductOptions\Model\OptionException();
     $e->setOption($option);
     $e->setExceptionId(\XLite\Core\Database::getRepo('XLite\\Module\\CDev\\ProductOptions\\Model\\OptionException')->getNextExceptionId());
     $option->addExceptions($e);
     \XLite\Core\Database::getEM()->persist($group);
     \XLite\Core\Database::getEM()->flush();
     return $group;
 }
Esempio n. 2
0
 protected function getTestGroups()
 {
     foreach ($this->testGroups as $data) {
         $group = new XLite\Module\CDev\ProductOptions\Model\OptionGroup();
         $group->setProduct($this->getProduct());
         $this->getProduct()->addOptionGroups($group);
         $group->map($data);
         foreach ($this->testOptions[$data['name']] as $opt) {
             $option = new XLite\Module\CDev\ProductOptions\Model\Option();
             $option->setGroup($group);
             $group->addOptions($option);
             $option->map($opt);
         }
         \XLite\Core\Database::getEM()->persist($group);
     }
     $e = new XLite\Module\CDev\ProductOptions\Model\OptionException();
     $e->setOption($this->getProduct()->getOptionGroups()->get(0)->getOptions()->get(0));
     $e->setOption($this->getProduct()->getOptionGroups()->get(1)->getOptions()->get(1));
     $e->setExceptionId(\XLite\Core\Database::getRepo('XLite\\Module\\CDev\\ProductOptions\\Model\\OptionException')->getNextExceptionId());
     $this->getProduct()->getOptionGroups()->get(0)->getOptions()->get(0)->addExceptions($e);
     $this->getProduct()->getOptionGroups()->get(1)->getOptions()->get(1)->addExceptions($e);
     \XLite\Core\Database::getEM()->flush();
     $e = new XLite\Module\CDev\ProductOptions\Model\OptionException();
     $e->setOption($this->getProduct()->getOptionGroups()->get(0)->getOptions()->get(1));
     $e->setOption($this->getProduct()->getOptionGroups()->get(1)->getOptions()->get(1));
     $e->setExceptionId(\XLite\Core\Database::getRepo('XLite\\Module\\CDev\\ProductOptions\\Model\\OptionException')->getNextExceptionId());
     $this->getProduct()->getOptionGroups()->get(0)->getOptions()->get(1)->addExceptions($e);
     $this->getProduct()->getOptionGroups()->get(1)->getOptions()->get(1)->addExceptions($e);
     \XLite\Core\Database::getEM()->flush();
 }
Esempio n. 3
0
 protected function getTestGroup()
 {
     $group = new XLite\Module\CDev\ProductOptions\Model\OptionGroup();
     $group->setProduct($this->getProduct());
     $this->getProduct()->addOptionGroups($group);
     $group->map($this->testGroup);
     $option = new XLite\Module\CDev\ProductOptions\Model\Option();
     $option->setGroup($group);
     $group->addOptions($option);
     $option->map($this->testOption);
     \XLite\Core\Database::getEM()->persist($group);
     \XLite\Core\Database::getEM()->flush();
     return $group;
 }
Esempio n. 4
0
 /**
  * Update option group
  *
  * @return void
  */
 protected function doActionUpdateOptionGroup()
 {
     if ('0' === \XLite\Core\Request::getInstance()->groupId) {
         $group = new \XLite\Module\CDev\ProductOptions\Model\OptionGroup();
         $group->setProduct($this->getProduct());
         $this->getProduct()->addOptionGroups($group);
     } else {
         $group = \XLite\Core\Database::getRepo('\\XLite\\Module\\CDev\\ProductOptions\\Model\\OptionGroup')->find(\XLite\Core\Request::getInstance()->groupId);
     }
     $data = \XLite\Core\Request::getInstance()->data;
     if (!isset($group)) {
         \XLite\Core\TopMessage::addError('The modified option group has not been found');
     } elseif (!$this->getProduct()) {
         \XLite\Core\TopMessage::addError('The modified product has not been found');
     } elseif (!is_array($data)) {
         \XLite\Core\TopMessage::addError('The modified option group data has not been found');
     } elseif (!isset($data['name']) || !$data['name']) {
         \XLite\Core\TopMessage::addError('The modified option group must have a name');
     } elseif (!$group->setType($data['type'])) {
         \XLite\Core\TopMessage::addError('The modified option group has a wrong type');
     } elseif (!$group->setViewType($data['view_type'])) {
         \XLite\Core\TopMessage::addError('The display type is not allowed with this type of option');
     } else {
         $data['orderby'] = abs(intval($data['orderby']));
         $data['enabled'] = isset($data['enabled']) && $data['enabled'];
         $group->map($data);
         $result = true;
         // Update options
         $options = \XLite\Core\Request::getInstance()->options;
         if ($options && \XLite\Core\Request::getInstance()->groupId) {
             foreach ($options as $optionId => $data) {
                 $option = \XLite\Core\Database::getRepo('\\XLite\\Module\\CDev\\ProductOptions\\Model\\Option')->find($optionId);
                 if ($option && !$this->saveOption($option, $data)) {
                     $result = false;
                     break;
                 }
             }
         }
         // Save new option
         $newOption = \XLite\Core\Request::getInstance()->newOption;
         if ($newOption['name']) {
             $option = new \XLite\Module\CDev\ProductOptions\Model\Option();
             $option->setGroup($group);
             $group->addOptions($option);
             if (!$this->saveOption($option, $newOption)) {
                 $result = false;
             }
         }
         if ($result) {
             \XLite\Core\Database::getEM()->persist($group);
             \XLite\Core\Database::getEM()->flush();
             if ('0' === \XLite\Core\Request::getInstance()->groupId) {
                 \XLite\Core\TopMessage::addInfo('The product option group has been added successfully');
             } else {
                 \XLite\Core\TopMessage::addInfo('The product option group has been updated successfully');
             }
         }
     }
 }