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; }
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; }
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); }
/** {@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; }