예제 #1
0
 /**
  * @param string $position
  * @param array  $args
  * @return string|void
  */
 public function renderPosition($position, $args = array())
 {
     // init vars
     $elements = array();
     $output = array();
     $style = isset($args['style']) ? $args['style'] : 'order.modifier';
     $layout = $this->_layout;
     // render elements
     foreach ($this->_getConfigPosition($position) as $index => $data) {
         if ($element = $this->_order->getModifierOrderPriceElement($data['identifier'])) {
             if (!$element->canAccess()) {
                 continue;
             }
             $data['_layout'] = $this->_layout;
             $data['_position'] = $position;
             $data['_index'] = $index;
             // set params
             $params = array_merge((array) $data, $args);
             // check value
             $elements[] = compact('element', 'params');
         }
     }
     foreach ($elements as $i => $data) {
         $output[$i] = parent::render('element.' . $style, array('element' => $data['element'], 'params' => array_merge(array('first' => $i == 0, 'last' => $i == count($elements) - 1), $data['params'])));
     }
     // restore layout
     $this->_layout = $layout;
     return implode(PHP_EOL, $output);
 }
예제 #2
0
 /**
  * @param string $eventType
  * @param JBCartOrder $order
  * @return array
  */
 public function getByEvent($eventType = null, $order)
 {
     $result = array();
     $eventType = 'list';
     // TODO add new evenet types
     $params = JBModelConfig::model()->get($eventType, array(), 'cart.validator');
     if (!empty($params)) {
         $result = array();
         foreach ($params as $elementParams) {
             $result[$elementParams['identifier']] = $order->getValidatorElement($elementParams['identifier']);
         }
     }
     return $result;
 }
예제 #3
0
 /**
  * @param $args
  * @return string
  */
 public function renderAdminPosition($args = array())
 {
     // init vars
     $elements = array();
     $output = array();
     $layout = $this->_layout;
     $style = isset($args['style']) ? $args['style'] : 'adminedit';
     $this->_order = isset($args['order']) ? $args['order'] : $this->_order;
     $shipping = $this->_order->getShipping();
     // render elements
     $shippingFields = $this->_order->getShippingFields();
     foreach ($shippingFields as $identifier => $data) {
         if ($element = $this->_order->getShippingFieldElement($identifier)) {
             if ($shipping && !$shipping->hasShippingField($identifier)) {
                 continue;
             }
             $element->bindData($data);
             $params = array_merge(array('_layout' => $this->_layout, '_index' => $identifier), $args);
             $elements[] = compact('element', 'params');
         }
     }
     foreach ($elements as $i => $data) {
         $output[$i] = parent::render('element.' . $style, array('element' => $data['element'], 'params' => array_merge(array('first' => $i == 0, 'last' => $i == count($elements) - 1), $data['params'])));
     }
     // restore layout
     $this->_layout = $layout;
     return implode(PHP_EOL, $output);
 }
예제 #4
0
파일: order.php 프로젝트: alexmixaylov/real
 /**
  * @param array $args
  * @return string
  */
 public function renderAdminPosition($args = array())
 {
     // init vars
     $elements = array();
     $output = array();
     $style = isset($args['style']) ? $args['style'] : 'adminedit';
     $layout = $this->_layout;
     $this->_order = isset($args['order']) ? $args['order'] : $this->_order;
     $fields = $this->_order->getFields();
     // render elements
     foreach ($fields as $identifier => $data) {
         if ($element = $this->_order->getFieldElement($identifier)) {
             $element->bindData($data);
             $data['_layout'] = $this->_layout;
             $data['_index'] = $identifier;
             // set params
             $params = array_merge((array) $data, $args);
             // check value
             $elements[] = compact('element', 'params');
         }
     }
     foreach ($elements as $i => $data) {
         $output[$i] = parent::render('element.' . $style, array('element' => $data['element'], 'params' => array_merge(array('first' => $i == 0, 'last' => $i == count($elements) - 1), $data['params'])));
     }
     // restore layout
     $this->_layout = $layout;
     return implode(PHP_EOL, $output);
 }
예제 #5
0
 /**
  * @param $identifier
  * @return JBCartElementShipping
  */
 protected function _getElement($identifier)
 {
     $shippingList = JBCart::getInstance()->getShippingList();
     if ($shipping = $this->_order->getShippingElement($identifier)) {
         if (isset($shippingList[$identifier])) {
             $shipping->bindData($shippingList[$identifier]);
         }
     }
     return $shipping;
 }
