public function add_method() { $data = $this->post(); $errors = $this->validate($data); $this->error = null; //clear errors $this->error = $errors; if (!$errors->has()) { if ($this->post('shippingMethodID')) { //update $shippingMethod = StoreShippingMethod::getByID($this->post('shippingMethodID')); $shippingMethodTypeMethod = $shippingMethod->getShippingMethodTypeMethod(); $shippingMethodTypeMethod->update($this->post()); $shippingMethod->update($this->post('methodName'), $this->post('methodEnabled')); $this->redirect('/dashboard/store/settings/shipping/updated'); } else { //first we send the data to the shipping method type. $shippingMethodType = StoreShippingMethodType::getByID($this->post('shippingMethodTypeID')); $shippingMethodTypeMethod = $shippingMethodType->addMethod($this->post()); //make a shipping method that correlates with it. StoreShippingMethod::add($shippingMethodTypeMethod, $shippingMethodType, $this->post('methodName'), true); $this->redirect('/dashboard/store/settings/shipping/success'); } } else { if ($this->post('shippingMethodID')) { $this->edit($this->post('shippingMethodID')); } else { $this->add($this->post('shippingMethodTypeID')); } } }
public static function migrateOldShippingMethod(Package $pkg) { $shippingMethodEnabled = Config::get('vividstore.shippingenabled'); //if it wasn't even enabled, then why bother. if ($shippingMethodEnabled) { $basePrice = Config::get('vividstore.shippingbase'); $perItem = Config::get('vividstore.shippingitem'); $data = array('baseRate' => $basePrice, 'rateType' => 'quantity', 'perItemRate' => $perItem, 'minimumAmount' => 0, 'maximumAmount' => 0, 'minimumWeight' => 0, 'maximumWeight' => 0, 'countries' => 'all'); $shippingMethodType = StoreShippingMethodType::getByHandle('flat_rate'); $shippingMethodTypeMethod = $shippingMethodType->addMethod($data); StoreShippingMethod::add($shippingMethodTypeMethod, $shippingMethodType, 'Flat Rate', true); } }