Source of file CheckoutStepAddressLocationFallback.php
Size: 2,438 Bytes - Last Modified: 2021-12-23T10:25:07+00:00
/var/www/docs.ssmods.com/process/src/src/Checkout/CheckoutStepAddressLocationFallback.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 | <?php namespace SilverShop\Geocoding\Checkout; use SilverShop\Checkout\Step\CheckoutStep; use SilverShop\Model\Address; use SilverStripe\Form\FieldList; use SilverStripe\Form\FormAction; use SilverStripe\Form\LiteralField; use SilverStripe\Form\Form; use BetterBrief\GoogleMapField; class CheckoutStepAddressLocationFallback extends CheckoutStep { private static $allowed_actions = [ "addresslocation", "AddressLocationForm" ]; public function addresslocation() { $shippingaddress = $this->getShippingAddress(); if ((int)$shippingaddress->Latitude && (int)$shippingaddress->Longitude) { return $this->owner->redirect($this->NextStepLink()); } $form = $this->AddressLocationForm(); return array( 'OrderForm' => $form ); } public function AddressLocationForm() { $shippingaddress = $this->getShippingAddress(); $config = array( 'fieldNames' => array( 'lat' => 'Latitude', 'lng' => 'Longitude' ), 'coords' => array( Address::config()->mapdefaults['latitude'], Address::config()->mapdefaults['longitude'] ), 'map' => array( 'zoom' => Address::config()->mapdefaults['zoom'] ), 'showSearchBox' => false ); $fields = new FieldList( LiteralField::create("locationneededmessage", "<p class=\"message warning\">We could not automatically determine your shipping location. Please find and click the exact location on the map:</p>"), GoogleMapField::create($shippingaddress, "Location", $config) ->setDescription("Please click the exact location of your address") ); $actions = new FieldList( new FormAction("setAddressLocation", "Continue") ); $form = new Form($this->owner, "AddressLocationForm", $fields, $actions); return $form; } public function setAddressLocation($data, $form) { $shippingaddress = $this->getShippingAddress(); $form->saveInto($shippingaddress); $shippingaddress->write(); return $this->owner->redirect($this->NextStepLink()); } protected function getShippingAddress() { return ShoppingCart::singleton()->current()->getShippingAddress(); } } |