예제 #6
0
 /**
  * @param string $position
  * @param array  $args
  * @return string|void
  */
 public function renderPosition($position, $args = array())
 {
     // init vars
     $elements = array();
     $output = array();
     $style = isset($args['style']) ? $args['style'] : 'order.validator';
     $layout = $this->_layout;
     // render elements
     foreach ($this->_getConfigPosition($position) as $index => $data) {
         if ($element = $this->_order->getValidatorElement($data['identifier'])) {
             if (!$element->canAccess() || !$element->hasValue()) {
                 continue;
             }
             $data['_layout'] = $this->_layout;
             $data['_position'] = $position;
             $data['_index'] = $index;
             // set params
             $params = array_merge((array) $data, $args);
             // check value
             $elements[] = compact('element', 'params');
         }
     }
     foreach ($elements as $i => $data) {
         $output[$i] = parent::render('element.' . $style, array('element' => $data['element'], 'params' => array_merge(array('first' => $i == 0, 'last' => $i == count($elements) - 1), $data['params'])));
     }
     $this->_layout = $layout;
     if (isset($args['rowAttrs']) && is_array($args['rowAttrs'])) {
         $rowOutput = '';
         $_rowAttrs = array('class' => 'grid-row');
         $rowAttrs = array_replace_recursive($_rowAttrs, $args['rowAttrs']);
         $column = isset($args['column']) ? (int) $args['column'] : 3;
         $rowElements = array_chunk($output, $column);
         foreach ($rowElements as $elements) {
             $rowOutput .= '<div ' . $this->app->jbhtml->buildAttrs($rowAttrs) . '>';
             foreach ($elements as $element) {
                 $rowOutput .= $element;
             }
             $rowOutput .= '</div>';
         }
         return $rowOutput;
     }
     return implode(PHP_EOL, $output);
 }
예제 #7
0
 /**
  * Action for robot from payment system
  * Validate and check order as success
  * @throws AppException
  */
 public function paymentCallback()
 {
     $this->_init();
     $this->app->jbevent->fire($this->order, 'basket:paymentCallback');
     $this->app->jbdoc->rawOutput();
     $cart = JBCart::getInstance();
     /** @type JBCartElementPayment $payment */
     $payment = $this->order->getPayment();
     // check payment element
     if (empty($payment)) {
         $this->_error('Saved without payment element');
     }
     // payment is exists
     if (!$this->_orderInfo->get('type')) {
         $this->_error('Undefined payment system');
     }
     // check payment type
     if ($payment->getType() != $this->_orderInfo->get('type')) {
         $this->_error('Payment type is not correct');
     }
     // current status is not completed
     if ($payment->getStatus() == $cart->getPaymentSuccess()) {
         $this->_error('Payment status is "' . $payment->getStatus()->getCode() . '" already');
     }
     // check sum
     $realSum = $payment->getOrderSumm();
     $requestSum = $payment->getRequestOrderSum();
     if ($realSum->compare($requestSum, '!=', 5)) {
         $this->_error('Not correct amount');
     }
     // check if sum was empty
     if ($realSum->compare(0, '<=')) {
         $this->_error('Amount less or equal zero');
     }
     // checking of payment element
     if ($payment->isValid()) {
         $payment->setSuccess();
         $this->app->event->dispatcher->notify($this->app->event->create($this->order, 'basket:paymentSuccess'));
         $payment->renderResponse();
     } else {
         $this->_error('No valid request');
     }
 }
예제 #8
0
 /**
  * @param $args
  * @return string
  */
 public function renderAdminPosition($args = array())
 {
     // init vars
     $layout = $this->_layout;
     $style = isset($args['style']) ? $args['style'] : 'adminedit';
     $this->_order = isset($args['order']) ? $args['order'] : $this->_order;
     if ($payment = $this->_order->getPayment()) {
         $output = parent::render('element.' . $style, array('element' => $payment, 'params' => $args));
         // restore layout
         $this->_layout = $layout;
         return $output;
     }
 }
