Exemplo n.º 1
0
 /**
  * Preview order's email
  */
 public function emailPreview()
 {
     $id = $this->app->request->getInt('id');
     $order = JBModelOrder::model()->getById($id);
     if (!$order) {
         throw new Exception('Order #' . $id . ' not forund');
     }
     $emailElement = $this->_element->create('sendemail', JBCart::ELEMENT_TYPE_NOTIFICATION, array());
     if (is_null($emailElement)) {
         throw new Exception('Sendemail element is not forund');
     }
     $emailElement->setOrder($order);
     $emailElement->config->set('layout_email', $this->app->jbrequest->get('layout', 'string'));
     $html = $emailElement->renderBody();
     jexit($html);
 }
Exemplo n.º 2
0
 /**
  * Create form fields
  */
 public function formFields()
 {
     $configModel = JBModelConfig::model();
     $application = $this->_migrate->getCartApp();
     $templatePath = null;
     $orderFields = null;
     if ($application) {
         $templatePath = $application->getTemplate()->getPath();
         $orderFields = $this->_migrate->getOrderFields();
     }
     if ($templatePath && $orderFields) {
         $posFile = $templatePath . '/renderer/item/positions.config';
         $renderParams = array();
         if (JFile::exists($posFile)) {
             $posFile = $this->app->data->create(json_decode(file_get_contents($posFile), true));
             foreach ($posFile->get('jbuniversal.order.order', array()) as $position) {
                 foreach ($position as $element) {
                     $renderParams[$element['element']] = $element;
                 }
             }
         }
         foreach ($renderParams as $elemId => $renderParam) {
             if (!isset($orderFields[$elemId])) {
                 continue;
             }
             /**
              * @var AppData $config
              * @var AppData $renderParam
              */
             $config = $this->app->data->create($orderFields[$elemId]);
             $renderParam = $this->app->data->create($renderParam);
             $elemType = isset($this->_elementMap[$config['type']]) ? $this->_elementMap[$config['type']] : 'text';
             $orderElement = $this->_element->create($elemType, JBCart::ELEMENT_TYPE_ORDER, array('name' => $config->get('name'), 'description' => $config->get('description'), 'access' => $config->get('access'), 'default' => $config->get('default'), 'option' => $config->get('option'), 'multiple' => $config->get('multiple')));
             $list = $configModel->getGroup('cart.field');
             $list[JBCart::DEFAULT_POSITION][$orderElement->identifier] = (array) $orderElement->config;
             $configModel->setGroup('cart.field', $list);
             $renderElement = array('user_field' => '', 'showlabel' => '0', 'altlabel' => $renderParam->get('altlabel'), 'required' => $renderParam->get('required', 0), 'type' => $orderElement->getElementType(), 'group' => $orderElement->getElementGroup(), 'identifier' => $orderElement->identifier);
             $list = $configModel->getGroup('cart.field_tmpl.default');
             $list[JBCart::DEFAULT_POSITION][] = $renderElement;
             $configModel->setGroup('cart.field_tmpl.default', $list);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Execute all elements in the event position
  * @param AppEvent    $event
  * @param array       $elements
  * @param JBCartOrder $order
  * @param array       $params
  */
 protected function _execElements($event, $elements, $order, $params)
 {
     $elements = (array) $elements;
     if (empty($elements)) {
         return;
     }
     foreach ($elements as $config) {
         // try to create order object
         $element = $this->_element->create($config['type'], $config['group'], $config);
         if (!$element) {
             continue;
         }
         // try to set order object
         if ($order && method_exists($element, 'setOrder') && $order instanceof JBCartOrder) {
             $element->setOrder($order);
         }
         // try to set order object
         if ($order && method_exists($element, 'setEvent')) {
             $element->setEvent($event);
         }
         // check is event available
         if (method_exists($element, 'hasValue') && !$element->hasValue($params)) {
             return;
         }
         // try to execute the element
         if (method_exists($element, 'notify')) {
             try {
                 $elemResult = $element->notify($params);
             } catch (JBCartOrderException $e) {
                 $this->app->jbnotify->warning(JText::_($e->getMessage()));
             }
             if (self::EVENT_BREAK == $elemResult) {
                 return;
                 // break event chain
             }
         }
     }
 }