1

please visit this link

add this configurable product to cart ,go to cart page and try to update the quantity , for example more than 1.

but in cart page, if we try to edit the quantity, its not updating more than one. but required number of quantity is available in backend.

Error : Number of quantity not available.

we installed one extension This error is coming from an extension. If we remove the extension, it will work fine.but we need that extension for some purpose. This is observer.php of the extension.

<?php
Class Company_Extension_Model_Observer
{
    /*after update cart*/   
    public function cartUpdate($observer) {
        $db = Mage::getSingleton('core/resource')->getConnection('core_read');
        $cart = $observer->getCart()->getQuote()->getAllItems();
        $cart_data =  Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
        $info = $observer->getInfo();
        foreach($cart_data as $item) {
            $current_qty=$info[$item->getId()]['qty'];
            $productid= $item->getProductId();
            $mpassignproductId=0;
            foreach($item->getOptions() as $option) {
                $temp=unserialize($option['value']);
                if($temp['mpassignproduct_id'])
                    $mpassignproductId=$temp['mpassignproduct_id'];
            }
            if($mpassignproductId) {
                $productdetail=Mage::getModel('mpassignproduct/mpassignproduct')->load($mpassignproductId);
                $price=$productdetail->getPrice();
                $avlqty=$productdetail->getQty();
                $seller=$productdetail->getSellerId();

                $diff=$avlqty-$current_qty;
                if($diff>0) {
                    $item->setCustomPrice($price);
                    $item->setOriginalCustomPrice($price);
                    $item->getProduct()->setIsSuperMode(true);
                } else if($diff<=0) {
                    if($current_qty > $avlqty) {
                        $item->setCustomPrice($price);
                        $item->setOriginalCustomPrice($price);
                        $item->setQty($avlqty);
                        Mage::getSingleton('core/session')->addNotice('Number of quantity not available.');
                    }
                }
            } else {
                $adminAvlQty=Mage::getModel('mpassignproduct/mpassignproduct')->getAssignProDetails($productid);
                if($current_qty >  $adminAvlQty['sellerqty']) {
                    $item->setQty($adminAvlQty['sellerqty']);
                    Mage::getSingleton('core/session')->addNotice('Number of quantity not available.');
                }
            }
        }
    }

    /*after product added to cart*/ 
    public function productCart(Varien_Event_Observer $obs) {
        $cart_data =  Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();

        $item = $obs->getQuoteItem();
        $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
        $db = Mage::getSingleton('core/resource')->getConnection('core_read');
        $productid=$item->getProductId();           
        foreach ($cart_data as $cart) { 
            if($cart->getProductId()==$productid){
                $quantity=$cart->getQty();
            }
        }
        $productid= $item->getProductId();
        $mpassignproductId=0;
        foreach($item->getOptions() as $option) {
            $temp=unserialize($option['value']);
            if($temp['mpassignproduct_id'])
                $mpassignproductId=$temp['mpassignproduct_id'];

        }
        if($mpassignproductId) {
            $productdetail=Mage::getModel('mpassignproduct/mpassignproduct')->load($mpassignproductId);
            $price=$productdetail->getPrice();
            $avlqty=$productdetail->getQty();
            $seller=$productdetail->getSellerId();

            $diff=$avlqty-$quantity;
            if($diff>0) {
                $item->setCustomPrice($price);
                $item->setOriginalCustomPrice($price);
                $item->getProduct()->setIsSuperMode(true);
            } else if($diff<=0) {
                if($quantity > $avlqty) {
                    $item->setCustomPrice($price);
                    $item->setOriginalCustomPrice($price);
                    $item->setQty($avlqty);
                    Mage::getSingleton('core/session')->addNotice('Number of quantity not available.');
                }
            }
        } else {
            $adminAvlQty=Mage::getModel('mpassignproduct/mpassignproduct')->getAssignProDetails($productid);
            if($quantity >  $adminAvlQty['sellerqty']) {
                $item->setQty($adminAvlQty['sellerqty']);
                Mage::getSingleton('core/session')->addNotice('Number of quantity not available.');
            }
        }
    }

    public function productUpdateCart(Varien_Event_Observer $observer) { 
        $item=$observer->getItem();
        $proprice=$item->getProduct()->getPrice();
        $item->setCustomPrice($proprice);
        $item->setOriginalCustomPrice($proprice);
        $item->save();  
    }

    public function afterPlaceOrder1($observer) { 
        $lastOrderId=$observer->getOrder()->getId();
        $order = Mage::getModel('sales/order')->load($lastOrderId);
        $ordered_items = $order->getAllItems();
        foreach ($ordered_items as $item) {
            $options=$item->getProductOptions();
            $productId=$item->getProductId();
            $mpassignproductId=$options['info_buyRequest']['mpassignproduct_id'];
            if($mpassignproductId) {
                $collect=Mage::getModel('marketplace/saleslist')->getCollection()
                    ->addFieldToFilter('mageproid',array('eq'=>$productId))
                    ->addFieldToFilter('mageorderid',array('eq'=>$lastOrderId));
                foreach($collect as $val) {
                    $slqty=$val['magequantity'];
                    $saleslistId=$val['autoid'];
                }
                $mpassignModel=Mage::getModel('mpassignproduct/mpassignproduct')->load($mpassignproductId);

                if($saleslistId) {
                    $saleslistModel=Mage::getModel('marketplace/saleslist')->load($saleslistId);
                    $saleslistModel->setMageproownerid($mpassignModel->getSellerId());
                    $saleslistModel->setMpassignproductId($mpassignproductId);
                    $saleslistModel->save();

                    $asqt=$mpassignModel->getQty();
                    $nasqt = $asqt-$slqty;
                    $mpassignModel->setQty($nasqt);
                    $mpassignModel->save();
                } 
            }
        }
    }
    /*Pending................................on product delete from seller*/
    public function deleteProductCheck($observer) {
        $productid=$observer->getId();
        $collection=Mage::getModel('mpassignproduct/mpassignproduct')
                        ->getCollection()
                        ->addFieldToFilter('product_id',array('eq'=>$productid))
                        ->addFieldToFilter('qty',array('gt'=>0));
        $collection->setOrder("price","ASC");
        if(count($collection)>0) {
            foreach($collection as $assignproduct) {
                $collectionpro=Mage::getModel('marketplace/product')->getCollection()
                        ->addFieldToFilter('mageproductid',array('eq'=>$productid));
                foreach($collectionpro as $row) {
                    $row->setUserid($assignproduct->getSellerId());
                    $row->save();
                    // set qty to product
                    $data=Mage::getModel('mpassignproduct/mpassignproduct')->getAssignProDetails($productid);

                    $_product=Mage::getModel('catalog/product')->load($productid);
                    $_product->setPrice($assignproduct->getPrice());
                    $_product->save();

                    $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productid);
                    $stockItem->setProductId($productid)->setStockId(1);
                    $savedStock = $stockItem->save();
                    $stockItem->load($savedStock->getId())->setQty($data['assignqty'])->save();
                    $stockItem->setData('is_in_stock', 1); 
                    $savedStock = $stockItem->save();
                }
                Mage::getSingleton('customer/session')->setIsAssing($assignproduct->getMpassignproductId());
                $assignproduct->delete();
                break;
            }
        } else {
            Mage::getSingleton('customer/session')->setIsAssing(0);
        }
    }

    //when admin will the delete the product
    public function DeleteProduct($observer) { 
        $collection = Mage::getModel('mpassignproduct/mpassignproduct')->getCollection()
                                ->addFieldToFilter('product_id ',$observer->getProduct()->getId());
        foreach($collection as $data){          
            Mage::getModel('mpassignproduct/mpassignproduct')->load($data['mpassignproduct_id'])->delete();         
        }       
    }
}