예제 #9
0
 /**
  * Filter action
  */
 function index()
 {
     $this->formRenderer = $this->app->jbrenderer->create('Order');
     $this->shippingRenderer = $this->app->jbrenderer->create('Shipping');
     $this->paymentRenderer = $this->app->jbrenderer->create('Payment');
     $this->validatorRenderer = $this->app->jbrenderer->create('Validator');
     $this->shippingFieldRenderer = $this->app->jbrenderer->create('ShippingFields');
     $this->modifierOrderPriceRenderer = $this->app->jbrenderer->create('ModifierOrderPrice');
     $this->shipping = $this->app->jbshipping->getEnabled();
     $this->shippingFields = $this->app->jbshipping->getFields();
     $this->payment = $this->app->jbpayment->getEnabled();
     $this->modifierPrice = $this->app->jbmodifierprice->getEnabled();
     $this->config = $this->_config;
     $this->Itemid = $this->_jbrequest->get('Itemid');
     $this->order = $this->cart->newOrder();
     $this->items = $this->order->getItems(true);
     $this->itemsHtml = $this->order->renderItems(array('image_width' => $this->_config->get('tmpl_image_width', 75), 'image_height' => $this->_config->get('tmpl_image_height', 75), 'image_link' => $this->_config->get('tmpl_image_link', 1), 'item_link' => $this->_config->get('tmpl_item_link', 1), 'edit' => true));
     $jbnotify = $this->app->jbnotify;
     $errors = 0;
     $orderSaved = false;
     $isPaymentBtn = $this->app->jbrequest->get('create-pay');
     if ($this->_jbrequest->isPost()) {
         $formData = $this->_getRequest();
         try {
             $errors += $this->order->bind($formData);
             $errorMessages = $this->order->isValid();
             $errors += count($errorMessages);
             if ($errors) {
                 $this->app->system->application->setUserState('JBZOO_ORDDER_SUBMISSION_FORM', serialize($formData));
                 // show custom error messages
                 $jbnotify->warning('JBZOO_CART_ORDER_SOME_ERROR');
                 $jbnotify->warning($errorMessages);
             } else {
                 // saving order
                 JBModelOrder::model()->save($this->order);
                 $orderSaved = true;
                 // empty cart items
                 $this->cart->removeItems();
                 // go to payment page
                 $payment = $this->order->getPayment();
                 $totalSum = $this->order->getTotalSum();
                 if ($totalSum->isPositive() && $isPaymentBtn && $payment && ($paymentUrl = $payment->getRedirectUrl())) {
                     $message = $payment->getSuccessMessage();
                     if (empty($message)) {
                         $message = 'JBZOO_CART_PAYMENT_REDIRECT';
                     }
                     $this->setRedirect($paymentUrl, JText::_($message));
                 } else {
                     $jbnotify->notice('JBZOO_CART_ORDER_SUCCESS_CREATED');
                 }
             }
         } catch (JBCartOrderException $e) {
             $jbnotify->warning(JText::_($e->getMessage()));
         } catch (AppException $e) {
             $jbnotify->warning(JText::_($e->getMessage()));
         }
     }
     $this->isError = $errors;
     $templatedName = 'basket';
     if ($orderSaved) {
         $templatedName = 'basket-success';
     }
     $this->getView($templatedName)->addTemplatePath($this->template->getPath())->setLayout($templatedName)->display();
 }
예제 #10
0
 /**
  * @param JBCartOrder $order
  * @param bool|false  $silentMode
  * @return int|mixed
  */
 public function save(JBCartOrder $order, $silentMode = false)
 {
     $this->app->jbtables->checkOrder();
     $currencies = $order->getCurrencyList();
     $params = $order->getParams();
     $params->set(JBCart::CONFIG_CURRENCIES, $currencies);
     $cartConfig = $order->params->find('config');
     if (!$cartConfig) {
         $cartConfig = JBModelConfig::model()->getGroup('cart.config');
     }
     $params->set('config', (array) $cartConfig);
     $total = $order->getTotalSum()->data();
     $data = array('id' => $order->id, 'status' => $order->getStatus()->getCode(), 'status_payment' => $order->getPaymentStatus(), 'status_shipping' => $order->getShippingStatus(), 'created' => $order->created, 'created_by' => $order->created_by, 'total' => $total[0], 'items' => $order->getItems(false), 'fields' => $order->getFields(), 'shippingfields' => $order->getShippingFields(), 'modifiers' => $order->getModifiersData(), 'params' => $params, 'comment' => $order->comment);
     if ($shipping = $order->getShipping()) {
         $data['shipping'] = $shipping->data();
     }
     if ($payment = $order->getPayment()) {
         $data['payment'] = $payment->data();
     }
     if (!$silentMode) {
         $this->app->jbevent->fire($order, 'basket:beforeSave');
     }
     if ($data['id'] <= 0) {
         unset($data['id']);
         $order->id = $this->_insert($data, ZOO_TABLE_JBZOO_ORDER);
         //TODO hardcoded
         $order->setItemsData((string) $data['items']);
         if (!$silentMode) {
             $this->app->jbevent->fire($order, 'basket:saved');
         }
     } else {
         $data['modified'] = $this->app->jbdate->toMySql();
         $this->_update($data, ZOO_TABLE_JBZOO_ORDER);
         if (!$silentMode) {
             $this->app->jbevent->fire($order, 'basket:updated');
         }
     }
     if ($order->id && !$silentMode) {
         $this->app->jbevent->fire($order, 'basket:afterSave');
     }
     return $order->id;
 }
