phpmagento

Display message is Not working for out of stock products


please visit link1 , you can see there is option to find shipping is available or not for particular zip code : image1

enter image description here

here shipping charges are working for instock products but not for out-of -stock products.

Form.phtml

app/design/frontend/default/default/template/webdevlopers/productpageshipping/estimate/form.phtml

<?php if ($this->isFieldVisible('postcode')): ?> 
  <li class="item"> 

    <label for="search"<?php if ($this->isFieldRequired('postcode')):?> class="required" <?php endif;?>>
      <?php if ($this->isFieldRequired('postcode')):?>
        <em>*</em>
      <?php endif;?>
      <?php echo Mage::helper('webdevlopers_productpageshipping')->__('') ?>
    </label> 
    <div class="search">
      <input placeholder="Enter your PIN Code" 
        class="input-text validate-postcode<?php if ($this->isFieldRequired('postcode')):?> required-entry<?php endif;?>" 
        type="text" id="estimate_postcode" 
        name="estimate[postcode]" 
        value="<?php echo $this->htmlEscape($this->getFieldValue('postcode')) ?>" 
        onkeydown="if (event.keyCode == 13) { return false;}" />
    </div> 
  </li>
<?php endif; ?> 

Script

<script type="text/javascript"> 
  var $ = jQuery.noConflict(); 
  (function($) { 
    $(document).ready(function(){ 
      $('#estimate_postcode').keydown(function(e){

        var items = $$(['.shipping-estimation-form input', 
          '.shipping-estimation-form select', 
          '#product_addtocart_form input', 
          '#product_addtocart_form select']); 
        var estimationUrl = '<?php echo $this->jsQuoteEscape($this->getEstimateUrl());?>'; 
        var parameters = Form.serializeElements(items, true); 
        console.log("zipcode onkeypress worked"); 
        if (!e) e = window.event; 
        var keyCode = e.keyCode || e.which; 
        if (keyCode == '13'){ 
          //disable default enter action 
          e.preventDefault(); 
          console.log("Enter button was pressed"); 
          $('#shipping-estimate-loading-message').show(); 
          $('#shipping-estimate-results').hide(); 

          new Ajax.Updater('shipping-estimate-results', estimationUrl, { 
            parameters: parameters, 
            onComplete: function() { 
              console.log("ajax updater worked"); 
              $('#shipping-estimate-loading-message').hide(); 
              $('#shipping-estimate-results').show(); 
              $('#unique_id').hide(); 
              //$('unique_id').hide(); 
              $('estimate_postcode').val()
            } 
          }); 
        }; 
      }); 
    }); 
  }) ( jQuery ); 

  function estimateProductShipping() 
  { 

    var estimationUrl = '<?php echo $this->jsQuoteEscape($this->getEstimateUrl());?>'; 
    var items = $$(['.shipping-estimation-form input', 
      '.shipping-estimation-form select', 
      '#product_addtocart_form input', 
      '#product_addtocart_form select']); 

    var validationResult = true; 

    // Check the valid input 
    if (!items.map(Validation.validate).all()) { 
      return; 
    } 

    var parameters = Form.serializeElements(items, true); 

    $('shipping-estimate-loading-message').show(); 
    $('shipping-estimate-results').hide(); 


    new Ajax.Updater('shipping-estimate-results', estimationUrl, { 
      parameters: parameters, 
      onComplete: function() { 
        console.log("ajax updater worked"); 
        $('shipping-estimate-loading-message').hide(); 
        $('shipping-estimate-results').show(); 
        // $('#unique_id').hide(); 
        $('unique_id').hide(); 
        $('estimate_postcode').val()
      } 
    }); 
  } 

  //]]> 
</script> 

complete code of the file : https://gist.github.com/anonymous/ebe868508b2c21e9c032

result.phtml

app/design/frontend/default/default/template/webdevlopers/productpageshipping/estimate/result.phtml

<div class="block block-shipping-estimate block-shipping-results">
  <div class="block-title">
    <strong><span>
    <?php echo Mage::helper('webdevlopers_productpageshipping')->getShiptitle(); ?>
    </span></strong>
  </div>
  <div class="block-content">
    <?php if ($this->getResult()):?>
      <dl>
        <?php foreach ($this->getResult() as $code => $_rates): ?>
          <dt><?php echo $this->getCarrierName($code) ?></dt>
          <dd>
            <ul>
              <?php foreach ($_rates as $_rate): ?>
                <li<?php if ($_rate->getErrorMessage()) echo ' class="error-msg"';?>>
                  <?php if ($_rate->getErrorMessage()): ?>
                    <?php echo $_rate->getErrorMessage() ?>
                  <?php else: ?>
                    <?php 
                      //  echo $_rate->getMethodTitle() 
                    ?>
                    <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
                    <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>

                    <!-- sat -->

                    <p>
                      <?php echo "Shipping is available";?>
                    </p>

                    <p class="vship1">
                      <?php echo "Selling Price + " . str_replace('.00','',$_excl) . " Delivery ";?>
                    </p>

                    <!-- sat -->

                    <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
                        (<?php echo Mage::helper('webdevlopers_productpageshipping')->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
                    <?php endif; ?>
                  <?php endif ?>
                </li>
              <?php endforeach; ?>
            </ul>
          </dd>
        <?php endforeach; ?>
      </dl>
    <?php else: ?>
      <?php //echo $this->getMessagesBlock()->toHtml(); ?>
      <?php echo Mage::helper('webdevlopers_productpageshipping')->getResult(); ?>
    <?php endif;?>
  </div>
</div>

app/code/community/webdevolopers/productpageshiping/Block/estimate/ Result.php

<?php

class WebDevlopers_ProductPageShipping_Block_Estimate_Result extends WebDevlopers_ProductPageShipping_Block_Estimate_Abstract
{

    public function getResult()
    {
        return $this->getEstimate()->getResult();
    }


    public function hasResult()
    {
        return $this->getResult() !== null;
    }


    public function getCarrierName($code)
    {
        $carrier = Mage::getSingleton('shipping/config')->getCarrierInstance($code);
        if ($carrier) {
            return $carrier->getConfigData('title');
        }

        return null;
    }


    public function getShippingPrice($price, $flag)
    {
        return $this->formatPrice(
            $this->helper('tax')->getShippingPrice(
                $price,
                $flag,
                $this->getEstimate()
                    ->getQuote()
                    ->getShippingAddress()
           )
        );
    }


    public function formatPrice($price)
    {
        return $this->getEstimate()
            ->getQuote()
            ->getStore()
            ->convertPrice($price, true);
    }
}

Solution

  • changing the settings in System > Config > Inventory

    Easiest way to do this is select all products you want to allow to be backordered, then select Update attributes from the actions drop down and click submit. then shipping problem will not be problem.