config.xml

<?xml version="1.0"?>
<!-- 
/**
 * @category   company
 * @package    company_Mpassignproduct
 * @author     ModuleCreator
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
 -->
<config>
    <modules>
        <company_Mpassignproduct>
            <version>1.0.1</version>
        </company_Mpassignproduct>
    </modules>


    <!-- ssl -->
    <frontend>
    <secure_url>
        <company_Mpassignproduct>/mpassignproduct/index/index/</company_Mpassignproduct>
        <company_Mpassignproduct>/mpassignproduct/index/mpassignproductlist/</company_Mpassignproduct>
    </secure_url>
</frontend>


<!-- ssl  end-->

    <frontend>
        <routers>
            <mpassignproduct>
                <use>standard</use>
                <args>
                    <module>company_Mpassignproduct</module>
                    <frontName>mpassignproduct</frontName>
                </args>
            </mpassignproduct>
        </routers>
        <layout>
            <updates>
                <mpassignproduct>
                    <file>mpassignproduct.xml</file>
                </mpassignproduct>
            </updates>
        </layout>
        <translate>
            <modules>
                <company_Mpassignproduct>
                    <files>
                      <mpassignproduct>company_Mpassignproduct.csv</mpassignproduct>
                    </files>
                </company_Mpassignproduct>
            </modules>
        </translate>
    </frontend>
        <admin>
              <routers>
                    <mpassignproduct>
                        <use>admin</use>
                        <args>
                            <module>company_Mpassignproduct</module>
                            <frontName>mpassignproduct</frontName>
                        </args>
                    </mpassignproduct>
            </routers>
        </admin>
        <adminhtml>
            <acl>
                <resources>
                    <all>
                       <title>Allow Everything</title>
                    </all>
                    <admin>
                        <children>
                            <company_Mpassignproduct>
                                <title>Mpassignproduct Module</title>
                                <sort_order>10</sort_order>
                            </company_Mpassignproduct>
                        </children>
                    </admin>
                </resources>
            </acl>
            <layout>
                <updates>
                      <mpassignproduct>
                         <file>mpassignproduct.xml</file>
                      </mpassignproduct>
                  </updates>
              </layout>
        </adminhtml>   
    <global>
    <events>
      <catalog_product_delete_after>
          <observers>
             <company_Mpassignproduct_Model_Observer>
                <type>singleton</type>
                <class>company_Mpassignproduct_Model_Observer</class>
                <method>DeleteProduct</method>
             </company_Mpassignproduct_Model_Observer>
         </observers>
      </catalog_product_delete_after>
      <checkout_cart_product_add_after>
               <observers>
                   <company_Mpassignproduct_Model_Observer>
                      <type>singleton</type>
                      <class>company_Mpassignproduct_Model_Observer</class>
                      <method>productCart</method>
                   </company_Mpassignproduct_Model_Observer>
               </observers>
           </checkout_cart_product_add_after>
      <checkout_cart_update_items_after>
          <observers>
              <company_Mpassignproduct_Model_Observer>
                  <type>singleton</type>
                  <class>company_Mpassignproduct_Model_Observer</class>
                  <method>cartUpdate</method>
              </company_Mpassignproduct_Model_Observer>
          </observers>
      </checkout_cart_update_items_after>
      <checkout_cart_update_item_complete>
          <observers>
              <company_Mpassignproduct_Model_Observer>
                  <type>singleton</type>
                  <class>company_Mpassignproduct_Model_Observer</class>
                  <method>productUpdateCart</method> 
              </company_Mpassignproduct_Model_Observer>
          </observers>
      </checkout_cart_update_item_complete>
      <sales_order_place_after>
          <observers>
              <company_Mpassignproduct_Model_Observer>
              <type>singleton</type>
              <class>company_Mpassignproduct_Model_Observer</class>
              <method>afterPlaceOrder1</method>
              </company_Mpassignproduct_Model_Observer>
          </observers>
      </sales_order_place_after>
      <mp_delete_product>
          <observers>
              <mp_delete_product_isassign>
                  <type>singleton</type>
                  <class>company_Mpassignproduct_Model_Observer</class>
                  <method>deleteProductCheck</method>
              </mp_delete_product_isassign>
          </observers>
      </mp_delete_product>
    </events>
        <models>
            <mpassignproduct>
                  <class>company_Mpassignproduct_Model</class>
                  <resourceModel>mpassignproduct_mysql4</resourceModel>
            </mpassignproduct>
            <mpassignproduct_mysql4>
                <class>company_Mpassignproduct_Model_Mysql4</class>
                <entities>
                    <mpassignproduct>
                        <table>marketplace_assignproduct</table>
                    </mpassignproduct>
                    <productshipping>
                        <table>marketplace_mpassign_shipping</table>
                    </productshipping>
                </entities>
            </mpassignproduct_mysql4>
        </models>
        <resources>
            <mpassignproduct_setup>
                <setup>
                    <module>company_Mpassignproduct</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </mpassignproduct_setup>
            <mpassignproduct_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </mpassignproduct_write>
            <mpassignproduct_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </mpassignproduct_read>
        </resources>
        <blocks>
            <mpassignproduct>
                <class>company_Mpassignproduct_Block</class>
            </mpassignproduct>
        </blocks>
        <helpers>
            <mpassignproduct>
                <class>company_Mpassignproduct_Helper</class>
            </mpassignproduct>
        </helpers>
        <template>
            <email>
                <approveassignproduct>
                    <label>Approve My Product</label>
                    <file>mpassignproduct/admininformnewpro.html</file>
                    <type>html</type>
                </approveassignproduct>
            </email>
        </template>
    </global>
</config>
4
  • What are the events that trigger the observer? Feb 2 '16 at 12:08
  • sorry, i did't got. i dont have much idea about this. Feb 2 '16 at 12:11
  • Ok, so edit your question and post the config.xml of your extension. Events are defined there. Feb 2 '16 at 12:30
  • please check updated question... Feb 2 '16 at 12:34
1
+50

check your code here

$diff=$avlqty-$current_qty; 

$diff is less then zero. So it will give you an error "Number of quantity not available".

9
  • is i need to remove this code ? Feb 2 '16 at 16:18
  • please debug variable $avlqty and $current_qty so you will get exact point of error Feb 2 '16 at 16:22
  • in checkout its checking the main configurable product quantity, its not checking the associative product quantity. i guess that is the reason ,its not allowing to increase the quantity. so please help me change the code, such that in it should check associative products quantity. Feb 2 '16 at 16:25
  • please try with $cart_data = Mage::getSingleton('checkout/session')->getQuote()->getAlltems(); Feb 2 '16 at 16:32
  • just for a min, i am checking..... Feb 2 '16 at 16:46
2

i think there is quantity issue for product.Just update product in stock qty in admin and try update qty again.

3
1

I am also having similar issue. I am getting error while adding any configurable product with any options, it always showing the requested quantity for "XXX" is not available.

below this error it is showing: XXX was added to your shopping cart.

I couldn't found any solution for it, please help.

Error for configurable products, add to cart functionality

2
  • are you getting error when increasing quantity in cart page. are you using any third party extensions.?... Feb 15 '16 at 16:59
  • did you checked in backend, is quantity is there for those simple products. Feb 15 '16 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.