コード例 #1
0
 /** @inheritdoc} */
 public function success($message = '', $data = array(), $placeholders = array())
 {
     if (!is_object($this->ms2)) {
         $this->ms2 = $this->modx->getService('minishop2');
     }
     return $this->ms2->success($message, $data, $placeholders);
 }
コード例 #2
0
 public function prepareRow(xPDOObject $object)
 {
     $fields = array_map('trim', explode(',', $this->modx->getOption('office_ms2_order_product_fields', null, '')));
     $fields = array_values(array_unique(array_merge($fields, array('product_id', 'name', 'url'))));
     $data = array();
     foreach ($fields as $v) {
         $data[$v] = $object->get($v);
         if ($v == 'product_price' || $v == 'product_old_price' || $v == 'price' || $v == 'cost') {
             $data[$v] = $this->ms2->formatPrice($data[$v]);
         } elseif ($v == 'product_weight') {
             $data[$v] = $this->ms2->formatWeight($data[$v]);
         }
     }
     if (empty($data['name'])) {
         $data['name'] = $object->get('product_pagetitle');
     }
     $options = $object->get('options');
     if (!empty($options) && is_array($options)) {
         $tmp = array();
         foreach ($options as $k => $v) {
             $tmp[] = $this->modx->lexicon('office_ms2_' . $k) . ': ' . $v;
             $data['option_' . $k] = $v;
         }
         $data['options'] = implode('; ', $tmp);
     }
     $data['url'] = $object->get('product_id') ? $this->modx->makeUrl($object->get('product_id'), $object->get('product_context_key'), '', 'full') : '';
     return $data;
 }
コード例 #3
0
 public function prepareArray(array $data)
 {
     $data = array_map('strip_tags', $data);
     if (isset($data['cost'])) {
         $data['cost'] = $this->ms2->formatPrice($data['cost']);
     }
     if (isset($data['cart_cost'])) {
         $data['cart_cost'] = $this->ms2->formatPrice($data['cart_cost']);
     }
     if (isset($data['delivery_cost'])) {
         $data['delivery_cost'] = $this->ms2->formatPrice($data['delivery_cost']);
     }
     if (isset($data['weight'])) {
         $data['weight'] = $this->ms2->formatWeight($data['weight']);
     }
     if (isset($data['status'])) {
         $data['status'] = $this->modx->lexicon(str_replace(array('[[%', ']]'), '', $data['status']));
         $data['status'] = '<span style="color:#' . $data['color'] . ';">' . $data['status'] . '</span>';
     }
     if (isset($data['delivery'])) {
         $data['delivery'] = $this->modx->lexicon(str_replace(array('[[%', ']]'), '', $data['delivery']));
     }
     if (isset($data['payment'])) {
         $data['payment'] = $this->modx->lexicon(str_replace(array('[[%', ']]'), '', $data['payment']));
     }
     unset($data['color']);
     return $data;
 }
コード例 #4
0
 public function cleanup()
 {
     $order_fields = array_map('trim', explode(',', $this->modx->getOption('office_ms2_order_form_fields', null, '', true)));
     $order_fields = array_intersect($order_fields, array_keys($this->modx->getFieldMeta('msOrder')));
     if (!in_array('cost', $order_fields)) {
         $order_fields[] = 'cost';
     }
     unset($order_fields['comment']);
     $array = array();
     foreach ($order_fields as $v) {
         if ($v == 'createdon' || $v == 'updatedon') {
             $array[$v] = $this->ms2->formatDate($this->object->get($v));
         } elseif ($v == 'cost' || $v == 'cart_cost' || $v == 'delivery_cost') {
             $array[$v] = $this->ms2->formatPrice($this->object->get($v));
         } elseif ($v == 'weight') {
             $array[$v] = $this->ms2->formatWeight($this->object->get($v));
         } else {
             $array[$v] = $this->object->get($v);
         }
     }
     if ($profile = $this->object->getOne('UserProfile')) {
         $array = array_merge($array, array('fullname' => $profile->get('fullname')));
     }
     if (in_array('status', $order_fields) && ($tmp = $this->object->getOne('Status'))) {
         $array['status'] = $this->modx->lexicon(str_replace(array('[[%', ']]'), '', $tmp->get('name')));
     }
     if (in_array('delivery', $order_fields) && ($tmp = $this->object->getOne('Delivery'))) {
         $array['delivery'] = $this->modx->lexicon(str_replace(array('[[%', ']]'), '', $tmp->get('name')));
     }
     if (in_array('payment', $order_fields) && ($tmp = $this->object->getOne('Payment'))) {
         $array['payment'] = $this->modx->lexicon(str_replace(array('[[%', ']]'), '', $tmp->get('name')));
     }
     $address_fields = array_map('trim', explode(',', $this->modx->getOption('office_ms2_order_address_fields', null, '', true)));
     $address_fields = array_intersect($address_fields, array_keys($this->modx->getFieldMeta('msOrderAddress')));
     /* @var msOrderAddress $address */
     if ($address = $this->object->getOne('Address')) {
         foreach ($address_fields as $v) {
             $array['addr_' . $v] = $address->get($v);
         }
     }
     $array = array_map('strip_tags', $array);
     return $this->success('', $array);
 }
コード例 #5
0
ファイル: getlist.class.php プロジェクト: volkovnd/miniShop2
 /** {@inheritDoc} */
 public function prepareArray(array $data)
 {
     if (empty($data['customer'])) {
         $data['customer'] = $data['customer_username'];
     }
     $data['status'] = '<span style="color:#' . $data['color'] . ';">' . $data['status'] . '</span>';
     $data['actions'] = array(array('className' => 'update', 'text' => $this->modx->lexicon('ms2_menu_update')), array('className' => 'delete', 'text' => $this->modx->lexicon('ms2_menu_remove')));
     if (isset($data['cost'])) {
         $data['cost'] = $this->ms2->formatPrice($data['cost']);
     }
     if (isset($data['cart_cost'])) {
         $data['cart_cost'] = $this->ms2->formatPrice($data['cart_cost']);
     }
     if (isset($data['delivery_cost'])) {
         $data['delivery_cost'] = $this->ms2->formatPrice($data['delivery_cost']);
     }
     if (isset($data['weight'])) {
         $data['weight'] = $this->ms2->formatWeight($data['weight']);
     }
     return $data;
 }
コード例 #6
0
ファイル: msprofile.class.php プロジェクト: ASDAFF/msProfile
 /**
  * @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'])));
         }
     }
 }
コード例 #7
0
 /**
  * Shorthand for MS2 success method
  *
  * @param string $message
  * @param array $data
  * @param array $placeholders
  *
  * @return array|string
  */
 public function success($message = '', $data = array(), $placeholders = array())
 {
     return $this->ms2->success($message, $data, $placeholders);
 }