1

we have Marketplace Multi vendor/seller site, means sellers can sell the products through our site.

we are using an extension to implement this.

Before using an extension, we can see correct quantity under Catalog > Manage Products.

In extension , there is a bug so that,

under Catalog > Manage Products we can see "Quantity" for each product, This quantity is a combination of all sellers.

example : Products "A" have 2 sellers.

seller A is base seller with 10 quantity and seller B assigned the same product with 5 quantity.

So its displaying 15 under Manage Products > quantity.

Extension is over riding the default Quantity Feature.

I want to remove this over riding.

I guess this is code for the overriding :

app/code/local/webkul/Mpassignproduct/Model/Mpassignproduct.php

<?php

class Webkul_Mpassignproduct_Model_Mpassignproduct extends Mage_Core_Model_Abstract
{
    public function _construct() {
        parent::_construct();
        $this->_init('mpassignproduct/mpassignproduct');
    }

    public function editproduct($data) {
        $sellerId=Mage::getSingleton('customer/session')->getCustomerId();
        $products=Mage::getModel('mpassignproduct/mpassignproduct')->getCollection()
                            ->addFieldToFilter('seller_id',array('eq'=>$sellerId))
                            ->addFieldToFilter('mpassignproduct_id',array('eq'=>$data['pro_id']));
        if(count($products)) {
            foreach($products as $product) {
                $isApproved=$product->getFlag();
                $preQty=$product->getQty();
                $product->setQty($data['qty']);
                $product->setPrice($data['price']);
                $product->setProductCondition($data['product_condition']);
                $product->setProductDescription($data['product_description']);
                $saved=$product->save();
                $lastId=$saved->getId();
            }
        }
        if($lastId)  {
            if($isApproved == 1) {
                $_product=Mage::getModel("catalog/product")->load($data['product_id']);
                $qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
                $qtyStock = ($qtyStock - $preQty) + $data['qty'];
                $this->_saveStock($data['product_id'],$qtyStock,1); 
            }
            $this->uploadImages($lastId);
        }

        return $lastId;
    }

    public function assineproduct($data) {
        $data['seller_id'] = Mage::getSingleton('customer/session')->getCustomerId();
        $product = Mage::getModel('mpassignproduct/mpassignproduct');
        $product->setData($data);
        $status = Mage::getStoreConfig('marketplace/marketplace_options/product_approval') ? 2 : 1;

        $product->setFlag($status);
        $product->setCreatedAt(Mage::getModel('core/date')->date('Y-m-d H:i:s'));
        $saved=$product->save();
        $lastId=$saved->getId();

        if($lastId) {
            if($status == 1) {
                $_product=Mage::getModel("catalog/product")->load($data['product_id']);
                $qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
                $qtyStock = $qtyStock + $data['qty'];
                $this->_saveStock($data['product_id'],$qtyStock,1); 
            }
            $this->uploadImages($lastId);
        }
        return $lastId;
    }

    public function uploadImages($lastId) {
        $target =Mage::getBaseDir().'/media/mpassignproduct/'.$lastId.'/';
        if(isset($_FILES) && count($_FILES) > 0) {
            if(!is_dir(Mage::getBaseDir().'/media/mpassignproduct/')) {
                mkdir(Mage::getBaseDir().'/media/mpassignproduct/', 0755);
            }
            if(!is_dir(Mage::getBaseDir().'/media/mpassignproduct/'.$lastId.'/')) {
                mkdir(Mage::getBaseDir().'/media/mpassignproduct/'.$lastId.'/', 0755);
            }
            foreach($_FILES as $image ) {
                if($image['tmp_name'] != '') {
                    $splitname = explode('.', $image['name']);
                    $splitname[0] = str_replace('-', '', $splitname[0]);
                    $image_name = preg_replace('/[^A-Za-z0-9\-]/', '', $splitname[0]);
                    $target1 = $target.$image_name.".".$splitname[1];
                    move_uploaded_file($image['tmp_name'],$target1);
                }
            }               
        }
    }

    public function _saveStock($lastId,$stock,$isstock) {
        $stockItem = Mage::getModel('cataloginventory/stock_item');
        $stockItem->loadByProduct($lastId);
        if(!$stockItem->getId()){$stockItem->setProductId($lastId)->setStockId(1);}
        $stockItem->setProductId($lastId)->setStockId(1);
        $savedStock = $stockItem->save();
        $stockItem->load($savedStock->getId())->setQty($stock)->save();
        if($stock) {
            $stockItem->setData('is_in_stock', $isstock); 
        }
        $savedStock = $stockItem->save();
    }

    public function getAssignProDetails($productid) {
        $collection=Mage::getModel('mpassignproduct/mpassignproduct')->getCollection()
                            ->addFieldToFilter('product_id',array('eq'=>$productid))
                            ->addFieldToFilter('qty',array('gt'=>0))
                            ->addFieldToFilter('flag',array('eq'=>'1'))
                            ->setOrder("price","ASC");
        $data=array();                          
        $totalAssignQty=0;
        $priceFrom=0;               
        foreach($collection as $item) {
            $price=$item->getPrice();
            break;
        }           
        foreach($collection as $item) {
            $totalAssignQty = $totalAssignQty + $item->getQty();
        }   
        $productModel = Mage::getModel("catalog/product")->load($productid);
        if($productModel->getPrice() < $price)
            $priceFrom=$productModel->getPrice();
        else
            $priceFrom=$price;
        $totalProductQty = $productModel->getStockItem()->getQty();
        $data['sellerqty'] = $totalProductQty - $totalAssignQty;
        $data['assignqty'] = $totalAssignQty;
        $data['pricefrom'] = $priceFrom;
        $data['assignCount'] = count($collection);
        return $data;
    }   

