Skip to content

Instantly share code, notes, and snippets.

@unlocomqx
Created April 25, 2019 12:49
Show Gist options
  • Save unlocomqx/d97195b1f7a12d428c7a01a9af70bc4b to your computer and use it in GitHub Desktop.
Save unlocomqx/d97195b1f7a12d428c7a01a9af70bc4b to your computer and use it in GitHub Desktop.
/*
* Get all carriers available for this zon
*/
public static function getCarriersByCountry($id_country, $id_state, $zipcode, $exiting_cart, $id_customer)
{
// Create temporary Address
$addr_temp = new Address();
$addr_temp->id_customer = $id_customer;
$addr_temp->id_country = $id_country;
$addr_temp->id_state = $id_state;
$addr_temp->postcode = $zipcode;
// Populate required attributes
// Note: Some carrier needs the whole address
// the '.' will do the job
$addr_temp->firstname = ".";
$addr_temp->lastname = ".";
$addr_temp->address1 = ".";
$addr_temp->city = ".";
$addr_temp->alias = "TEMPORARY_ADDRESS_TO_DELETE";
$addr_temp->save();
$id_prev_address = $exiting_cart->id_address_delivery;
$exiting_cart->id_address_delivery = $addr_temp->id;
$carriers = $exiting_cart->simulateCarriersOutput(null, true);
$exiting_cart->id_address_delivery = $id_prev_address;
//delete temporary objects
$addr_temp->delete();
return $carriers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment