public function postProcess(Axis_Sales_Model_Order_Row $order) { $view = Axis::app()->getBootstrap()->getResource('layout')->getView(); $delivery = $order->getDelivery(); $formFields = array('business' => $this->_config->email, 'return' => $view->href('paymentpaypal/standard/success'), 'cancel_return' => $view->href('paymentpaypal/standard/cancel'), 'notify_url' => $view->href('paymentpaypal/standard/ipn'), 'invoice' => $order->id, 'address_override' => 1, 'first_name' => $delivery->getFirstname(), 'last_name' => $delivery->getLastname(), 'address1' => $delivery->getStreetAddress(), 'address2' => $delivery->getSuburb(), 'city' => $delivery->getCity(), 'state' => $delivery->getZone()->getCode(), 'country' => $delivery->getCountry()->getIsoCode2(), 'zip' => $delivery->getPostcode()); if ($this->_config->logo) { $formFields['cpp_header_image'] = $this->_config->logo; } if ($this->_config->paymentAction) { $formFields['paymentaction'] = strtolower($this->_config->paymentAction); } $transaciton_type = $this->_config->transactionType; /* O=aggregate cart amount to paypal I=individual items to paypal */ if ($transaciton_type == 'Aggregate Cart') { $businessName = $this->_config->name; $formFields = array_merge($formFields, array('cmd' => '_ext-enter', 'redirect_cmd' => '_xclick', 'item_name' => $businessName ? $businessName : Axis::config()->core->store->name, 'currency_code' => $this->getBaseCurrencyCode(), 'amount' => sprintf('%.2f', $this->getAmountInBaseCurrency($order->getSubTotal(), $order->currency)))); $tax = $order->getTax(); $shippingTax = $order->getShippingTax(); $tax = sprintf('%.2f', $tax + $shippingTax); if ($tax > 0) { $formFields['tax'] = $tax; } } else { $formFields = array_merge($formFields, array('cmd' => '_cart', 'upload' => '1')); $products = $order->getProducts(); if ($products) { $i = 1; foreach ($products as $product) { $formFields = array_merge($formFields, array('item_name_' . $i => $product['name'], 'item_number_' . $i => $product['sku'], 'quantity_' . $i => intval($product['quantity']), 'amount_' . $i => sprintf('%.2f', $product['final_price']))); if ($product['tax'] > 0) { $formFields = array_merge($formFields, array('tax_' . $i => sprintf('%.2f', $product['tax']))); } $i++; } } } $totals = $order->getTotals(); $shipping = sprintf('%.2f', $totals['shipping']['value']); if ($shipping > 0) { if ($transaciton_type == 'Aggregate Cart') { $formFields['shipping'] = $shipping; } else { $shippingTax = $totals['shipping_tax']['value']; $formFields = array_merge($formFields, array('item_name_' . $i => $order->shipping_method, 'quantity_' . $i => 1, 'amount_' . $i => $shipping, 'tax_' . $i => sprintf('%.2f', $shippingTax))); $i++; } } $sReq = ''; $rArr = array(); foreach ($formFields as $k => $v) { /* replacing & char with and. otherwise it will break the post */ $value = str_replace('&', 'and', $v); $rArr[$k] = $value; $sReq .= '&' . $k . '=' . $value; } $this->getStorage()->formFields = $rArr; return array('redirect' => $view->href('paymentpaypal/standard/submit')); }
/** * "processing" => "ship" * * @param Axis_Sales_Model_Order_Row $order * @return bool */ public function ship(Axis_Sales_Model_Order_Row $order) { $modelStock = Axis::single('catalog/product_stock'); $products = $order->getProducts(); // check the availability of all products foreach ($products as $product) { if (!$product['backorder']) { continue; } if (!$modelStock->find($product['product_id'])->current()->canShipping($product['quantity'], $product['variation_id'])) { Axis::message()->addError(Axis::translate('sales')->__("Product can't be shipped. Name: %s, Sku: %s", $product['name'], $product['sku'])); return false; } } // update stock data for backordered products // normal products update the stock in pending status foreach ($products as $product) { if (!$product['backorder']) { continue; } $stockRow = $modelStock->find($product['product_id'])->current(); $quantity = $stockRow->getQuantity($product['variation_id']); $stockRow->setQuantity($quantity - $product['quantity'], $product['variation_id']); } return true; }