    public function getSellerList($productid) {
        $customerId=Mage::getSingleton('customer/session')->getCustomerId();
        $collection=Mage::getModel('mpassignproduct/mpassignproduct')->getCollection();
        $collection->addFieldToFilter('product_id',array('eq'=>$productid));
        $i=0;
        foreach($collection as $item) {
            $sql2=Mage::getModel('marketplace/userprofile')->getPartnerProfileById($item['seller_id']);
            $item['logo']=$sql2['logopic'];
            $item['sellername']=$sql2['firstname']." ".$sql2['lastname'];
            $sql[$i]=$item;
            $i++;
        }
        return $sql;
    }

     public function detailsale($mageproid, $userid) {
        $data = array();
        $sum=0;
        $arr=array();
        $quantity = Mage::getModel('marketplace/saleslist')->getCollection()
                            ->addFieldToFilter('mageproid',array('eq'=>$mageproid))
                            ->addFieldToFilter('mageproownerid',array('eq'=>$userid));
        $data['quantitysoldconfirmed']=0;
        $data['quantitysoldpending']=0;
        foreach($quantity as $rec) {
            $status=$rec->getCpprostatus();
            $qty=$rec->getMagequantity();
            if($status==1) {
                    $data['quantitysoldconfirmed']=$data['quantitysoldconfirmed']+$qty;
            } else if($status==0) {
                    $data['quantitysoldpending']=$data['quantitysoldpending']+$qty;
            }
        }
        $amountearned = Mage::getModel('marketplace/saleslist')->getCollection()
                    ->addFieldToFilter('mageproid',array('eq'=>$mageproid))
                    ->addFieldToFilter('mageproownerid',array('eq'=>$userid));
        foreach($amountearned as $rec) {
            $sum=$sum+$rec->getactualparterprocost();
            $arr[]=$rec->getClearedAt();
        }
        $data['amountearned']=$sum;
        $data['clearedat']=$arr;
        $quantitysold = Mage::getModel('marketplace/saleslist')->getCollection()
                    ->addFieldToFilter('mageproid',$mageproid)
                    ->addFieldToFilter('mageproownerid',$userid);
        $data['quantitysold']=0;
        $data['quantitysold']=0;
        foreach($quantitysold as $rec) {
            $qty = $rec->getMagequantity(); 
            $data['quantitysold']=$data['quantitysold']+$qty;

        }
        return $data;
    }

    public function detsalebyid($productId, $userid) {
        $data = array();
        if($productId > 0) {
           $collection = Mage::getModel('marketplace/saleslist')->getCollection();
           $collection->addFieldToFilter('mageproid',array('eq'=>$productId));
            $collection->addFieldToFilter('mageproownerid',array('eq'=>$userid));
            $i=0;
            foreach ($collection as $record) {
                $data[$i]=array(
                            'magequantity'=>$record->getmagequantity(),
                            'actualparterprocost'=>$record->getactualparterprocost()
                        );
                $i++;
            }
            return $data;
        }
    }
}
1
+50

i think this is not the bug in this extension. this extension work like number of total number of quantity by all seller of that product. so in admin this is showing correct quantity for selling.

let me take your example.

seller A is base seller with 10 quantity and seller B assigned the same product with 5 quantity.

so the total number of quantity for the purchased is 15 quantity.

So its displaying 15 under Manage Products > quantity. that are correct.

if you change the main quantity to 10 of seller a you will lose your 5 quantity of seller b.

2

Try this:

<?php
  class Webkul_Mpassignproduct_Model_Mpassignproduct extends Mage_Core_Model_Abstract
{
    public function _construct() {
        parent::_construct();
        $this->_init('mpassignproduct/mpassignproduct');
    }

    public function editproduct($data)
    {
        $sellerId = Mage::getSingleton('customer/session')->getCustomerId();

        $products = Mage::getModel('mpassignproduct/mpassignproduct')->getCollection()
                            ->addFieldToFilter('seller_id',array('eq'=>$sellerId))
                            ->addFieldToFilter('mpassignproduct_id',array('eq'=>$data['pro_id']));
        if(count($products)) {
            foreach($products as $product) {
                $isApproved = $product->getFlag();
                $preQty = $product->getQty();
                $product->setQty($data['qty']+$product->getQty());
                $product->setPrice($data['price']);
                $product->setProductCondition($data['product_condition']);
                $product->setProductDescription($data['product_description']);
                $saved=$product->save();
                $lastId=$saved->getId();
            }
        }
        if($lastId)  {
            if($isApproved == 1) {
                $_product = Mage::getModel("catalog/product")->load($data['product_id']);
                $qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
                $qtyStock = ($qtyStock - $preQty) + $data['qty'];
                $this->_saveStock($data['product_id'],$qtyStock,1); 
            }
            $this->uploadImages($lastId);
        }

        return $lastId;
    }
}
5
  • i checked it, but same result.... Jan 20 '16 at 9:49
  • $isApproved=$product->getFlag(); can you exp?
    – Abdul
    Jan 20 '16 at 10:08
  • or which function call to update qty?
    – Abdul
    Jan 20 '16 at 10:09
  • i guess this is the function : :_saveStock($lastId,$stock,$isstock)" Jan 20 '16 at 10:11
  • sorry , i have no idea about this : "$isApproved=$product->getFlag();" as it is extension. Jan 20 '16 at 10:12

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.