/** @inheritdoc} */
 public function error($message = '', $data = array(), $placeholders = array())
 {
     if (!is_object($this->ms2)) {
         $this->ms2 = $this->modx->getService('minishop2');
     }
     return $this->ms2->error($message, $data, $placeholders);
 }
Beispiel #2
0
 /**
  * @param array $data
  *
  * @return array|string
  */
 public function createPayment(array $data)
 {
     if (!$this->modx->user->isAuthenticated($this->modx->context->key)) {
         return $this->ms2->error($this->modx->lexicon('ms2_profile_err_auth'));
     }
     // Call system event
     $response = $this->ms2->invokeEvent('msOnSubmitOrder', array('data' => $data, 'order' => $this->ms2->order));
     if (!$response['success']) {
         return $this->ms2->error($response['message']);
     }
     if (!empty($response['data']['data'])) {
         $data = array_merge($data, $response['data']['data']);
         $this->ms2->order->set($data);
     }
     // Check required fields
     $errors = array();
     if (empty($data['sum']) || $data['sum'] < $this->config['minSum']) {
         $errors['sum'] = $this->modx->lexicon('ms2_profile_err_min_sum', array('min_sum' => $this->config['minSum']));
     } elseif (!empty($maxSum) && $data['sum'] > $this->config['maxSum']) {
         $errors['sum'] = $this->modx->lexicon('ms2_profile_err_max_sum', array('max_sum' => $this->config['maxSum']));
     }
     if (empty($data['payment'])) {
         $errors['payment'] = $this->modx->lexicon('ms2_profile_err_payment', array('min_sum' => $this->config['minSum']));
     }
     if (!empty($errors)) {
         return $this->ms2->error($this->modx->lexicon('ms2_profile_err_form'), $errors);
     }
     // Create new order
     /** @var msOrder $order */
     $order = $this->modx->newObject('msOrder', array('user_id' => $this->modx->user->id, 'createdon' => date('Y-m-d H:i:s'), 'num' => $this->ms2->order->getnum(), 'delivery' => 0, 'payment' => $data['payment'], 'cart_cost' => $data['sum'], 'weight' => 0, 'delivery_cost' => 0, 'cost' => $data['sum'], 'status' => 0, 'context' => $this->ms2->config['ctx'], 'properties' => array('account_charge' => true)));
     $products = array($this->modx->newObject('msOrderProduct', array('product_id' => 0, 'name' => $this->modx->lexicon('ms2_profile_charge'), 'price' => $data['sum'], 'cost' => $data['sum'])));
     $order->addMany($products);
     $response = $this->ms2->invokeEvent('msOnBeforeCreateOrder', array('msOrder' => $order, 'order' => $this->ms2->order));
     if (!$response['success']) {
         return $this->ms2->error($response['message']);
     }
     if ($order->save()) {
         $response = $this->ms2->invokeEvent('msOnCreateOrder', array('msOrder' => $order, 'order' => $this->ms2->order));
         if (!$response['success']) {
             return $this->ms2->error($response['message']);
         }
         if (empty($_SESSION['minishop2']['orders'])) {
             $_SESSION['minishop2']['orders'] = array();
         }
         $_SESSION['minishop2']['orders'][] = $order->get('id');
         // Trying to set status "new"
         $response = $this->ms2->changeOrderStatus($order->get('id'), 1);
         if ($response !== true) {
             return $this->ms2->error($response, array('msorder' => $order->get('id')));
         } elseif ($payment = $this->modx->getObject('msPayment', array('id' => $order->get('payment'), 'active' => 1))) {
             $response = $payment->send($order);
             if (!empty($response['data']['redirect'])) {
                 $this->modx->sendRedirect($response['data']['redirect']);
             } elseif (!empty($response['data']['msorder'])) {
                 $this->modx->sendRedirect($this->modx->context->makeUrl($this->modx->resource->id, array('msorder' => $response['data']['msorder'])));
             } else {
                 $this->modx->sendRedirect($this->modx->context->makeUrl($this->modx->resource->id));
             }
         } else {
             $this->modx->sendRedirect($this->modx->context->makeUrl($this->modx->resource->id, array('msorder' => $response['data']['msorder'])));
         }
     }
 }
 /**
  * Shorthand for MS2 error method
  *
  * @param string $message
  * @param array $data
  * @param array $placeholders
  *
  * @return array|string
  */
 public function error($message = '', $data = array(), $placeholders = array())
 {
     return $this->ms2->error($message, $data, $placeholders);
 }