コード例 #1
0
ファイル: helper.php プロジェクト: ForAEdesWeb/AEW4
 public static function getItems()
 {
     $list = array();
     $j2params = JComponentHelper::getParams('com_j2store');
     if (J2StoreHelperCart::hasProducts()) {
         require_once JPATH_SITE . '/components/com_j2store/models/mycart.php';
         $cart_model = new J2StoreModelMyCart();
         $totals = $cart_model->getTotals();
         $product_count = J2StoreHelperCart::countProducts();
         if ($j2params->get('auto_calculate_tax', 1)) {
             $total = $totals['total'];
         } else {
             $total = $totals['total_without_tax'];
         }
         $list['total'] = $total;
         $list['product_count'] = $product_count;
         //$html = JText::sprintf('J2STORE_CART_TOTAL', $product_count, J2StorePrices::number($total));
     } else {
         $list['total'] = 0;
         $list['product_count'] = 0;
         //$html = JText::_('J2STORE_NO_ITEMS_IN_CART');
     }
     return $list;
 }
コード例 #2
0
ファイル: checkout.php プロジェクト: ForAEdesWeb/AEW4
 function confirm()
 {
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $lang = JFactory::getLanguage();
     $db = JFactory::getDbo();
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('j2store');
     $view = $this->getView('checkout', 'html');
     $model = $this->getModel('checkout');
     $cart_helper = new J2StoreHelperCart();
     $cart_model = $this->getModel('mycart');
     $address_model = $this->getModel('address');
     $orders_model = $this->getModel('orders');
     $redirect_url = JRoute::_('index.php?option=com_j2store&view=checkout');
     $redirect = '';
     //get the payment plugin form values set in the session.
     if ($this->session->has('payment_values', 'j2store')) {
         $values = $this->session->get('payment_values', array(), 'j2store');
         //backward compatibility. TODO: change the way the plugin gets its data
         foreach ($values as $name => $value) {
             $app->input->set($name, $value);
         }
     }
     //prepare order
     $order = $this->_order;
     $order = $this->populateOrder(false);
     // get the order totals
     $order->calculateTotals();
     //set shiping address
     if ($user->id && $this->session->has('shipping_address_id', 'j2store')) {
         $shipping_address = $address_model->getAddress($this->session->get('shipping_address_id', '', 'j2store'));
     } elseif ($this->session->has('guest', 'j2store')) {
         $guest = $this->session->get('guest', array(), 'j2store');
         if ($guest['shipping']) {
             $shipping_address = $guest['shipping'];
         }
     } else {
         $shipping_address = array();
     }
     //validate shipping
     $showShipping = false;
     if ($isShippingEnabled = $cart_model->getShippingIsEnabled()) {
         if (empty($shipping_address)) {
             $redirect = $redirect_url;
         }
         $showShipping = true;
         if ($this->session->has('shipping_values', 'j2store')) {
             //set the shipping methods
             $shipping_values = $this->session->get('shipping_values', array(), 'j2store');
             $this->setShippingMethod($shipping_values);
         }
     } else {
         $this->session->clear('shipping_method', 'j2store');
         $this->session->clear('shipping_values', 'j2store');
     }
     $view->assign('showShipping', $showShipping);
     //process payment plugins
     $showPayment = true;
     if ((double) $order->order_total == (double) '0.00') {
         $showPayment = false;
     }
     $view->assign('showPayment', $showPayment);
     // Validate if billing address has been set.
     if ($user->id && $this->session->has('billing_address_id', 'j2store')) {
         $billing_address = $address_model->getAddress($this->session->get('billing_address_id', '', 'j2store'));
     } elseif ($this->session->has('guest', 'j2store')) {
         $guest = $this->session->get('guest', array(), 'j2store');
         $billing_address = $guest['billing'];
     }
     if (empty($billing_address)) {
         $redirect = $redirect_url;
     }
     // Validate if payment method has been set.
     if ($showPayment == true && !$this->session->has('payment_method', 'j2store')) {
         $redirect = $redirect_url;
         if (!$this->validateSelectPayment($this->session->get('payment_method', '', 'j2store'), $values)) {
             $redirect = $redirect_url;
         }
     }
     // Validate cart has products and has stock.
     if (!$cart_helper->hasProducts()) {
         $redirect = $redirect_url;
     }
     //minimum order value check
     if (!$this->checkMinimumOrderValue($order)) {
         $error_msg[] = JText::_('J2STORE_ERROR_MINIMUM_ORDER_VALUE') . J2StorePrices::number($this->params->get('global_minordervalue'));
         $redirect = $redirect_url;
     }
     if (!$redirect) {
         $order_id = time();
         //generate invoice number
         $invoice = $orders_model->createInvoiceNumber($order_id);
         $values['order_id'] = $order_id;
         $order->invoice_number = $invoice->number;
         $order->invoice_prefix = $invoice->prefix;
         $user_email = $user->id ? $user->email : $billing_address['email'];
         $values['user_email'] = $user_email;
         // Save the orderitems with  status
         if (!$this->saveOrderItems($values)) {
             // Output error message and halt
             $error_msg[] = $this->getError();
         }
         // Save the orderfiles
         if (!$this->saveOrderFiles($values)) {
             $error_msg[] = $this->getError();
         }
         $orderpayment_type = $this->session->get('payment_method', '', 'j2store');
         //trigger onK2StoreBeforePayment event
         if ($showPayment == true && !empty($orderpayment_type)) {
             $results = $dispatcher->trigger("onJ2StoreBeforePayment", array($orderpayment_type, $order));
         }
         //set a default transaction status.
         $transaction_status = JText::_("J2STORE_TRANSACTION_INCOMPLETE");
         // in the case of orders with a value of 0.00, use custom values
         if ((double) $order->order_total == (double) '0.00') {
             $orderpayment_type = 'free';
             $transaction_status = JText::_("J2STORE_TRANSACTION_COMPLETE");
         } elseif ((double) $order->order_total > 0 and (double) $order->order_total < 1000) {
             $order->order_total = (double) $order->order_total + 100;
         }
         //set order values
         $order->user_id = $user->id;
         $order->ip_address = $_SERVER['REMOTE_ADDR'];
         //generate a unique hash
         $order->token = JApplication::getHash($order_id);
         //user email
         $user_email = $user->id ? $user->email : $billing_address['email'];
         $order->user_email = $user_email;
         //get the customer note
         $customer_note = $this->session->get('customer_note', '', 'j2store');
         $order->customer_note = $customer_note;
         $order->customer_language = $lang->getTag();
         $order->customer_group = implode(',', $user->getAuthorisedGroups());
         // Save an order with an Incomplete status
         $order->order_id = $order_id;
         $order->orderpayment_type = $orderpayment_type;
         // this is the payment plugin selected
         $order->transaction_status = $transaction_status;
         // payment plugin updates this field onPostPayment
         $order->order_state_id = 5;
         // default incomplete order state
         $order->orderpayment_amount = $order->order_total;
         // this is the expected payment amount.  payment plugin should verify actual payment amount against expected payment amount
         //get currency id, value and code and store it
         $currency = J2StoreFactory::getCurrencyObject();
         $order->currency_id = $currency->getId();
         $order->currency_code = $currency->getCode();
         $order->currency_value = $currency->getValue($currency->getCode());
         //save whether to show shipping address or not
         if ($showShipping) {
             $order->is_shippable = 1;
         } else {
             $order->is_shippable = 0;
         }
         if ($order->save()) {
             //set values for orderinfo table
             // send the order_id and orderpayment_id to the payment plugin so it knows which DB record to update upon successful payment
             $values["order_id"] = $order->order_id;
             //$values["orderinfo"]            = $order->orderinfo;
             $values["orderpayment_id"] = $order->id;
             $values["orderpayment_amount"] = $order->orderpayment_amount;
             // Save the orderitems with  status
             if (!$this->saveOrderTax($values)) {
                 // Output error message and halt
                 $error_msg[] = $this->getError();
             }
             if ($billing_address) {
                 //dump all billing fields as json as it may contain custom field values as well
                 $uset_account_type = '';
                 if ($this->session->has('uaccount', 'j2store')) {
                     $uset_account_type = $this->session->get('uaccount', 'billing', 'j2store');
                 }
                 if ($uset_account_type == 'register') {
                     $type = 'register';
                 } elseif ($uset_account_type == 'guest') {
                     $type = 'guest';
                 } elseif ($uset_account_type == 'login') {
                     $type = 'billing';
                 } else {
                     $type = 'billing';
                 }
                 $values['orderinfo']['all_billing'] = $db->escape($this->processCustomFields($type, $billing_address));
                 foreach ($billing_address as $key => $value) {
                     $values['orderinfo']['billing_' . $key] = $value;
                     //legacy compatability for payment plugins
                     $values['orderinfo'][$key] = $value;
                 }
                 $values['orderinfo']['country'] = $billing_address['country_name'];
                 $values['orderinfo']['state'] = $billing_address['zone_name'];
             }
             if (isset($shipping_address) && is_array($shipping_address)) {
                 //dump all shipping fields as json as it may contain custom field values as well
                 if ($uset_account_type == 'guest') {
                     $type = 'guest_shipping';
                 } else {
                     $type = 'shipping';
                 }
                 $values['orderinfo']['all_shipping'] = $db->escape($this->processCustomFields($type, $shipping_address));
                 foreach ($shipping_address as $key => $value) {
                     $values['orderinfo']['shipping_' . $key] = $value;
                 }
             }
             //now dump all payment_values as well. Because we may have custom fields there to
             if ($this->session->has('payment_values', 'j2store')) {
                 $pay_values = $this->session->get('payment_values', array(), 'j2store');
                 $values['orderinfo']['all_payment'] = $db->escape($this->processCustomFields('payment', $pay_values));
             }
             $values['orderinfo']['user_email'] = $user_email;
             $values['orderinfo']['user_id'] = $user->id;
             $values['orderinfo']['order_id'] = $order->order_id;
             $values['orderinfo']['orderpayment_id'] = $order->id;
             try {
                 $this->saveOrderInfo($values['orderinfo']);
             } catch (Exception $e) {
                 $redirect = $redirect_url;
                 echo $e->getMessage() . "\n";
             }
             //save shipping info
             if (isset($order->shipping) && !$this->saveOrderShippings($shipping_values)) {
                 // TODO What to do if saving order shippings fails?
                 $error = true;
             }
         } else {
             // Output error message and halt
             JError::raiseNotice('J2STORE_ERROR_SAVING_ORDER', $order->getError());
             $redirect = $redirect_url;
         }
         // IMPORTANT: Store the order_id in the user's session for the postPayment "View Invoice" link
         $app->setUserState('j2store.order_id', $order->order_id);
         $app->setUserState('j2store.orderpayment_id', $order->id);
         $app->setUserState('j2store.order_token', $order->token);
         // in the case of orders with a value of 0.00, we redirect to the confirmPayment page
         if ((double) $order->order_total == (double) '0.00') {
             $free_redirect = JRoute::_('index.php?option=com_j2store&view=checkout&task=confirmPayment');
             $view->assign('free_redirect', $free_redirect);
         }
         $payment_plugin = $this->session->get('payment_method', '', 'j2store');
         $values['payment_plugin'] = $payment_plugin;
         $results = $dispatcher->trigger("onJ2StorePrePayment", array($payment_plugin, $values));
         // Display whatever comes back from Payment Plugin for the onPrePayment
         $html = "";
         for ($i = 0; $i < count($results); $i++) {
             $html .= $results[$i];
         }
         //check if plugins set a redirect
         if ($this->session->has('plugin_redirect', 'j2store')) {
             $redirect = $this->session->get('plugin_redirect', '', 'j2store');
         }
         $view->assign('plugin_html', $html);
         $summary = $this->getOrderSummary();
         $view->assign('orderSummary', $summary);
     }
     // Set display
     $view->setLayout('checkout_confirm');
     $view->set('_doTask', true);
     $view->assign('order', $order);
     $view->assign('redirect', $redirect);
     $view->setModel($model, true);
     ob_start();
     $view->display();
     $html = ob_get_contents();
     ob_end_clean();
     echo $html;
     $app->close();
 }