Пример #1
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;
 }
Пример #2
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;
 }