Question

we have marketplace multi vendor/seller site. we gave an option for seller to update the product information through frontend.

As it is marketplace site, we have many sellers.

seller A uploaded product A in frontend [quantity = 20 ]

if seller B have same product , he will assign the same product to his account [quantity = 5 ]

in backend it showing 20 + 5 = 25 quantity.

now the problem is when seller A update the quantity from 20 to 40, it showing 40 in frontend and once we refresh the page, it showing only 35. Means after refreshing it showing quantity of [ Seller A qty- Seller B qty ]

but it should show seller A Quantity.

Before It was working properly , later we did some code changes than we are facing this Problem.

before the qty textfield was looking like as in image :

enter image description here

once we click on "edit " button present in image, it looks like below image :

enter image description here

But we decided to display below image :

enter image description here

so we changed code to look like above image. Than this problem happened.

Before Code : [Everything was working fine ]

<td>
<?php
$selllermpassignproduct=Mage::getModel('mpassignproduct/mpassignproduct')->getAssignProDetails($products->getId());
//Zend_Debug::dump($selllermpassignproduct,null,true);
$stock_item=Mage::getModel('cataloginventory/stock_item')->loadByProduct($products);

$SellerQty=isset($selllermpassignproduct['sellerqty'])?$selllermpassignproduct['sellerqty']:$stock_item->getQty();
$assignqty=isset($selllermpassignproduct['assignqty'])?$selllermpassignproduct['assignqty']:0;
?>

<span id="valueqty_<?php echo $products->getId(); ?>"><?php echo (int) $SellerQty; ?></span>
<input type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name = "stock" value = "<?php echo (int) $SellerQty; ?>" style = "display:none"/>



<span class="label wk_action" id="edit_link_<?php echo $products->getId(); ?>">
<img onclick="showField('<?php echo $products->getId(); ?>'); return false;" src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>"/>
</span>  

<p id="updatedqty_<?php echo $products->getId(); ?>" style = "display:none;color:red;">Updated</p>
<br/>


<button id="update_button_<?php echo $products->getId(); ?>" class="buttons" onclick="updateField('<?php echo $products->getId(); ?>',<?php echo $assignqty;?>); return false;" style="display:none" >
<span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span>
</button>

<button id="reset_button_<?php echo $products->getId(); ?>" type="reset" class="cancel" onclick="hideReset('<?php echo $products->getId(); ?>'); return false;" style="display:none" >
<span><span><?php echo $helper->__('Cancel') ?></span></span>
</button>

Script

function hideReset(product_id) {

            var qtyId='#qty_'+ product_id;
            var editLink="#edit_link_"+ product_id;
            var updateButton="#update_button_"+ product_id;
            var resetButton="#reset_button_"+ product_id;

            $wk_jq(qtyId).hide();
            $wk_jq(editLink).show();
            $wk_jq(updateButton).hide();
            $wk_jq(resetButton).hide();
        }


        function updateField(product_id,assignqty)
        {
            var qtyId = '#qty_'+ product_id;
            var valueId = '#valueqty_'+ product_id;
            var updatedqty = '#updatedqty_'+ product_id;


            var editLink = "#edit_link_"+ product_id;
            var updateButton = "#update_button_"+ product_id;
            var resetButton = "#reset_button"+ product_id;
            var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateField/')?>';

            $wk_jq(qtyId).toggle()

            $wk_jq(editLink).hide();
            $wk_jq(updateButton).show();
            $wk_jq(resetButton).show();

            $qty = $wk_jq(qtyId).val();
            jQuery(valueId).html($qty);
            hideReset(product_id);

            var tmpQty=assignqty+ parseInt($qty) ;

            new Ajax.Request(url, {
                method: 'post',
                parameters: {id: product_id, qty: tmpQty},
                onComplete: function (transport) {
                    //alert(transport.responseText);
                    jQuery(priceId).val($price);
            // $wk_jq(priceId).setValue($price);

                    jQuery(updatedqty).show().delay(2000).fadeOut();

                    $updateButton.prop('disabled', false);

                    // $wk_jq(qtyId).setValue($qty);



                }
            });
        }

Present code

In the above code, we comment some lines and we replaced some codes as below.

commented code

 <!--   <img onclick="showField('<?php echo $products->getId(); ?>'); return false;" src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?> -->

    **script**

    //$wk_jq(qtyId).toggle()
    //$wk_jq(updateButton).show();
    //hideReset(product_id);
    //jQuery(updatedqty).show().delay(2000).fadeOut();

Replaced code 1 )

 <input type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name = "stock" 
    value = "<?php echo (int) $SellerQty; ?>" style = "display:none"/> 

to

<input type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" 
name = "stock" class="ama1" value = "<?php echo (int) $SellerQty; ?>" />

Replaced code 2)

 var tmpQty=assignqty+ parseInt($qty) ;          
   new Ajax.Request(url, {
   method: 'post',
   parameters: {id: product_id, qty: tmpQty},

to

var tmpQty=parseInt(assignqty)+ parseInt($qty) ;
 new Ajax.Request(url, {
 method: 'post',
 parameters: {id: product_id, qty: $qty},
Was it helpful?

Solution

after reading you code i figure out problem was with the 'assignqty'

<?php
$selllermpassignproduct=Mage::getModel('mpassignproduct/mpassignproduct')->getAssignProDetails($products->getId());
//Zend_Debug::dump($selllermpassignproduct,null,true);
$stock_item=Mage::getModel('cataloginventory/stock_item')->loadByProduct($products);

$SellerQty=isset($selllermpassignproduct['sellerqty'])?$selllermpassignproduct['sellerqty']:$stock_item->getQty();
$assignqty=isset($selllermpassignproduct['assignqty'])?$selllermpassignproduct['assignqty']:0;
?> 

while you are updating the qty you have to add asignqty with new qty

$qty = $this->getRequest()->getParam('stock'.$i);
      $selllermpassignproduct=Mage::getModel('mpassignproduct/mpassignproduct')->getAssignProDetails($value);
 $assignqty=isset($selllermpassignproduct['assignqty'])?$selllermpassignproduct['assignqty']:0;
        $newqty=$qty+$assignqty;
       $stockItem->setData('qty', $newqty);

OTHER TIPS

1st problem:

Do not use $product->setQty(...)

Use:

foreach ($ids as $key => $value) {
    $product = Mage::getModel('catalog/product')->load($value);
    ...
    $product->save();
    ...

    $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId());

    $stockItem->setData('manage_stock', 1);
    $stockItem->setData('qty', $qty[$key]);

    $stockItem->save();
    ...
}

2nd problem:

There is not an easy solution with your code.

You should use multiple warehouses (one for each merchant).

Look at this extension that may help you:

https://github.com/webgriffe/Webgriffe_Multiwarehouse

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top