diff --git a/app/code/community/Medma/MarketPlace/Block/Adminhtml/System/Convert/Gui/Grid.php b/app/code/community/Medma/MarketPlace/Block/Adminhtml/System/Convert/Gui/Grid.php
new file mode 100644
index 0000000..7a60a1a
--- /dev/null
+++ b/app/code/community/Medma/MarketPlace/Block/Adminhtml/System/Convert/Gui/Grid.php
@@ -0,0 +1,48 @@
+addFieldToFilter('entity_type', array('notnull'=>''));
+
+
+ $isVendor = Mage::helper('marketplace')->isVendor();//current user is vendor or not
+
+ if($isVendor)
+ {
+ $collection->addFieldToFilter('name',array('in'=>array('Vendor Import Products','Vendor Export Products')));
+ //$collection->addFieldToFilter('entity_type','product');
+ $this->setCollection($collection);
+ return $this;
+ }
+ else
+ {
+ $this->setCollection($collection);
+ return parent::_prepareCollection();
+ }
+
+
+ }
+
+}
+
diff --git a/app/code/community/Medma/MarketPlace/Block/Adminhtml/System/Convert/Profile/Edit/Tab/Run.php b/app/code/community/Medma/MarketPlace/Block/Adminhtml/System/Convert/Profile/Edit/Tab/Run.php
new file mode 100644
index 0000000..2deebfd
--- /dev/null
+++ b/app/code/community/Medma/MarketPlace/Block/Adminhtml/System/Convert/Profile/Edit/Tab/Run.php
@@ -0,0 +1,21 @@
+isVendor();//current user is vendor or not
+
+ $model = Mage::registry('current_convert_profile');
+
+ if($isVendor && $model->getDirection()=='export')
+ {
+ $this->setTemplate('marketplace/system/convert/profile/run.phtml');
+ }
+ }
+
+
+}
+?>
diff --git a/app/code/community/Medma/MarketPlace/Helper/Data.php b/app/code/community/Medma/MarketPlace/Helper/Data.php
index 61f3ae1..7c7fe2f 100644
--- a/app/code/community/Medma/MarketPlace/Helper/Data.php
+++ b/app/code/community/Medma/MarketPlace/Helper/Data.php
@@ -54,5 +54,45 @@ public function getVarificationProofTypeList()
return $proofType;
}
+
+
+ /**Check current user is a vendor**/
+ public function isVendor()
+ {
+ $result = '';
+
+ /**Fetch Current User Id**/
+ $user = Mage::getSingleton('admin/session');
+ $userId = $user->getUser()->getUserId();
+
+ /**Fetch Parent Id For Current Role**/
+ $role = Mage::getModel('admin/role')
+ ->getCollection()
+ ->addFieldToFilter('user_id',$userId)
+ ->getFirstItem();
+
+ $parentId = $role->getParentId();
+
+
+ /**Fetch Role Name of current parent id**/
+
+ $parentRole = Mage::getModel('admin/role')
+ ->getCollection()
+ ->addFieldToFilter('role_id',$parentId)
+ ->getFirstItem();
+
+ $roleName = $parentRole->getRoleName();
+
+ if($roleName == 'VENDORS')
+ {
+ $result = true;
+ }
+ else
+ {
+ $result = false;
+ }
+
+ return $result;
+ }
}
?>
diff --git a/app/code/community/Medma/MarketPlace/Model/Convert/Adapter/Product.php b/app/code/community/Medma/MarketPlace/Model/Convert/Adapter/Product.php
new file mode 100644
index 0000000..07c7f71
--- /dev/null
+++ b/app/code/community/Medma/MarketPlace/Model/Convert/Adapter/Product.php
@@ -0,0 +1,383 @@
+ 'type_id',
+ 'attribute_set' => 'attribute_set_id'
+ );
+
+ $filters = $this->_parseVars();
+
+ if ($qty = $this->getFieldValue($filters, 'qty')) {
+ $qtyFrom = isset($qty['from']) ? (float) $qty['from'] : 0;
+ $qtyTo = isset($qty['to']) ? (float) $qty['to'] : 0;
+
+ $qtyAttr = array();
+ $qtyAttr['alias'] = 'qty';
+ $qtyAttr['attribute'] = 'cataloginventory/stock_item';
+ $qtyAttr['field'] = 'qty';
+ $qtyAttr['bind'] = 'product_id=entity_id';
+ $qtyAttr['cond'] = "{{table}}.qty between '{$qtyFrom}' AND '{$qtyTo}'";
+ $qtyAttr['joinType'] = 'inner';
+
+ $this->setJoinField($qtyAttr);
+ }
+
+ parent::setFilter($attrFilterArray, $attrToDb);
+
+ if ($price = $this->getFieldValue($filters, 'price')) {
+ $this->_filter[] = array(
+ 'attribute' => 'price',
+ 'from' => $price['from'],
+ 'to' => $price['to']
+ );
+ $this->setJoinAttr(array(
+ 'alias' => 'price',
+ 'attribute' => 'catalog_product/price',
+ 'bind' => 'entity_id',
+ 'joinType' => 'LEFT'
+ ));
+ }
+
+
+ /**Start Code For Vendor**/
+ $isVendor = Mage::helper('marketplace')->isVendor();//current user is vendor or not
+
+ if($isVendor)
+ {
+ /**Fetch Current User Id**/
+ $user = Mage::getSingleton('admin/session');
+ $userId = $user->getUser()->getUserId();
+
+ $this->_filter[] = array(
+ 'attribute' => 'vendor',
+ 'eq' => $userId
+ );
+ }
+ /**End Code For Vendor**/
+
+ return parent::load();
+ }
+
+
+
+ /**
+ * Save product (import)
+ *
+ * @param array $importData
+ * @throws Mage_Core_Exception
+ * @return bool
+ */
+ public function saveRow(array $importData)
+ {
+ $product = $this->getProductModel()
+ ->reset();
+
+ if (empty($importData['store'])) {
+ if (!is_null($this->getBatchParams('store'))) {
+ $store = $this->getStoreById($this->getBatchParams('store'));
+ } else {
+ $message = Mage::helper('catalog')->__('Skipping import row, required field "%s" is not defined.', 'store');
+ Mage::throwException($message);
+ }
+ } else {
+ $store = $this->getStoreByCode($importData['store']);
+ }
+
+ if ($store === false) {
+ $message = Mage::helper('catalog')->__('Skipping import row, store "%s" field does not exist.', $importData['store']);
+ Mage::throwException($message);
+ }
+
+ if (empty($importData['sku'])) {
+ $message = Mage::helper('catalog')->__('Skipping import row, required field "%s" is not defined.', 'sku');
+ Mage::throwException($message);
+ }
+ $product->setStoreId($store->getId());
+ $productId = $product->getIdBySku($importData['sku']);
+
+ $isVendor = false;
+
+ if ($productId) {
+ $product->load($productId);
+
+ /**Start Code For Vendor**/
+ $isVendor = Mage::helper('marketplace')->isVendor();//current user is vendor or not
+
+ if($isVendor)
+ {
+ /**Fetch Current User Id**/
+ $user = Mage::getSingleton('admin/session');
+ $userId = $user->getUser()->getUserId();
+
+ if($userId != $product->getVendor())
+ {
+ $message = Mage::helper('catalog')->__("You are not allowed to update product with sku '".$product->getSku()."' because it's not created by you");
+ Mage::throwException($message);
+ }
+ else if(($importData['status']=='Enabled' || $importData['status']==1)&&$product->getStatus()==2)
+ {
+ //Mage::throwException($product->getStatus());
+ $importData['status'] = 'Disabled';
+ }
+
+ }
+ /**End Code For Vendor**/
+
+ } else {
+ $productTypes = $this->getProductTypes();
+ $productAttributeSets = $this->getProductAttributeSets();
+
+ /**Start Code For Vendor**/
+ $isVendor = Mage::helper('marketplace')->isVendor();//current user is vendor or not
+
+ if($isVendor)
+ {
+ $importData['status'] = 'Disabled';
+ }
+ /**End Code For Vendor**/
+
+
+ /**
+ * Check product define type
+ */
+ if (empty($importData['type']) || !isset($productTypes[strtolower($importData['type'])])) {
+ $value = isset($importData['type']) ? $importData['type'] : '';
+ $message = Mage::helper('catalog')->__('Skip import row, is not valid value "%s" for field "%s"', $value, 'type');
+ Mage::throwException($message);
+ }
+ $product->setTypeId($productTypes[strtolower($importData['type'])]);
+ /**
+ * Check product define attribute set
+ */
+ if (empty($importData['attribute_set']) || !isset($productAttributeSets[$importData['attribute_set']])) {
+ $value = isset($importData['attribute_set']) ? $importData['attribute_set'] : '';
+ $message = Mage::helper('catalog')->__('Skip import row, the value "%s" is invalid for field "%s"', $value, 'attribute_set');
+ Mage::throwException($message);
+ }
+ $product->setAttributeSetId($productAttributeSets[$importData['attribute_set']]);
+
+ foreach ($this->_requiredFields as $field) {
+ $attribute = $this->getAttribute($field);
+ if (!isset($importData[$field]) && $attribute && $attribute->getIsRequired()) {
+ $message = Mage::helper('catalog')->__('Skipping import row, required field "%s" for new products is not defined.', $field);
+ Mage::throwException($message);
+ }
+ }
+ }
+
+ $this->setProductTypeInstance($product);
+
+ if (isset($importData['category_ids'])) {
+ $product->setCategoryIds($importData['category_ids']);
+ }
+
+ foreach ($this->_ignoreFields as $field) {
+ if (isset($importData[$field])) {
+ unset($importData[$field]);
+ }
+ }
+
+ if ($store->getId() != 0) {
+ $websiteIds = $product->getWebsiteIds();
+ if (!is_array($websiteIds)) {
+ $websiteIds = array();
+ }
+ if (!in_array($store->getWebsiteId(), $websiteIds)) {
+ $websiteIds[] = $store->getWebsiteId();
+ }
+ $product->setWebsiteIds($websiteIds);
+ }
+
+ if (isset($importData['websites'])) {
+ $websiteIds = $product->getWebsiteIds();
+ if (!is_array($websiteIds) || !$store->getId()) {
+ $websiteIds = array();
+ }
+ $websiteCodes = explode(',', $importData['websites']);
+ foreach ($websiteCodes as $websiteCode) {
+ try {
+ $website = Mage::app()->getWebsite(trim($websiteCode));
+ if (!in_array($website->getId(), $websiteIds)) {
+ $websiteIds[] = $website->getId();
+ }
+ } catch (Exception $e) {}
+ }
+ $product->setWebsiteIds($websiteIds);
+ unset($websiteIds);
+ }
+
+ foreach ($importData as $field => $value) {
+ if (in_array($field, $this->_inventoryFields)) {
+ continue;
+ }
+ if (is_null($value)) {
+ continue;
+ }
+
+ $attribute = $this->getAttribute($field);
+ if (!$attribute) {
+ continue;
+ }
+
+ $isArray = false;
+ $setValue = $value;
+
+ if ($attribute->getFrontendInput() == 'multiselect') {
+ $value = explode(self::MULTI_DELIMITER, $value);
+ $isArray = true;
+ $setValue = array();
+ }
+
+ if ($value && $attribute->getBackendType() == 'decimal') {
+ $setValue = $this->getNumber($value);
+ }
+
+ if ($attribute->usesSource()) {
+ $options = $attribute->getSource()->getAllOptions(false);
+
+ if ($isArray) {
+ foreach ($options as $item) {
+ if (in_array($item['label'], $value)) {
+ $setValue[] = $item['value'];
+ }
+ }
+ } else {
+ $setValue = false;
+ foreach ($options as $item) {
+ if (is_array($item['value'])) {
+ foreach ($item['value'] as $subValue) {
+ if (isset($subValue['value']) && $subValue['value'] == $value) {
+ $setValue = $value;
+ }
+ }
+ } else if ($item['label'] == $value) {
+ $setValue = $item['value'];
+ }
+ }
+ }
+ }
+
+ $product->setData($field, $setValue);
+ }
+
+
+
+ if (!$product->getVisibility()) {
+ $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
+ }
+
+ $stockData = array();
+ $inventoryFields = isset($this->_inventoryFieldsProductTypes[$product->getTypeId()])
+ ? $this->_inventoryFieldsProductTypes[$product->getTypeId()]
+ : array();
+ foreach ($inventoryFields as $field) {
+ if (isset($importData[$field])) {
+ if (in_array($field, $this->_toNumber)) {
+ $stockData[$field] = $this->getNumber($importData[$field]);
+ } else {
+ $stockData[$field] = $importData[$field];
+ }
+ }
+ }
+ $product->setStockData($stockData);
+
+ $mediaGalleryBackendModel = $this->getAttribute('media_gallery')->getBackend();
+
+ $arrayToMassAdd = array();
+
+ foreach ($product->getMediaAttributes() as $mediaAttributeCode => $mediaAttribute) {
+ if (isset($importData[$mediaAttributeCode])) {
+ $file = trim($importData[$mediaAttributeCode]);
+ if (!empty($file) && !$mediaGalleryBackendModel->getImage($product, $file)) {
+ $arrayToMassAdd[] = array('file' => trim($file), 'mediaAttribute' => $mediaAttributeCode);
+ }
+ }
+ }
+
+ $addedFilesCorrespondence = $mediaGalleryBackendModel->addImagesWithDifferentMediaAttributes(
+ $product,
+ $arrayToMassAdd, Mage::getBaseDir('media') . DS . 'import',
+ false,
+ false
+ );
+
+ foreach ($product->getMediaAttributes() as $mediaAttributeCode => $mediaAttribute) {
+ $addedFile = '';
+ if (isset($importData[$mediaAttributeCode . '_label'])) {
+ $fileLabel = trim($importData[$mediaAttributeCode . '_label']);
+ if (isset($importData[$mediaAttributeCode])) {
+ $keyInAddedFile = array_search($importData[$mediaAttributeCode],
+ $addedFilesCorrespondence['alreadyAddedFiles']);
+ if ($keyInAddedFile !== false) {
+ $addedFile = $addedFilesCorrespondence['alreadyAddedFilesNames'][$keyInAddedFile];
+ }
+ }
+
+ if (!$addedFile) {
+ $addedFile = $product->getData($mediaAttributeCode);
+ }
+ if ($fileLabel && $addedFile) {
+ $mediaGalleryBackendModel->updateImage($product, $addedFile, array('label' => $fileLabel));
+ }
+ }
+ }
+
+ $product->setIsMassupdate(true);
+ $product->setExcludeUrlRewrite(true);
+
+
+ /**Code For Vendor**/
+ if($isVendor)
+ {
+ /**Fetch Current User Id**/
+ $user = Mage::getSingleton('admin/session');
+ $userId = $user->getUser()->getUserId();
+
+ $product->setVendor($userId);
+ }
+
+ $product->save();
+
+ // Store affected products ids
+ $this->_addAffectedEntityIds($product->getId());
+
+ return true;
+ }
+
+}
diff --git a/app/code/community/Medma/MarketPlace/Model/Dataflow/Convert/Adapter/Io.php b/app/code/community/Medma/MarketPlace/Model/Dataflow/Convert/Adapter/Io.php
new file mode 100644
index 0000000..55a2f81
--- /dev/null
+++ b/app/code/community/Medma/MarketPlace/Model/Dataflow/Convert/Adapter/Io.php
@@ -0,0 +1,68 @@
+getResource(true)) {
+ return $this;
+ }
+
+ $batchModel = Mage::getSingleton('dataflow/batch');
+
+ $dataFile = $batchModel->getIoAdapter()->getFile(true);
+
+ $filename = $this->getVar('filename');
+
+ /**Start Code For Vendor**/
+ $isVendor = Mage::helper('marketplace')->isVendor();//current user is vendor or not
+
+ if($isVendor)
+ {
+ /**Fetch Current User Name**/
+ $user = Mage::getSingleton('admin/session');
+ $userName = $user->getUser()->getUsername();
+
+ $filename = 'export_product_'.$userName.'.csv';
+ }
+ /**End Code For Vendor**/
+
+ $result = $this->getResource()->write($filename, $dataFile, 0777);
+
+ if (false === $result) {
+ $message = Mage::helper('dataflow')->__('Could not save file: %s.', $filename);
+ Mage::throwException($message);
+ } else {
+
+ /**Start Code For Vendor**/
+ if($isVendor)
+ {
+ $localpath = 'vendor/';
+ //create path if not exist
+ if (!file_exists($localpath)) {
+ mkdir($localpath, 0777, true);
+ }
+ $fileWithPath = $localpath.'/'.$filename;
+
+ $localResource = new Varien_Io_File();
+
+ $localResource->write($fileWithPath, $dataFile, 0777);
+
+ }
+ /**End Code For Vendor**/
+
+
+ $message = Mage::helper('dataflow')->__('Saved successfully: "%s" [%d byte(s)].', $filename, $batchModel->getIoAdapter()->getFileSize());
+ if ($this->getVar('link')) {
+ $message .= Mage::helper('dataflow')->__('Link', $this->getVar('link'));
+ }
+ $this->addException($message);
+ }
+ return $this;
+ }
+}
+
diff --git a/app/code/community/Medma/MarketPlace/Model/Dataflow/Profile.php b/app/code/community/Medma/MarketPlace/Model/Dataflow/Profile.php
new file mode 100644
index 0000000..124c7e2
--- /dev/null
+++ b/app/code/community/Medma/MarketPlace/Model/Dataflow/Profile.php
@@ -0,0 +1,295 @@
+setGuiData($p);
+
+ $xml = '
" . print_r($p,1) . ""; +echo "