Exemplo n.º 1
0
 /**
  *
  * @return array
  */
 protected function _loadCollection()
 {
     $methods = array();
     foreach (Axis_Shipping::getMethods() as $methodCode => $method) {
         $methods[$methodCode] = $method->getTitle();
     }
     return $methods;
 }
Exemplo n.º 2
0
 /**
  *
  * @static
  * @return array
  */
 public static function collect()
 {
     $ret = array();
     foreach (Axis_Shipping::getMethods() as $methodCode => $method) {
         $ret[$methodCode] = $method->getTitle();
     }
     return $ret;
 }
Exemplo n.º 3
0
 public function listAction()
 {
     function _calculateShippingTax($price, Axis_Method_Shipping_Model_Abstract $shipping, array $params)
     {
         $customerGroupId = $params['customer_group_id'];
         if (!($taxClassId = $shipping->config()->taxClass)) {
             if (!($taxClassId = Axis::config()->tax->shipping->taxClass)) {
                 return 0;
             }
         }
         if (!($taxBasis = $shipping->config()->taxBasis)) {
             if (!($taxBasis = Axis::config()->tax->shipping->taxBasis)) {
                 return 0;
             }
         }
         if ('billing' === $taxBasis) {
             $countryId = $params['billing_country_id'];
             $zoneId = $params['billing_zone_id'];
         } else {
             $countryId = $params['delivery_country_id'];
             $zoneId = $params['delivery_zone_id'];
         }
         if (empty($zoneId)) {
             $zoneId = null;
         }
         $geozoneIds = Axis::single('location/geozone')->getIds($countryId, $zoneId);
         if (empty($geozoneIds)) {
             return 0;
         }
         return Axis::single('tax/rate')->calculateByPrice($price, $taxClassId, $geozoneIds, $customerGroupId);
     }
     $this->_helper->layout->disableLayout();
     $params = $this->_getAllParams();
     $countryId = (int) $this->_getParam('delivery_country_id', 0);
     $zoneId = (int) $this->_getParam('delivery_zone_id', 0);
     $quantity = (double) $this->_getParam('quantity', 0);
     $weight = (double) $this->_getParam('weight', 0);
     $subtotal = (double) $this->_getParam('subtotal', 0);
     $paymentMethodCode = $this->_getParam('payment_method_code', null);
     if (empty($paymentMethodCode)) {
         $paymentMethodCode = null;
     }
     $postcode = $this->_getParam('postcode', null);
     $request = array('boxes' => 1, 'qty' => $quantity, 'weight' => $weight, 'price' => $subtotal, 'payment_method_code' => $paymentMethodCode, 'postcode' => $postcode);
     $request['country'] = Axis::model('location/country')->find($countryId)->current()->toArray();
     $request['zone'] = Axis::model('location/zone')->find($zoneId)->current()->toArray();
     $allowedMethods = Axis_Shipping::getAllowedMethods($request);
     $data = array();
     foreach ($allowedMethods['methods'] as $methodCode => $types) {
         $shipping = Axis_Shipping::getMethod($methodCode);
         $title = $shipping->getTitle();
         foreach ($types as $type) {
             $data[] = array('code' => $type['id'], 'title' => $type['title'], 'name' => $title . ' ' . $type['title'] . ' ' . $type['price'], 'price' => $type['price'], 'tax' => _calculateShippingTax($type['price'], $shipping, $params));
         }
     }
     return $this->_helper->json->setData($data)->sendSuccess();
 }
Exemplo n.º 4
0
 /**
  * Return additional paymet form
  * @return string
  * @param object|string $payment
  * @param string $template example: 'view', 'form', 'process' etc
  */
 public function shippingForm($shippingCode, $template, $area = null)
 {
     if ($shippingCode instanceof Axis_Method_Shipping_Model_Abstract) {
         $this->view->shipping = $shippingCode;
         $shippingCode = $this->view->shipping->getCode();
     } else {
         $this->view->shipping = Axis_Shipping::getMethod($shippingCode);
     }
     if (null === $area) {
         $area = $this->view->area;
     }
     $shortPath = 'shipping' . str_replace('_', '/', strtolower($shippingCode)) . '/' . $template . '.phtml';
     $fallbackList = array_unique(array($this->view->templateName, 'fallback', 'default'));
     foreach ($fallbackList as $fallback) {
         $templatePath = $this->view->path . '/app/design/' . $area . '/' . $fallback . '/templates';
         if (is_readable($templatePath . '/' . $shortPath)) {
             return $this->view->render($shortPath);
         }
     }
     return '';
 }
