A client of mine sells some products that can not be shipped via regular channels due to extreme size and/or weight.
For these products, I would like to add a setting like "can be shipped regularly". Then, in the checkout process I would like to check if there are any products in the cart having this flag, and if so: only show the shipment option "delivery on appointment".
I have already developed custom shipment carriers/methods, but do not know what would be a good way to disable any shipment methods for carts that contain a product matching the criteria.
I expected that when I set <sort_order>99999</sort_order>
in the carrier's config.xml
(so it's rendered last) and then having the following code in the Carrier.php
model, I would be able to unset any other possible carriers. However, this does not work.
<?php
class Vendor_ExampleCarrier_Model_Carrier
extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface
{
/** @var string carrier code */
protected $_code = 'vendor_examplecarrier';
/**
* Collect and get rates
*
* @param Mage_Shipping_Model_Rate_Request $request
* @return Mage_Shipping_Model_Rate_Result|bool|null
*/
public function collectRates( Mage_Shipping_Model_Rate_Request $request )
{
// ...
$canShipRegularly = false;
// ...
$shippingRateResultModel = Mage::getModel('shipping/rate_result');
if (true !== $canShipRegularly) {
// does nothing
$shippingRatesResultModel->reset();
// returns empty array
$shippingRatesResultModel->getAllRates();
}
return $shippingRateResultModel;
}
// other stuff..
}
I feel this might be a possible solution, if I would be possible to get access to this model in another scope.
Anyone have an idea as to how to accomplish this?