예제 #11
0
 /**
  * @param string      $text
  * @param string      $macros
  * @param JBCartOrder $order
  * @return mixed
  * @throws Exception
  */
 private function _replaceMacros($text, $macros, JBCartOrder $order = null)
 {
     if ($macros == 'date') {
         $date = new JDate();
         $replace = $date->format(JText::_('DATE_FORMAT_LC3'));
     } else {
         if ($macros == 'time') {
             $date = new JDate();
             $replace = $date->format('H:i');
         } else {
             if ($macros == 'datetime') {
                 $date = new JDate();
                 $replace = $date->format('Y-m-d H:m');
             } else {
                 if ($macros == 'order_id' && $order) {
                     $replace = $order->getName('short');
                 } else {
                     if ($macros == 'order_name' && $order) {
                         $replace = $order->getName('full');
                     } else {
                         if ($macros == 'order_status' && $order) {
                             $replace = $order->getStatus()->getName();
                         } else {
                             if ($macros == 'order_total' && $order) {
                                 $replace = $order->getTotalSum()->text();
                             } else {
                                 if ($macros == 'order_payment_name' && $order) {
                                     $replace = JText::_('JBZOO_UNDEFINED');
                                     if ($payment = $order->getPayment()) {
                                         $replace = $payment->getName();
                                     }
                                 } else {
                                     if ($macros == 'order_payment_stat' && $order) {
                                         $replace = $order->getPaymentStatus()->getName();
                                     } else {
                                         if ($macros == 'order_shipping_name' && $order) {
                                             $replace = JText::_('JBZOO_UNDEFINED');
                                             if ($shipping = $order->getShipping()) {
                                                 $replace = $shipping->getName();
                                             }
                                         } else {
                                             if ($macros == 'order_shipping_stat' && $order) {
                                                 $replace = $order->getShippingStatus()->getName();
                                             } else {
                                                 if ($macros == 'user_id') {
                                                     $replace = (int) JFactory::getUser()->id;
                                                 } else {
                                                     if ($macros == 'user_name') {
                                                         $juser = JFactory::getUser();
                                                         $replace = $juser->id > 0 ? $juser->get('name') : JText::_('JBZOO_UNDEFINED');
                                                     } else {
                                                         if ($macros == 'order_created_id') {
                                                             $replace = $order->created_by;
                                                         } else {
                                                             if ($macros == 'order_created_name') {
                                                                 $juser = JFactory::getUser($order->created_by);
                                                                 $replace = $juser->id > 0 ? $juser->name : JText::_('JBZOO_UNDEFINED');
                                                             } else {
                                                                 if ($macros == 'site_name') {
                                                                     $replace = JFactory::getConfig()->get('sitename', '');
                                                                 } else {
                                                                     if ($macros == 'site_desc') {
                                                                         $replace = JFactory::getConfig()->get('MetaDesc', '');
                                                                     } else {
                                                                         if ($macros == 'site_url') {
                                                                             $replace = JUri::root();
                                                                         } else {
                                                                             if ($macros == 'site_link') {
                                                                                 $sitename = JString::trim(JFactory::getConfig()->get('sitename'));
                                                                                 $replace = '<a href="' . JUri::root() . '" target="_blank">' . $sitename . '</a>';
                                                                             } else {
                                                                                 if ($macros == 'shop_name') {
                                                                                     $replace = JBModelConfig::model()->get('shop_name', '', 'cart.config');
                                                                                 } else {
                                                                                     if ($macros == 'shop_desc') {
                                                                                         $replace = JBModelConfig::model()->get('shop_details', '', 'cart.config');
                                                                                     } else {
                                                                                         if ($macros == 'shop_country') {
                                                                                             $replace = JBModelConfig::model()->get('default_shipping_country', '', 'cart.config');
                                                                                         } else {
                                                                                             if ($macros == 'shop_city') {
                                                                                                 $replace = JBModelConfig::model()->get('default_shipping_city', '', 'cart.config');
                                                                                             } else {
                                                                                                 if ($macros == 'shop_address') {
                                                                                                     $replace = JBModelConfig::model()->get('default_shipping_address', '', 'cart.config');
                                                                                                 } else {
                                                                                                     if ($macros == 'shop_zip') {
                                                                                                         $replace = JBModelConfig::model()->get('default_shipping_zip', '', 'cart.config');
                                                                                                     } else {
                                                                                                         throw new Exception('Undefined email macros: "{' . $macros . '}"');
                                                                                                     }
                                                                                                 }
                                                                                             }
                                                                                         }
                                                                                     }
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (isset($replace)) {
         $replace = JString::trim($replace);
         $macros = preg_quote('{' . trim($macros) . '}');
         $text = preg_replace('#' . $macros . '#ius', $replace, $text);
     }
     return $text;
 }