Skip to main content
added 562 characters in body
Source Link
andyjv
  • 3.3k
  • 5
  • 27
  • 49

-- Edit 2 --

The truly mystifying part of this, is that I've added the results of Mage::getSingleton('checkout/session') to the Ajax response; and it correctly shows the data from setOptions(). Even if I log out of the admin and log back in, the data that I set in that singleton is still retained, according to my Ajax controller, but that seems to be the only place it exists. I can't echo it in a template and I can't access it in any other blocks, models, templates, or controllers. Is my Ajax Controller somehow existing in its own session?

-- Edit 2 --

The truly mystifying part of this, is that I've added the results of Mage::getSingleton('checkout/session') to the Ajax response; and it correctly shows the data from setOptions(). Even if I log out of the admin and log back in, the data that I set in that singleton is still retained, according to my Ajax controller, but that seems to be the only place it exists. I can't echo it in a template and I can't access it in any other blocks, models, templates, or controllers. Is my Ajax Controller somehow existing in its own session?

Adding specific code details in case there is something else going on
Source Link
andyjv
  • 3.3k
  • 5
  • 27
  • 49
<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>
 
// cut for brevity ... there are a number of select fields

        <button type="button" id="updateFQ" class="button" onclick="order.itemsUpdate()"><span><span>Save & Continue</span></span></button>
</fieldset>
<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>
<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>

// cut for brevity ... there are a number of select fields

        <button type="button" id="updateFQ" class="button" onclick="order.itemsUpdate()"><span><span>Save & Continue</span></span></button>
</fieldset>
Adding specific code details in case there is something else going on
Source Link
andyjv
  • 3.3k
  • 5
  • 27
  • 49

--- 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
}

--- 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
}
Source Link
andyjv
  • 3.3k
  • 5
  • 27
  • 49
Loading