/** * Get shipping estimates * @return DataList */ public function getShippingEstimates() { //$package = $this->order->createShippingPackage(); $address = $this->owner->getShippingAddress(); $estimator = new ShippingEstimator($this->owner, $address); $estimates = $estimator->getEstimates(); return $estimates; }
function testGetEstimates() { $address = new Address(); $package = new ShippingPackage(2); $estimator = new ShippingEstimator($package, $address); $options = $estimator->getShippingMethods(); $this->assertNotNull($options, "options found"); $estimates = $estimator->getEstimates(); $this->assertNotNull($estimates, "estimates found"); }
function submit($data, $form) { if ($order = ShoppingCart::singleton()->current()) { $package = $order->createShippingPackage(); $address = new Address(); $form->saveInto($address); $estimator = new ShippingEstimator($package, $address); $estimates = $estimator->getEstimates(); Session::set("ShippingEstimates", $estimates); if (Director::is_ajax()) { return json_encode($estimates->toArray()); //TODO: replace with an AJAXResponse class that can output to different formats } } Director::redirectBack(); }
function submit($data, $form) { if ($order = ShoppingCart::singleton()->current()) { $estimator = new ShippingEstimator($order, new Address(Convert::raw2sql($data))); $estimates = $estimator->getEstimates(); if (!$estimates->exists()) { $form->sessionMessage("No estimates could be found for that location.", "warning"); } Session::set("ShippingEstimates", $estimates); if (Director::is_ajax()) { //TODO: replace with an AJAXResponse class that can output to different formats return json_encode($estimates->toArray()); } } $this->controller->redirectBack(); }
function submit($data, $form) { if ($country = SiteConfig::current_site_config()->getSingleCountry()) { // Add Country if missing due to ReadonlyField in form $data['Country'] = $country; } if ($order = ShoppingCart::singleton()->current()) { $estimator = new ShippingEstimator($order, new Address(Convert::raw2sql($data))); $estimates = $estimator->getEstimates(); if (!$estimates->exists()) { $form->sessionMessage(_t('ShippingEstimateForm.FormActionWarningMessage', 'No estimates could be found for that location.'), _t('ShippingEstimateForm.FormActionWarningCode', "warning")); } Session::set("ShippingEstimates", $estimates); if (Director::is_ajax()) { //TODO: replace with an AJAXResponse class that can output to different formats return json_encode($estimates->toNestedArray()); } } $this->controller->redirectBack(); }