Beispiel #1
0
 /**
  * Executes before rendering the page for the Add task.
  *
  * @param   string  $tpl  Subtemplate to use
  *
  * @return  boolean  Return true to allow rendering of the page
  */
 protected function onAdd($tpl = null)
 {
     $id = $this->input->getInt('id');
     $this->order = F0FTable::getAnInstance('Order', 'J2StoreTable');
     $this->order->load($id);
     $this->item = $this->order;
     $this->fieldClass = J2Store::getSelectableBase();
     $this->params = J2Store::config();
     $this->currency = J2Store::currency();
     $this->taxes = $this->order->getOrderTaxrates();
     $this->shipping = $this->order->getOrderShippingRate();
     $this->coupons = $this->order->getOrderCoupons();
     $this->vouchers = $this->order->getOrderVouchers();
     $this->orderinfo = $this->order->getOrderInformation();
     $this->orderhistory = $this->order->getOrderHistory();
     parent::onAdd();
 }
 /**
  * This method runs before the $data is saved to the $table. Return false to
  * stop saving.
  *
  * @param   array     &$data   The data to save
  * @param   F0FTable  &$table  The table to save the data to
  *
  * @return  boolean  Return false to prevent saving, true to allow it
  */
 public function save($data)
 {
     $status = true;
     //get the customfieldtable
     $table = $this->getTable();
     $selectableBase = J2Store::getSelectableBase();
     $result = $selectableBase->save();
     if ($result) {
         //get process field because result is true
         $data = $selectableBase->fielddata;
         //$table = $this->getTable();
         //$table->bind($data);
         $status = parent::save($data);
         //return true;
         //return $table->field_id;
     } else {
         //error get it
         $errors = $selectableBase->errors;
         $error = implode(',', $errors);
         throw new Exception($error);
         $status = false;
     }
     return true;
 }
Beispiel #3
0
 /**
  * Method to edit orderinfo based on the address type
  *
  */
 function setOrderinfo()
 {
     $order_id = $this->input->getString('order_id');
     $address_type = $this->input->getString('address_type');
     $orderinfo = F0FTable::getAnInstance('Orderinfo', 'J2StoreTable');
     $orderinfo->load(array('order_id' => $order_id));
     $type = "all_" . $address_type;
     $custom_datas = json_decode($orderinfo->{$type});
     $processed = $this->removePrefix((array) $orderinfo, $address_type);
     foreach ($custom_datas as $key => $custom_data) {
         $processed->{$key} = $custom_data->value;
     }
     $model = F0FModel::getTmpInstance('Orders', 'J2StoreModel');
     $view = $this->getThisView();
     $view->setModel($model, true);
     $view->addTemplatePath(JPATH_ADMINISTRATOR . '/components/com_j2store/views/order/tmpl/');
     $view->set('address_type', $address_type);
     $fieldClass = J2Store::getSelectableBase();
     $view->set('fieldClass', $fieldClass);
     $view->set('orderinfo', $processed);
     $view->set('item', $orderinfo);
     $view->setLayout('address');
     $view = $this->display();
 }
