예제 #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;
 }
예제 #2
0
파일: Product.php 프로젝트: kingsj/core
 /**
  * Save option
  *
  * @param \XLite\Module\CDev\ProductOptions\Model\Option $option Option
  * @param array                                          $data   Data
  *
  * @return boolean
  */
 protected function saveOption(\XLite\Module\CDev\ProductOptions\Model\Option $option, array $data)
 {
     $result = false;
     if (!$data['name']) {
         \XLite\Core\TopMessage::addError('The modified option group has a wrong display type');
     } else {
         $data['orderby'] = abs(intval($data['orderby']));
         $data['enabled'] = isset($data['enabled']) && $data['enabled'];
         if (isset($data['modifiers'])) {
             foreach ($data['modifiers'] as $type => $m) {
                 $m['modifier'] = round($m['modifier'], 4);
                 if (0 != $m['modifier']) {
                     $surcharge = $option->getSurcharge($type);
                     if (!$surcharge) {
                         $surcharge = new \XLite\Module\CDev\ProductOptions\Model\OptionSurcharge();
                         $surcharge->setOption($option);
                         $option->addSurcharges($surcharge);
                         $surcharge->setType($type);
                     }
                     $surcharge->map($m);
                     \XLite\Core\Database::getEM()->persist($surcharge);
                 } elseif ($option->getSurcharge($type)) {
                     $surcharge = $option->getSurcharge($type);
                     $option->getSurcharges()->removeElement($surcharge);
                     $surcharge->setOption(null);
                     \XLite\Core\Database::getEM()->remove($surcharge);
                 }
             }
             unset($data['modifiers']);
         }
         $option->map($data);
         \XLite\Core\Database::getEM()->persist($option);
         $result = true;
     }
     return $result;
 }