public function requireDefaultRecords() { if (!Country_Shipping::get()->filter('Code', 'NZ')->count()) { $country = new Country_Shipping(['Code' => 'NZ', 'Title' => 'New Zealand']); $country->write(); DB::alteration_message("Added 'New Zealand' to shipping countries", "changed"); } }
public function onBeforeWrite() { parent::onBeforeWrite(); $code = $this->CountryCode; $country = Country_Shipping::get()->where("\"Code\" = '{$code}'")->first(); if ($country && $country->exists()) { $this->CountryName = $country->Title; $this->CountryID = $country->ID; } $code = $this->RegionCode; $region = Region_Shipping::get()->where("\"Code\" = '{$code}'")->first(); if ($region && $region->exists()) { $this->RegionName = $region->Title; $this->RegionID = $region->ID; } }
public function add($order, $value = null) { $this->OrderID = $order->ID; $country = Country_Shipping::get()->filter("Code", $order->ShippingCountryCode)->first(); $rates = $this->getFlatShippingRates($country); if ($rates && $rates->exists()) { //Pick the rate $rate = $rates->find('ID', $value); if (!$rate || !$rate->exists()) { $rate = $rates->first(); } //Generate the Modification now that we have picked the correct rate $mod = new FlatFeeShippingModification(); $mod->Price = $rate->Amount()->getAmount(); $mod->Description = $rate->Description; $mod->OrderID = $order->ID; $mod->Value = $rate->ID; $mod->FlatFeeShippingRateID = $rate->ID; $mod->write(); } }
public function add($order, $value = null) { //Get valid rates for this order $rates = null; $country = Country_Shipping::get()->where("\"Code\" = '" . $order->ShippingCountryCode . "'")->first(); $countryID = $country && $country->exists() ? $country->ID : null; $rates = $countryID ? $rates = FlatFeeTaxRate::get()->where("\"CountryID\" = '{$countryID}'") : null; if ($rates && $rates->exists()) { //Pick the rate $rate = $rates->find('ID', $value); if (!$rate || !$rate->exists()) { $rate = $rates->first(); } //Generate the Modification now that we have picked the correct rate $mod = new FlatFeeTaxModification(); $mod->Price = $rate->Amount($order)->getAmount(); $mod->Description = $rate->Description; $mod->OrderID = $order->ID; $mod->Value = $rate->ID; $mod->FlatFeeTaxRateID = $rate->ID; $mod->write(); } }
public function updateFields($fields) { Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js'); Requirements::javascript('swipestripe-addresses/javascript/Addresses_OrderForm.js'); $shippingAddressFields = CompositeField::create(HeaderField::create(_t('CheckoutPage.SHIPPING_ADDRESS', "Shipping Address"), 3), TextField::create('ShippingFirstName', _t('CheckoutPage.FIRSTNAME', "First Name"))->addExtraClass('shipping-firstname')->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_FIRSTNAME', "Please enter a first name.")), TextField::create('ShippingSurname', _t('CheckoutPage.SURNAME', "Surname"))->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_SURNAME', "Please enter a surname.")), TextField::create('ShippingCompany', _t('CheckoutPage.COMPANY', "Company")), TextField::create('ShippingAddress', _t('CheckoutPage.ADDRESS', "Address"))->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_ADDRESS', "Please enter an address."))->addExtraClass('address-break'), TextField::create('ShippingAddressLine2', ' '), TextField::create('ShippingCity', _t('CheckoutPage.CITY', "City"))->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_CITY', "Please enter a city.")), TextField::create('ShippingPostalCode', _t('CheckoutPage.POSTAL_CODE', "Zip / Postal Code")), TextField::create('ShippingState', _t('CheckoutPage.STATE', "State / Province"))->addExtraClass('address-break'), DropdownField::create('ShippingCountryCode', _t('CheckoutPage.COUNTRY', "Country"), Country_Shipping::get()->map('Code', 'Title')->toArray())->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_COUNTRY', "Please enter a country."))->addExtraClass('country-code'))->setID('ShippingAddress')->setName('ShippingAddress'); $billingAddressFields = CompositeField::create(HeaderField::create(_t('CheckoutPage.BILLINGADDRESS', "Billing Address"), 3), $checkbox = CheckboxField::create('BillToShippingAddress', _t('CheckoutPage.SAME_ADDRESS', "same as shipping address?"))->addExtraClass('shipping-same-address'), TextField::create('BillingFirstName', _t('CheckoutPage.FIRSTNAME', "First Name"))->setCustomValidationMessage(_t('CheckoutPage.PLEASEENTERYOURFIRSTNAME', "Please enter your first name."))->addExtraClass('address-break'), TextField::create('BillingSurname', _t('CheckoutPage.SURNAME', "Surname"))->setCustomValidationMessage(_t('CheckoutPage.PLEASEENTERYOURSURNAME', "Please enter your surname.")), TextField::create('BillingCompany', _t('CheckoutPage.COMPANY', "Company")), TextField::create('BillingAddress', _t('CheckoutPage.ADDRESS', "Address"))->setCustomValidationMessage(_t('CheckoutPage.PLEASEENTERYOURADDRESS', "Please enter your address."))->addExtraClass('address-break'), TextField::create('BillingAddressLine2', ' '), TextField::create('BillingCity', _t('CheckoutPage.CITY', "City"))->setCustomValidationMessage(_t('CheckoutPage.PLEASEENTERYOURCITY', "Please enter your city")), TextField::create('BillingPostalCode', _t('CheckoutPage.POSTALCODE', "Zip / Postal Code")), TextField::create('BillingState', _t('CheckoutPage.STATE', "State / Province"))->addExtraClass('address-break'), DropdownField::create('BillingCountryCode', _t('CheckoutPage.COUNTRY', "Country"), Country_Billing::get()->map('Code', 'Title')->toArray())->setCustomValidationMessage(_t('CheckoutPage.PLEASEENTERYOURCOUNTRY', "Please enter your country.")))->setID('BillingAddress')->setName('BillingAddress'); $fields->push($shippingAddressFields); $fields->push($billingAddressFields); }
/** * Fields for CRUD of shipping regions * * @see DataObject::getCMSFields() */ public function getCMSFields() { // $fields = new FieldList( // $rootTab = new TabSet('Root', // $tabMain = new Tab('Region', // TextField::create('Code', _t('Region.CODE', 'Code')), // TextField::create('Title', _t('Region.TITLE', 'Title')), // DropdownField::create('CountryID', 'Country', Country_Shipping::get()->map()->toArray()) // ) // ) // ); // return $fields; $fields = parent::getCMSFields(); $fields->replaceField('CountryID', DropdownField::create('CountryID', 'Country', Country_Shipping::get()->map()->toArray())); $fields->removeByName('SortOrder'); $fields->removeByName('ShopConfigID'); return $fields; }
/** * Field for editing a {@link FlatFeeTaxRate}. * * @return FieldSet */ public function getCMSFields() { return new FieldList($rootTab = new TabSet('Root', $tabMain = new Tab('TaxRate', TextField::create('Title', _t('FlatFeeTaxRate.TITLE', 'Title')), TextField::create('Description', _t('FlatFeeTaxRate.DESCRIPTION', 'Description')), DropdownField::create('CountryID', _t('FlatFeeTaxRate.COUNTRY', 'Country'), Country_Shipping::get()->map()->toArray()), NumericField::create('Rate', _t('FlatFeeTaxRate.TAX_RATE', 'Tax rate'))->setRightTitle('As a percentage (%)')))); }
/** * Field for editing a {@link FlatFeeShippingRate}. * * @return FieldSet */ public function getCMSFields() { return new FieldList($rootTab = new TabSet('Root', $tabMain = new Tab('ShippingRate', TextField::create('Title', _t('FlatFeeShippingRate.TITLE', 'Title')), TextField::create('Description', _t('FlatFeeShippingRate.DESCRIPTION', 'Description'))->setRightTitle('Label used in checkout form.'), DropdownField::create('CountryID', _t('FlatFeeShippingRate.COUNTRY', 'Country'), Country_Shipping::get()->map()->toArray()), PriceField::create('Price')))); }