Beispiel #4
0
    protected function onAdd($tpl = null)
    {
        $app = JFactory::getApplication();
        $doc = JFactory::getDocument();
        $model = $this->getModel('Customfields');
        $this->item = $model->getTable();
        $this->item->field_table = 'address';
        $this->item->field_type = 'text';
        $selectableBase = J2Store::getSelectableBase();
        if (!empty($this->item->j2store_customfield_id)) {
            $field = $selectableBase->getField($this->item->j2store_customfield_id);
            $data = null;
            $allFields = $selectableBase->getFields('', $data, $field->field_table);
        } else {
            $field = $model->getTable();
            $field->field_table = 'address';
            $field->field_published = 1;
            $field->field_type = 'text';
            $field->field_backend = 1;
            $allFields = array();
        }
        $this->allFields = $allFields;
        $this->field = $field;
        //get the field type
        $fieldtype = J2Store::getSelectableFields();
        $this->assignRef('fieldtype', $fieldtype);
        $this->assignRef('fieldClass', $selectableBase);
        //country, zone type
        $zoneType = new j2storeZoneType();
        $this->assignRef('zoneType', $zoneType);
        $lists = array();
        $script = 'function addLine(){
		var myTable=window.document.getElementById("tablevalues");
		var newline = document.createElement(\'tr\');
		var column = document.createElement(\'td\');
		var column2 = document.createElement(\'td\');
		var column3 = document.createElement(\'td\');
		var input = document.createElement(\'input\');
		var input2 = document.createElement(\'input\');
		var input3 = document.createElement(\'select\');
		var option1 = document.createElement(\'option\');
		var option2 = document.createElement(\'option\');
		input.type = \'text\';
		input2.type = \'text\';
		option1.value= \'0\';
		option2.value= \'1\';
		input.name = \'field_values[title][]\';
		input2.name = \'field_values[value][]\';
		input3.name = \'field_values[disabled][]\';
		option1.text= \'' . JText::_('J2STORE_NO', true) . '\';
		option2.text= \'' . JText::_('J2STORE_YES', true) . '\';
		try { input3.add(option1, null); } catch(ex) { input3.add(option1); }
		try { input3.add(option2, null); } catch(ex) { input3.add(option2); }
		column.appendChild(input);
		column2.appendChild(input2);
		column3.appendChild(input3);
		newline.appendChild(column);
		newline.appendChild(column2);
		newline.appendChild(column3);
		myTable.appendChild(newline);
		}

		function deleteRow(divName,inputName,rowName){
			var d = document.getElementById(divName);
			var olddiv = document.getElementById(inputName);
			if(d && olddiv){
				d.removeChild(olddiv);
				document.getElementById(rowName).style.display="none";
			}
			return false;
		}

		function setVisible(value){
			if(value=="product" || value=="item" || value=="category"){
				document.getElementById(\'category_field\').style.display = "";
			}else{
				document.getElementById(\'category_field\').style.display = \'none\';
			}
		}';
        $doc->addScriptDeclaration($script);
        return true;
    }
Beispiel #5
0
 public function processCustomFields($type, $data)
 {
     $selectableBase = J2Store::getSelectableBase();
     $address = F0FTable::getAnInstance('Address', 'J2StoreTable');
     $orderinfo = F0FTable::getAnInstance('Orderinfo', 'J2StoreTable');
     $fields = $selectableBase->getFields($type, $address, 'address');
     if (is_array($data)) {
         $data = JArrayHelper::toObject($data);
     }
     $values = array();
     foreach ($fields as $fieldName => $oneExtraField) {
         if (isset($data->{$fieldName})) {
             if (!property_exists($orderinfo, $type . '_' . $fieldName) && !property_exists($orderinfo, 'user_' . $fieldName) && $fieldName != 'country_id' && $fieldName != 'zone_id' && $fieldName != 'option' && $fieldName != 'task' && $fieldName != 'view') {
                 $values[$fieldName]['label'] = $oneExtraField->field_name;
                 $values[$fieldName]['value'] = $data->{$fieldName};
             }
         }
     }
     $registry = new JRegistry();
     $registry->loadArray($values);
     $json = $registry->toString('JSON');
     return $json;
 }
Beispiel #6
0
 function shipping_payment_method_validate()
 {
     $app = JFactory::getApplication();
     $session = JFactory::getSession();
     $user = JFactory::getUser();
     $params = J2Store::config();
     $address_model = F0FModel::getTmpInstance('Addresses', 'J2StoreModel');
     $view = $this->getThisView();
     if ($model = $this->getThisModel()) {
         // Push the model into the view (as default)
         $view->setModel($model, true);
     }
     $order = F0FModel::getTmpInstance('Orders', 'J2StoreModel')->initOrder()->getOrder();
     $redirect_url = JRoute::_('index.php?option=com_j2store&view=checkout');
     //now get the values posted by the plugin, if any
     $values = $app->input->getArray($_POST);
     $json = array();
     //first validate custom fields
     $selectableBase = J2Store::getSelectableBase();
     $json = $selectableBase->validate($values, 'payment', 'address');
     if (!$json) {
         $json = J2Store::plugin()->eventWithArray('CheckoutValidateShippingPayment', array($values));
     }
     if (!$json) {
         //validate weather the customer is logged in
         $billing_address = '';
         if ($user->id && $session->has('billing_address_id', 'j2store')) {
             $billing_address = $address_model->getItem($session->get('billing_address_id', '', 'j2store'));
         } elseif ($session->has('guest', 'j2store')) {
             $guest = $session->get('guest', array(), 'j2store');
             $billing_address = $guest['billing'];
         }
         if (empty($billing_address)) {
             $json['redirect'] = $redirect_url;
         }
         //cart has products?
         if ($order->getItemCount() < 1) {
             $json['redirect'] = $redirect_url;
         }
         if (!$json) {
             $isShippingEnabled = $order->isShippingEnabled();
             //validate selection of shipping methods and set the shipping rates
             if ($params->get('show_shipping_address', 0) || $isShippingEnabled) {
                 //shipping is required.
                 if ($user->id && $session->has('shipping_address_id', 'j2store')) {
                     $shipping_address = $address_model->getItem($session->get('shipping_address_id', '', 'j2store'));
                 } elseif ($session->has('guest', 'j2store')) {
                     $guest = $session->get('guest', array(), 'j2store');
                     $shipping_address = $guest['shipping'];
                 }
                 //check if shipping address id is set in session. If not, redirect
                 if (empty($shipping_address)) {
                     $json['error']['shipping'] = JText::_('J2STORE_CHECKOUT_ERROR_SHIPPING_ADDRESS_NOT_FOUND');
                     $json['redirect'] = $redirect_url;
                 }
                 try {
                     $this->validateSelectShipping($values, $order);
                 } catch (Exception $e) {
                     $json['error']['shipping'] = $e->getMessage();
                 }
                 if (!$json) {
                     $shipping_values = array();
                     $shipping_values['shipping_price'] = isset($values['shipping_price']) ? $values['shipping_price'] : 0;
                     $shipping_values['shipping_extra'] = isset($values['shipping_extra']) ? $values['shipping_extra'] : 0;
                     $shipping_values['shipping_code'] = isset($values['shipping_code']) ? $values['shipping_code'] : '';
                     $shipping_values['shipping_name'] = isset($values['shipping_name']) ? $values['shipping_name'] : '';
                     $shipping_values['shipping_tax'] = isset($values['shipping_tax']) ? $values['shipping_tax'] : 0;
                     $shipping_values['shipping_plugin'] = isset($values['shipping_plugin']) ? $values['shipping_plugin'] : '';
                     //set the shipping method to session
                     $session->set('shipping_method', $shipping_values['shipping_plugin'], 'j2store');
                     $session->set('shipping_values', $shipping_values, 'j2store');
                 }
             }
         }
         if (!$json) {
             // is shipping mandatory
             if ($params->get('shipping_mandatory', 0)) {
                 //yes it is. Check if session has shipping values
                 $shipping_values = $session->get('shipping_values', array(), 'j2store');
                 $shipping_method = $session->get('shipping_method', null, 'j2store');
                 if (count($shipping_values) < 1 || empty($shipping_method)) {
                     //now value selected
                     $json['error']['shipping'] = JText::_('J2STORE_CHECKOUT_SHIPPING_METHOD_SELECTION_MANDATORY');
                 }
             }
         }
         //validate selection of payment methods
         if (!$json) {
             //re initialise the order
             $order = F0FModel::getTmpInstance('Orders', 'J2StoreModel')->initOrder()->getOrder();
             $showPayment = true;
             if ((double) $order->order_total == (double) '0.00') {
                 $showPayment = false;
             }
             if ($showPayment) {
                 $payment_plugin = $app->input->getString('payment_plugin');
                 if (!isset($payment_plugin)) {
                     $json['error']['warning'] = JText::_('J2STORE_CHECKOUT_ERROR_PAYMENT_METHOD');
                 } elseif (!isset($payment_plugin)) {
                     $json['error']['warning'] = JText::_('J2STORE_CHECKOUT_ERROR_PAYMENT_METHOD');
                 }
                 //validate the selected payment
                 try {
                     $this->validateSelectPayment($payment_plugin, $values);
                 } catch (Exception $e) {
                     $json['error']['warning'] = $e->getMessage();
                 }
             }
             if ($params->get('show_terms', 0) && $params->get('terms_display_type', 'link') == 'checkbox') {
                 $tos_check = $app->input->get('tos_check');
                 if (!isset($tos_check)) {
                     $json['error']['tos_check'] = JText::_('J2STORE_CHECKOUT_ERROR_AGREE_TERMS');
                 }
             }
             if (!$json) {
                 $payment_plugin = $app->input->getString('payment_plugin');
                 //set the payment plugin form values in the session as well.
                 $session->set('payment_values', $values, 'j2store');
                 $session->set('payment_method', $payment_plugin, 'j2store');
                 $session->set('customer_note', strip_tags($app->input->getString('customer_note')), 'j2store');
             }
         }
     }
     echo json_encode($json);
     $app->close();
 }
Beispiel #7
0
 /**
  * Method to save Address
  * edit / new address will be saved
  * @param post data
  * @return result
  */
 function saveAddress()
 {
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $values = $app->input->getArray($_POST);
     $values['id'] = $values['address_id'];
     $values['user_id'] = isset($values['user_id']) && $values['user_id'] ? $values['user_id'] : $user->id;
     $values['email'] = $user->email;
     $model = $this->getModel('myprofile');
     $selectableBase = J2Store::getSelectableBase();
     $json = $selectableBase->validate($values, $values['type'], 'address');
     if (empty($json['error'])) {
         $table = F0FTable::getAnInstance('Address', 'J2StoreTable');
         $values['user_id'] = isset($values['user_id']) ? $values['user_id'] : $user->id;
         $values['email'] = isset($values['user_id']) ? $values['email'] : $user->email;
         if ($table->save($values)) {
             $json['success']['url'] = JRoute::_('index.php?option=com_j2store&view=myprofile&task=editAddress&layout=address&tmpl=component&address_id=' . $table->j2store_address_id);
             $json['success']['msg'] = JText::_('J2STORE_' . strtoupper($table->type) . '_ADDRESS_SAVED_SUCCESSFULLY');
             $json['success']['msgType'] = 'success';
         } else {
             $json['error']['msgType'] = 'Warning';
         }
     }
     echo json_encode($json);
     $app->close();
 }
Beispiel #8
0
 function formatCustomFields($type, $data_field, &$order)
 {
     $address = F0FTable::getAnInstance('Address', 'J2StoreTable');
     $fields = J2Store::getSelectableBase()->getFields($type, $address, 'address', '', true);
     foreach ($fields as $field) {
         $order[$type . '_' . JString::strtolower($field->field_namekey)] = '';
     }
     $registry = new JRegistry();
     $registry->loadString(stripslashes($data_field), 'JSON');
     $custom_fields = $registry->toObject();
     $row = F0FTable::getAnInstance('Orderinfo', 'J2StoreTable');
     if (isset($custom_fields) && count($custom_fields)) {
         foreach ($custom_fields as $namekey => $field) {
             if (!property_exists($row, $type . '_' . strtolower($namekey)) && !property_exists($row, 'user_' . $namekey) && $namekey != 'country_id' && $namekey != 'zone_id' && $namekey != 'option' && $namekey != 'task' && $namekey != 'view' && $namekey != 'email') {
                 if (is_object($field)) {
                     $string = '';
                     if (is_array($field->value)) {
                         $k = count($field->value);
                         $i = 1;
                         foreach ($field->value as $value) {
                             $string .= JText::_($value);
                             if ($i != $k) {
                                 $string .= '|';
                             }
                             $i++;
                         }
                     } elseif (is_object($field->value)) {
                         //convert the object into an array
                         $obj_array = JArrayHelper::fromObject($field->value);
                         $k = count($obj_array);
                         $i = 1;
                         foreach ($obj_array as $value) {
                             $string .= JText::_($value);
                             if ($i != $k) {
                                 $string .= '|';
                             }
                             $i++;
                         }
                     } elseif (J2Store::utilities()->isJson(stripslashes($field->value))) {
                         $json_values = json_decode(stripslashes($field->value));
                         if (is_array($json_values)) {
                             $k = count($json_values);
                             $i = 1;
                             foreach ($json_values as $value) {
                                 $string .= JText::_($value);
                                 if ($i != $k) {
                                     $string .= '|';
                                 }
                                 $i++;
                             }
                         } else {
                             $string .= JText::_($field->value);
                         }
                     } else {
                         $string = JText::_($field->value);
                     }
                     if (!empty($string)) {
                         $order[$type . '_' . JString::strtolower($namekey)] = $string;
                     }
                 }
             }
         }
     }
 }
Beispiel #9
0
?>
		<tr>
			<td><?php 
echo JText::_('J2STORE_ORDER_TRANSACTION_LOG');
?>
</td>
			<td>  <!-- Button to trigger modal -->
   				 <a href="#myTransaction" role="button" class="btn btn-success" data-toggle="modal"><?php 
echo JText::_('J2STORE_VIEW');
?>
</a>
  			</td>
		</tr>
		<tr>			
			<td colspan="2"><?php 
echo J2Store::getSelectableBase()->getFormatedCustomFields($this->orderinfo, 'customfields', 'payment');
?>
</td>			
		</tr>
		
</table>
</div>

<!-- Transaction log modal window -->
  <div id="myTransaction" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myTransactionLabel" aria-hidden="true">
   <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    	<h3 id="myTransactionLabel">
			<?php 
echo JText::_('J2STORE_TRANSACTION_LOG_HEADER');
?>