示例#1
0
 /**
  * Get option modifiers
  *
  * @param \XLite\Module\CDev\ProductOptions\Model\Option $option Options OPTIONAL
  *
  * @return array
  */
 public function getOptionModifiers(\XLite\Module\CDev\ProductOptions\Model\Option $option = null)
 {
     $keys = array_keys($this->getModifiersNames());
     $result = array();
     foreach ($keys as $key) {
         if ($option) {
             $result[$key] = $option->getSurcharge($key);
         }
         if (!isset($result[$key]) || !$result[$key]) {
             $result[$key] = new \XLite\Module\CDev\ProductOptions\Model\OptionSurcharge();
             $result[$key]->setType($key);
         }
     }
     return $result;
 }
示例#2
0
 /**
  * Check - option is selected or not
  *
  * @param \XLite\Module\CDev\ProductOptions\Model\Option $option Option class
  *
  * @return boolean
  */
 public function isOptionSelected(\XLite\Module\CDev\ProductOptions\Model\Option $option)
 {
     $selected = $this->getParam(self::PARAM_SELECTED_OPTIONS);
     if (is_array($selected) && isset($selected[$option->getGroup()->getGroupId()])) {
         $optionId = $selected[$option->getGroup()->getGroupId()];
     }
     if (!isset($optionId)) {
         $options = $option->getGroup()->getOptions();
         $optionId = 0 < count($options) ? $options[0]->getOptionId() : 0;
     }
     return $optionId == $option->getOptionId();
 }
示例#3
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;
 }
示例#4
0
 /**
  * Check - is option selected in specified exception or not
  *
  * @param array                                          $exception Exception cell
  * @param \XLite\Module\CDev\ProductOptions\Model\Option $option    Option
  *
  * @return boolean
  */
 public function isOptionSelected(array $exception, \XLite\Module\CDev\ProductOptions\Model\Option $option)
 {
     return isset($exception[$option->getGroup()->getGroupId()]) && $exception[$option->getGroup()->getGroupId()] == $option->getOptionId();
 }
示例#5
0
文件: Product.php 项目: kingsj/core
 /**
  * Update option surcharge 
  * 
  * @param \XLite\Module\CDev\ProductOptions\Model\Option $model    Option
  * @param array                                          $modifier Modifier data
  * @param string                                         $type     Modifier type
  *  
  * @return void
  */
 protected function updateOptionSurcharge(\XLite\Module\CDev\ProductOptions\Model\Option $model, array $modifier, $type)
 {
     $surcharge = $model->getSurcharge($type);
     if (0 != $modifier['value'] && !$surcharge) {
         // Create if new value is not empty
         $surcharge = new \XLite\Module\CDev\ProductOptions\Model\OptionSurcharge();
         $model->addSurcharges($surcharge);
         $surcharge->setOption($model);
         $surcharge->setType($type);
     }
     if (0 == $modifier['value'] && $surcharge) {
         // Remove if new value is empty
         \XLite\Core\Database::getEM()->remove($surcharge);
         $model->getSurcharges()->removeElement($surcharge);
     } elseif ($surcharge) {
         $surcharge->setModifierType($modifier['type']);
         $surcharge->setModifier($modifier['value']);
     }
 }