/** * Shipping Methods */ private function defaultShippingMethod() { $method = new Market_ShippingMethodRecord(); $method->name = 'Default Shipping Method'; $method->enabled = true; $method->default = true; $method->save(); $rule = new Market_ShippingRuleRecord(); $rule->methodId = $method->id; $rule->description = "Catches all countries and states"; $rule->name = "Catch All"; $rule->enabled = true; $rule->save(); }
/** * @param Market_ShippingMethodModel $model * * @return bool * @throws \Exception */ public function save(Market_ShippingMethodModel $model) { if ($model->id) { $record = Market_ShippingMethodRecord::model()->findById($model->id); if (!$record) { throw new Exception(Craft::t('No shipping method exists with the ID “{id}”', ['id' => $model->id])); } } else { $record = new Market_ShippingMethodRecord(); } $record->name = $model->name; $record->enabled = $model->enabled; $record->default = $model->default; $record->validate(); $model->addErrors($record->getErrors()); if (!$model->hasErrors()) { // Save it! $record->save(false); // Now that we have a record ID, save it on the model $model->id = $record->id; //If this was the default make all others not the default. if ($model->default) { Market_ShippingMethodRecord::model()->updateAll(['default' => 0], 'id != ?', [$record->id]); } return true; } else { return false; } }