Exemplo n.º 5
0
 /**
  *
  * @param array $request
  * @return bool
  */
 public function isAllowed($request)
 {
     // Zend_Debug::dump($request);die;
     if (isset($this->_config->minOrderTotal) && !empty($this->_config->minOrderTotal) && $request['price'] < $this->_config->minOrderTotal) {
         return false;
     }
     if (isset($this->_config->maxOrderTotal) && !empty($this->_config->maxOrderTotal) && $request['price'] > $this->_config->maxOrderTotal) {
         return false;
     }
     if (null !== $request['shipping_method_code']) {
         $shipping = Axis_Shipping::getMethod($request['shipping_method_code']);
         // get list of disallowed payment methods, and compare with requested payment method
         $disallowedPaymentMethods = $shipping->config()->payments->toArray();
         if (in_array($this->getCode(), $disallowedPaymentMethods)) {
             return false;
         }
         // get list of disallowed shippings and compare with selected shipping method
         $disallowedShippingMethods = $this->_config->shippings->toArray();
         if (in_array($shipping->getCode(false), $disallowedShippingMethods)) {
             return false;
         }
     }
     if (!isset($this->_config->geozone) || !intval($this->_config->geozone)) {
         return true;
     }
     if (empty($request['country']['id'])) {
         return true;
     }
     $zoneId = null;
     if (isset($request['zone']['id'])) {
         $zoneId = $request['zone']['id'];
     }
     return Axis::single('location/geozone_zone')->inGeozone($this->_config->geozone, $request['country']['id'], $zoneId);
 }
Exemplo n.º 6
0
 public function setShippingMethodAction()
 {
     $methodCode = $this->_getParam('method');
     // methodCode can include method type also - Pickup_Standard|Ups_Standard_WXS
     list($moduleName, $methodName) = explode('_', $methodCode);
     if (!in_array($moduleName . '_' . $methodName, Axis_Shipping::getMethodNames())) {
         Axis::message()->addError(Axis::translate('checkout')->__("'%s' method not found among installed modules", $methodCode));
         $this->_redirect('/paymentpaypal/express/shipping-method');
     }
     $method = Axis_Shipping::getMethod($methodCode);
     if (!$method instanceof Axis_Method_Shipping_Model_Abstract || !$method->isEnabled() || !$method->isAllowed($this->_getCheckout()->getShippingRequest())) {
         Axis::message()->addError(Axis::translate('checkout')->__('Selected shipping method in not allowed'));
         $this->_redirect('/paymentpaypal/express/shipping-method');
     }
     $this->_getCheckout()->setShippingMethod($methodCode);
     $this->_redirect('/paymentpaypal/express/confirmation');
 }
Exemplo n.º 7
0
 /**
  * Updates shopping cart totals, available shipping and payment methods
  * Unset shipping and payment methods if needed
  */
 public function updateShoppingCartAction()
 {
     $this->_helper->layout->disableLayout();
     $checkout = $this->_getCheckout();
     $cart = Axis::single('checkout/cart');
     foreach ($this->_getParam('quantity') as $itemId => $quantity) {
         $cart->updateItem($itemId, $quantity);
     }
     $products = $checkout->getCart()->getProducts();
     if (!count($products)) {
         return $this->_helper->json->sendSuccess(array('redirect' => $this->view->href('checkout/cart', true)));
     }
     $shippingMethods = Axis_Shipping::getAllowedMethods($checkout->getShippingRequest());
     $paymentMethods = Axis_Payment::getAllowedMethods($checkout->getPaymentRequest());
     $this->view->checkout = array('shipping_methods' => $shippingMethods, 'payment_methods' => $paymentMethods, 'products' => $products, 'totals' => $checkout->getTotal()->getCollects(), 'total' => $checkout->getTotal()->getTotal());
     return $this->_helper->json->sendSuccess(array('sections' => $this->_renderSections(array('shopping-cart', 'shipping-method', 'payment-method'))));
 }
Exemplo n.º 8
0
 /**
  * Apply Shipping method if possible
  *
  * @param mixed $data
  * @return void
  * @throws Axis_Exception
  */
 public function setShippingMethod($data)
 {
     if (!is_array($data)) {
         $data = array('method' => $data);
     }
     if (empty($data['method'])) {
         return $this->setShippingMethodCode(null);
     }
     // methodCode can include method type also - Pickup_Standard|Ups_Standard_WXS
     list($moduleName, $methodName) = explode('_', $data['method']);
     if (!in_array($moduleName . '_' . $methodName, Axis_Shipping::getMethodNames())) {
         throw new Axis_Exception(Axis::translate('checkout')->__("'%s' method not found among installed modules", $data['method']));
     }
     $method = Axis_Shipping::getMethod($data['method']);
     if (!$method instanceof Axis_Method_Shipping_Model_Abstract || !$method->isAllowed($this->getShippingRequest())) {
         throw new Axis_Exception(Axis::translate('checkout')->__('Selected shipping method is not allowed'));
     }
     $this->_shipping = $method;
     $this->setShippingMethodCode($data['method']);
 }