--- edit ---
I am specifically testing this when editing an existing order, but creating an order would essentially be the same.
When the select field in this template(options.phtml
) is changed, it is sent via AJAX to options/ajax/addOption
(see addOptionAction()
below).
Then, when the submit button is hit, it fires the magento function order.itemsUpdate()
, which I confess I'm not very familiar with, but it gives the desired result of clearing the shipping quotes. Then the user clicks on the link that fires order.loadShippingRates()
, which causes Magento to get all shipping quotes, eventually getting to Freightquote below.
This all seems to behave in the same way that the standard checkout process does, except in the Freightquote module, I cannot access my singleton or registry when creating an order from the admin side.
Added in the adminhtml local.xml
:
<block type="adminhtml/sales_order_create_data" template="sales/order/create/data.phtml" name="data">
<block type="adminhtml/template" name="options" as="options" template="options/options.phtml" />
</block>
/design/adminhtml/default/[namespace]/template/options/options.phtml
<fieldset id="options">
<h4>Does the destination have a...</h4>
<label for="dock">Dock?*
<select name="dock">
<option></option>
<option value="0">No</option>
<option value="1">Yes</option>
<option value="2" >Don't know</option>
</select>
</label>
<button type="button" id="updateFQ" class="button" onclick="order.itemsUpdate()"><span><span>Save & Continue</span></span></button>
</fieldset>
/local/[namespace]/Options/controllers/AjaxController.php
public function addOptionAction()
{
$params = $this->getRequest()->getParams();
$session = Mage::getSingleton('checkout/session');
foreach($params as $key => $value){
$data = $session->getOptions();
$data[$key] = $value;
$session->setOptions($data);
Mage::register('options', $data);
}
$result['options'] = $session->getOptions();
$result['success'] = true;
header("Content-type: application/json", true);
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
/community/Freightquote/Shipping/Model/Carrier/Shipping.php
public function getDestConfig($type)
{
$config = array(
'liftgate' => $this->getConfigData('destination_liftgate'),
'residential' => $this->getConfigData('destination_residence'),
'construction' => $this->getConfigData('destination_construction'),
'dock' => $this->getConfigData('destination_dock'),
);
$session = Mage::getSingleton('checkout/session')->getOptions(); //empty when called from admin area
if(count($session) < 1){
$session = Mage::registry('options');
Mage::log($session); //Returns nothing!
}
//snipping the code here because the rest doesn't matter
}