I've got a question regarding when and why a model is loaded (specifically the shipping models). I've been working on a custom shipping model that grabs a rate quote from a truckline carrier and returns the values for my shipping total. The rate part works fine, im getting my numbers and everything. However what i ran into was that after cart changes (specifically changing the quantity of an item) that the shipping page used the shipping quote that was stored in the session from the previous quote. After a while i realized that the model wasn't being called again bc of this line in catalog/controller/checkout/shipping.php.
Code: Select all
if (!isset($this->session->data['shipping_methods']) {
Which was looking to see if shipping_methods had been stored in teh session and if so it wasn't loading the shipping models. Now, as a dirty hack bc i was coming up on 5pm and needed a visible solution to show the cart owner, i changed it to this.
Code: Select all
if (!isset($this->session->data['shipping_methods']) || isset($this->session->data['force_update'])) {
and in systems/library/cart.php i changed the add, update, and remove functions to contain this line after they completed their normal duties.
Code: Select all
$this->session->data['force_update'] = TRUE;
Then at the end of the If statement in shipping.php i just added
Code: Select all
unset($this->session->data['force_update']);
so that it wouldn't continually requery the quote API on our trucklines site every page refresh.
Ugh, after writing all that i just found where you unset($this->session->data['shipping_methods']) in the address controller. However, im still at a bit of a loss as how to eliminate my problem. Unsetting those 2 session variables on every add/remove/update cart call doesnt' seem like the cleanest way to fix my problem, but is that my only solution? I have to have it load the model if theres been changes, bc they change the weight, which in turn changes the quote. And, im going to run into the same issues when i start in on the UPS shipping model, so im hoping to find a better way to force the reloading of the models on any cart changes.