Esempio n. 1
0
 protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
 {
     // CHECK IF ATTRIBUTE EXISTS
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $attribute_id = $eavAttribute->getIdByCode('catalog_product', 'created_at');
     if ($attribute_id) {
         $attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'created_at');
         $sort = $attributeModel['used_for_sort_by'];
         if ($sort) {
             $installed = '1';
             $url = $this->getUrl('*/updatesort/index');
             $button_title = Mage::helper('sortbydate')->__('Remove as listing option');
         } else {
             $installed = '0';
             $url = $this->getUrl('*/updatesort/index');
             $button_title = Mage::helper('sortbydate')->__('Add as listing option');
         }
     } else {
         $installed = '0';
         $url = $this->getUrl('*/updatesort/index');
         $button_title = Mage::helper('sortbydate')->__('Add as listing option');
     }
     $this->setElement($element);
     $html = $this->getLayout()->createBlock('adminhtml/widget_button')->setType('button')->setClass('scalable')->setLabel($button_title)->setOnClick("setLocation('{$url}')")->toHtml();
     return $html;
 }
Esempio n. 2
0
 private function _prepareCollection()
 {
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $supplier_id = Mage::helper('marketplace')->getSupplierId();
     $code = $eavAttribute->getIdByCode('catalog_product', 'creator_id');
     $intEntityName = Mage::getSingleton("core/resource")->getTableName('catalog_product_entity_int');
     $orderItemTable = Mage::getSingleton('core/resource')->getTableName('sales/order_item');
     $collection = Mage::getModel('sales/order')->getCollection();
     $collection->getSelect()->distinct()->joinInner(array('i' => $orderItemTable), 'i.order_id = main_table.entity_id', array('SUM(i.qty_ordered) AS sold_count', 'COUNT(item_id) AS item_count', 'SUM(price) AS sum_price', 'SUM(price-(price*((i.vendor_fee)/100))) AS vendor_income', 'product_id'))->joinInner(array('e' => $intEntityName), 'e.entity_id = i.product_id AND e.attribute_id = ' . $code, array())->where('i.parent_item_id is null')->where('e.value = ?', $supplier_id);
     if ($this->getFilter('from') && strtotime($this->getFilter('from'))) {
         $datetime = new DateTime($this->getFilter('from'));
         $collection->getSelect()->where('main_table.created_at >= ?', $datetime->format('Y-m-d') . " 00:00:00");
     }
     if ($this->getFilter('to') && strtotime($this->getFilter('to'))) {
         $datetime = new DateTime($this->getFilter('to'));
         $collection->getSelect()->where('main_table.created_at <= ?', $datetime->format('Y-m-d') . " 23:59:59");
     }
     switch ($this->getFilter('period_type')) {
         case 'day':
             $collection->getSelect()->group('DAY(main_table.created_at)');
             break;
         case 'month':
             $collection->getSelect()->group('MONTH(main_table.created_at)');
             break;
         case 'year':
             $collection->getSelect()->group('YEAR(main_table.created_at)');
             break;
         default:
             break;
     }
     return $collection;
 }
Esempio n. 3
0
 public function getFlatCollection()
 {
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $supplier_id = Mage::helper('marketplace')->getSupplierId();
     $code = $eavAttribute->getIdByCode('catalog_product', 'creator_id');
     $table = "catalog_product_entity_int";
     $tableName = Mage::getSingleton("core/resource")->getTableName($table);
     $orderTable = Mage::getSingleton('core/resource')->getTableName('sales/order');
     $collection = Mage::getModel('sales/order_item')->getCollection();
     $collection->getSelect()->joinInner(array('o' => $orderTable), 'o.entity_id = main_table.order_id', array())->joinInner(array('e' => $tableName), 'e.entity_id = main_table.product_id AND e.attribute_id = ' . $code, array())->where('main_table.parent_item_id is null')->where('e.value = ?', $supplier_id)->group('o.entity_id')->order('o.entity_id DESC');
     if ($this->getFilter('autoincrement_id')) {
         $collection->getSelect()->where('o.increment_id LIKE ?', "%" . $this->getFilter('autoincrement_id') . "%");
     }
     if ($this->getFilter('status')) {
         $collection->getSelect()->where('o.status = ?', $this->getFilter('status'));
     }
     if ($this->getFilter('from') && strtotime($this->getFilter('from'))) {
         $datetime = new DateTime($this->getFilter('from'));
         $collection->getSelect()->where('main_table.created_at >= ?', $datetime->format('Y-m-d') . " 00:00:00");
     }
     if ($this->getFilter('to') && strtotime($this->getFilter('to'))) {
         $datetime = new DateTime($this->getFilter('to'));
         $collection->getSelect()->where('main_table.created_at <= ?', $datetime->format('Y-m-d') . " 23:59:59");
     }
     return $collection;
 }
Esempio n. 4
0
 public function addOption($brand)
 {
     //        $op = Mage::getModel('eav/entity_attribute_option')->load($brand->getOptionId());
     $prefix = Mage::helper('shopbybrand')->getTablePrefix();
     $attributeCode = Mage::helper('shopbybrand/brand')->getAttributeCode();
     $brandStoreId = 0;
     if ($brand->getOptionId()) {
         if ($brand->getStoreId()) {
             $brandStoreId = $brand->getStoreId();
         }
         $select = $this->_getReadAdapter()->select()->from(array('eao' => $prefix . 'eav_attribute_option'), array('option_id', 'eaov.value', 'eaov.store_id'))->join(array('ea' => $prefix . 'eav_attribute'), 'eao.attribute_id=ea.attribute_id', array())->join(array('eaov' => $prefix . 'eav_attribute_option_value'), 'eao.option_id=eaov.option_id', array())->where('ea.attribute_code=?', $attributeCode)->where('eao.option_id=?', $brand->getOptionId())->where('eaov.store_id=?', $brandStoreId);
         $storeValue = $this->_getReadAdapter()->fetchAll($select);
         if (count($storeValue)) {
             foreach ($storeValue as $value) {
                 if (isset($value['value']) && $value['value']) {
                     if ($value['value'] == $brand->getName()) {
                         return;
                     } else {
                         $data = array('value' => $brand->getName());
                         $where = array('option_id=?' => $brand->getOptionId(), 'store_id=?' => $brandStoreId);
                         $update = $this->_getWriteAdapter()->update($prefix . 'eav_attribute_option_value', $data, $where);
                     }
                 }
             }
         } else {
             $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
             $attId = $eavAttribute->getIdByCode('catalog_product', $attributeCode);
             $data = array('value' => $brand->getName(), 'option_id' => $brand->getOptionId(), 'store_id' => $brandStoreId);
             $select = $this->_getReadAdapter()->select()->from(array('eao' => $prefix . 'eav_attribute_option'), array('option_id'))->join(array('ea' => $prefix . 'eav_attribute'), 'eao.attribute_id=ea.attribute_id', array())->where('ea.attribute_code=?', $attributeCode)->where('eao.option_id=?', $brand->getOptionId());
             $storeValue = $this->_getReadAdapter()->fetchAll($select);
             if (count($storeValue) == 0) {
                 $optionData = array('option_id' => $brand->getOptionId(), 'attribute_id' => $attId, 'sort_order' => 0);
                 $option = $this->_getWriteAdapter()->insert($prefix . 'eav_attribute_option', $optionData);
             }
             try {
                 $update = $this->_getWriteAdapter()->insert($prefix . 'eav_attribute_option_value', $data);
             } catch (Exception $e) {
             }
         }
     } else {
         $attributeId = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode)->getId();
         $setup = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('catalog_setup');
         $option['attribute_id'] = $attributeId;
         if ($brand->getStoreId()) {
             $option['value']['option'][$brand->getStoreId()] = $brand->getName();
         } else {
             $option['value']['option'][0] = $brand->getName();
         }
         $setup->addAttributeOption($option);
         //get option id
         $select = $this->_getReadAdapter()->select()->from(array('eao' => $prefix . 'eav_attribute_option'), array('option_id', 'eaov.value', 'eaov.store_id'))->join(array('ea' => $prefix . 'eav_attribute'), 'eao.attribute_id=ea.attribute_id', array())->join(array('eaov' => $prefix . 'eav_attribute_option_value'), 'eao.option_id=eaov.option_id', array())->where('ea.attribute_code=?', $attributeCode)->where('eaov.value=?', $brand->getName())->where('eaov.store_id=?', $brandStoreId);
         $option = $this->_getReadAdapter()->fetchAll($select);
         if (count($option)) {
             $optionId = $option[0]['option_id'];
             return $optionId;
         }
     }
     return null;
 }
Esempio n. 5
0
 protected function _prepareCollection()
 {
     $collection = Mage::getModel('marketplace/product')->getCollection();
     if ($this->getRequest()->getParam('unapp') == 1) {
         $collection->addFieldToFilter('status', array('neq' => '1'));
     }
     $customerModel = Mage::getModel('customer/customer');
     $prefix = Mage::getConfig()->getTablePrefix();
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $pro_att_id = $eavAttribute->getIdByCode("catalog_product", "name");
     $fnameid = Mage::getModel("eav/entity_attribute")->loadByCode("1", "firstname")->getAttributeId();
     $lnameid = Mage::getModel("eav/entity_attribute")->loadByCode("1", "lastname")->getAttributeId();
     $collection->getSelect()->join(array("ce1" => $prefix . "customer_entity_varchar"), "ce1.entity_id = main_table.userid", array("fname" => "value"))->where("ce1.attribute_id = " . $fnameid)->join(array("ce2" => $prefix . "customer_entity_varchar"), "ce2.entity_id = main_table.userid", array("lname" => "value"))->where("ce2.attribute_id = " . $lnameid)->columns(new Zend_Db_Expr("CONCAT(`ce1`.`value`, ' ',`ce2`.`value`) AS fullname"));
     $collection->addFilterToMap("fullname", "`ce1`.`value`");
     $pro_att_id = $eavAttribute->getIdByCode("catalog_product", "name");
     $collection->getSelect()->join(array("pn" => $prefix . "catalog_product_entity_varchar"), "pn.entity_id = main_table.mageproductid", array("proname" => "value"))->where("pn.attribute_id = " . $pro_att_id . " AND pn.store_id = " . Mage::app()->getStore()->getStoreId());
     $collection->addFilterToMap("proname", "pn.value");
     // $price_att_id = $eavAttribute->getIdByCode("catalog_product","price");
     // $collection->getSelect()
     // ->join(array("pp" => $prefix."catalog_product_entity_decimal"),"pp.entity_id = main_table.mageproductid",array("price" => "value"))->where("pp.attribute_id = ".$price_att_id. " AND pn.store_id = ".Mage::app()->getStore()->getStoreId());
     // $collection->addFilterToMap("price","pp.value");
     // $collection->getSelect()->joinLeft($prefix."cataloginventory_stock_item","main_table.mageproductid = ".$prefix."cataloginventory_stock_item.product_id",array("qty"=>"qty"));
     $collection->getSelect()->joinLeft($prefix . "catalog_product_entity", "main_table.mageproductid = " . $prefix . "catalog_product_entity.entity_id", array("created_at" => "created_at"));
     $this->setCollection($collection);
     parent::_prepareCollection();
     //Modify loaded collection
     foreach ($this->getCollection() as $item) {
         $item->deny = sprintf('<button type="button" class="wk_denyproduct" customer-id ="%s" product-id="%s"><span><span title="Deny">Deny</span></span></button>', $item->getuserid(), $item->getMageproductid());
         $item->prev = sprintf('<span data="%s" product-id="%s" customer-id="%s" title="Click to Review" class="prev btn">prev</span>', $this->getUrl('marketplace/prev/index/id/' . $item->getMageproductid()), $item->getMageproductid(), $item->getuserid());
         $item->entity_id = (int) $item->getmageproductid();
         if (!is_null($item->getmageproductid()) && $item->getmageproductid() != 0) {
             if ($item->getstatus() == 1) {
                 $item->status = sprintf('<a href="%s" title="View product">Approved</a>', $this->getUrl('adminhtml/catalog_product/edit/id/' . $item->getmageproductid()));
             } else {
                 $item->status = sprintf('<a href="%s" title="Click to Approve" onclick="return confirm(\'You sure?\')">Unapproved</a>', $this->getUrl('marketplace/adminhtml_products/approve/id/' . $item->getmageproductid()));
             }
             $product = Mage::getModel('catalog/product')->load($item->getmageproductid());
             $item->price = $product->getPrice();
             $stock_inventory = Mage::getModel('cataloginventory/stock_item')->loadByProduct($item->getmageproductid());
             $item->weight = $product->getWeight();
             $item->qty = $stock_inventory->getQty();
             $item->stock = $stock_inventory->getQty();
             $quantity = Mage::getModel('marketplace/saleslist')->getSalesdetail($item->getmageproductid());
             $item->qty_sold = (int) $quantity['quantitysold'];
             $item->qty_soldconfirmed = (int) $quantity['quantitysoldconfirmed'];
             $symbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
             $item->qty_soldpending = (int) $quantity['quantitysoldpending'];
             $item->amount_earned = $symbol . $quantity['amountearned'];
             foreach ($quantity['clearedat'] as $clear) {
                 if (isset($clear) && $clear != '0000-00-00 00:00:00') {
                     $item->cleared_at = $clear;
                 }
             }
         }
     }
 }
Esempio n. 6
0
 public function setDateRange($from, $to)
 {
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $code = $eavAttribute->getIdByCode('catalog_product', 'creator_id');
     $table = "catalog_product_entity_int";
     $tableName = Mage::getSingleton("core/resource")->getTableName($table);
     $this->_reset();
     $this->getSelect()->joinInner(array('i' => $this->getTable('sales/order_item')), 'i.order_id = main_table.entity_id')->joinInner(array('e' => $tableName), 'e.entity_id = i.product_id AND e.attribute_id = ' . $code)->where('i.parent_item_id is null')->where("i.created_at BETWEEN '" . $from . "' AND '" . $to . "'")->where('main_table.state = \'complete\'')->columns(array('ordered_qty' => 'count(distinct `main_table`.`entity_id`)'));
     return $this;
 }
 /**
  * Updates the products that have failed to export.
  *
  * @param array $successIds
  *
  * @return void
  */
 protected function _updateFailedImports($failureIds)
 {
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $attrId = $eavAttribute->getIdByCode('catalog_product', 'export_failures');
     $resource = Mage::getSingleton('core/resource');
     $write = $resource->getConnection('core_write');
     $cpei = $resource->getTableName('catalog_product_entity_int');
     $sql = "UPDATE " . $cpei . " cpei\n                SET\n                cpei.value = cpei.value + 1\n                WHERE\n                cpei.entity_id = ? AND cpei.attribute_id = ?;";
     foreach ($failureIds as $failureId) {
         $write->query($sql, array($failureId, $attrId));
     }
 }
Esempio n. 8
0
 private function _prepareCollection()
 {
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $supplier_id = Mage::helper('supplierfrontendproductuploader')->getSupplierId();
     $code = $eavAttribute->getIdByCode('catalog_product', 'creator_id');
     $table = "catalog_product_entity_int";
     $tableName = Mage::getSingleton("core/resource")->getTableName($table);
     $orderItemTable = Mage::getSingleton('core/resource')->getTableName('sales/order_item');
     $collection = Mage::getModel('sales/order')->getCollection();
     $collection->getSelect()->joinInner(array('i' => $orderItemTable), 'i.order_id = main_table.entity_id', array())->joinInner(array('e' => $tableName), 'e.entity_id = i.product_id AND e.attribute_id = ' . $code, array())->where('i.parent_item_id is null')->where('e.value = ?', $supplier_id)->where('main_table.state = \'complete\'');
     return $collection;
 }
Esempio n. 9
0
 protected function _prepareCollection()
 {
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $supplier_id = Mage::registry('current_customer')->getId();
     $code = $eavAttribute->getIdByCode('catalog_product', 'creator_id');
     $table = "catalog_product_entity_int";
     $tableName = Mage::getSingleton("core/resource")->getTableName($table);
     $orderTable = Mage::getSingleton('core/resource')->getTableName('sales/order');
     $collection = Mage::getModel('sales/order_item')->getCollection();
     $collection->getSelect()->joinInner(array('o' => $orderTable), 'o.entity_id = main_table.order_id', array("CONCAT(`customer_firstname`, ' ', `customer_lastname`) AS customer_name", ""))->joinInner(array('e' => $tableName), 'e.entity_id = main_table.product_id AND e.attribute_id = ' . $code, array())->where('main_table.parent_item_id is null')->where('e.value = ?', $supplier_id)->group('o.entity_id');
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
 public function setCollection($collection, $excludeExisting = false)
 {
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $this->_attributeCode = $eavAttribute->getIdByCode('catalog_product', "factfinder_updated");
     $this->_updateTime = date('Y-m-d H:i:s', strtotime('+30 minutes'));
     $this->_collection = $collection;
     $attributesString = Mage::getStoreConfig('kirchbergerknorr/factfindersync/attributes');
     $keyValAttrString = Mage::getStoreConfig('kirchbergerknorr/factfindersync/key_attributes');
     $attributes = explode(',', $attributesString);
     $keyValAttr = explode(',', $keyValAttrString);
     foreach ($attributes as $attribute) {
         $collection->addAttributeToSelect($attribute);
     }
     $this->_products = array();
     $this->_ids = array();
     $storeId = 1;
     $exportImageAndDeeplink = Mage::getStoreConfigFlag('factfinder/export/urls', $storeId);
     if ($exportImageAndDeeplink) {
         $imageType = Mage::getStoreConfig('factfinder/export/suggest_image_type', $storeId);
         $imageSize = (int) Mage::getStoreConfig('factfinder/export/suggest_image_size', $storeId);
     }
     foreach ($collection as $product) {
         $productAttributes = array();
         foreach ($attributes as $attribute) {
             $attribute = trim($attribute);
             if ($attribute) {
                 $productAttributes[] = $product->getData($attribute);
             }
         }
         if ($this->searchId($product->getId())) {
             $this->updateProductsDates(array($product->getId()), $this->_updateTime);
             continue;
         }
         $product->setStoreId($storeId);
         $this->_ids[] = $product->getId();
         $productData = array('id' => $product->getId(), 'record' => array(array('key' => 'id', 'value' => $product->getId()), array('key' => 'sku', 'value' => $product->getSku()), array('key' => 'price', 'value' => (double) $product->getPrice()), array('key' => 'name', 'value' => $product->getName()), array('key' => 'description', 'value' => $product->getDescription()), array('key' => 'short_description', 'value' => $product->getShortDescription()), array('key' => 'deeplink', 'value' => $product->getProductUrl()), array('key' => 'meta_description', 'value' => $product->getMetaDescription()), array('key' => 'category', 'value' => $this->_getCategoryName($product)), array('key' => 'image', 'value' => (string) Mage::helper('catalog/image')->init($product, $imageType)->resize($imageSize)), array('key' => 'filterable_attributes', 'value' => "")), 'refKey' => time(), 'simiMalusAdd' => 1, 'simiMalusMul' => 1, 'visible' => true);
         foreach ($keyValAttr as $attr) {
             if ($product->getData($attr)) {
                 $productData['record'][] = array('key' => $attr, 'value' => $product->getData($attr));
             }
         }
         if (is_array($productAttributes) && count($productAttributes) > 0) {
             $productData['record'][] = array('key' => 'searchable_attributes', 'value' => join(" ", $productAttributes));
         }
         $this->_products[] = $productData;
     }
     return sizeof($this->_ids);
 }
Esempio n. 11
0
 public function getCategoryList()
 {
     $sellerid = $this->getProfileDetail()->getmageuserid();
     $products = Mage::getModel('marketplace/product')->getCollection()->addFieldToFilter('userid', array('eq' => $sellerid))->addFieldToFilter('status', array('neq' => 2))->addFieldToSelect('mageproductid');
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $pro_att_id = $eavAttribute->getIdByCode("catalog_category", "name");
     $storeId = Mage::app()->getStore()->getStoreId();
     //if(!$_GET["c"]){
     $parentid = Mage::app()->getStore($storeId)->getRootCategoryId();
     // }else{
     // 	$parentid = $_GET["c"];
     // }
     $prefix = Mage::getConfig()->getTablePrefix();
     $products->getSelect()->join(array("ccp" => $prefix . "catalog_category_product"), "ccp.product_id = main_table.mageproductid", array("category_id" => "category_id"))->join(array("cce" => $prefix . "catalog_category_entity"), "cce.entity_id = ccp.category_id", array("parent_id" => "parent_id"))->where("cce.parent_id = '" . $parentid . "'")->columns('COUNT(*) AS countCategory')->group('category_id')->join(array("ce1" => $prefix . "catalog_category_entity_varchar"), "ce1.entity_id = ccp.category_id", array("name" => "value"))->where("ce1.attribute_id = " . $pro_att_id)->order('name');
     return $products;
 }
Esempio n. 12
0
 protected function _saveOption(Mage_Core_Model_Abstract $object)
 {
     $option = $object->getOption();
     if (!isset($option['parent'])) {
         return parent::_saveOption($object);
     }
     if (is_array($option)) {
         $write = $this->_getWriteAdapter();
         $optionTable = $this->getTable('attribute_option');
         $optionValueTable = $this->getTable('attribute_option_value');
         $stores = Mage::getModel('core/store')->getResourceCollection()->setLoadDefault(true)->load();
         if (isset($option['value'])) {
             $attributeDefaultValue = array();
             if (!is_array($object->getDefault())) {
                 $object->setDefault(array());
             }
             foreach ($option['value'] as $optionId => $values) {
                 $intOptionId = (int) $optionId;
                 if (!empty($option['delete'][$optionId])) {
                     if ($intOptionId) {
                         $condition = $write->quoteInto('option_id=?', $intOptionId);
                         $write->delete($optionTable, $condition);
                     }
                     continue;
                 }
                 if (!$intOptionId) {
                     $data = array('attribute_id' => $object->getId(), 'sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0, 'parent_option_id' => isset($option['parent'][$optionId]) ? $option['parent'][$optionId] : 0);
                     $write->insert($optionTable, $data);
                     $intOptionId = $write->lastInsertId();
                 } else {
                     $data = array('sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0, 'parent_option_id' => isset($option['parent'][$optionId]) ? $option['parent'][$optionId] : 0);
                     $write->update($optionTable, $data, $write->quoteInto('option_id=?', $intOptionId));
                 }
                 if (in_array($optionId, $object->getDefault())) {
                     if ($object->getFrontendInput() == 'multiselect') {
                         $attributeDefaultValue[] = $intOptionId;
                     } else {
                         if ($object->getFrontendInput() == 'select') {
                             $attributeDefaultValue = array($intOptionId);
                         }
                     }
                 }
                 // Default value
                 if (!isset($values[0])) {
                     Mage::throwException(Mage::helper('eav')->__('Default option value is not defined.'));
                 }
                 $write->delete($optionValueTable, $write->quoteInto('option_id=?', $intOptionId));
                 foreach ($stores as $store) {
                     if (isset($values[$store->getId()]) && (!empty($values[$store->getId()]) || $values[$store->getId()] == "0")) {
                         $data = array('option_id' => $intOptionId, 'store_id' => $store->getId(), 'value' => $values[$store->getId()]);
                         $write->insert($optionValueTable, $data);
                     }
                 }
             }
             $write->update($this->getMainTable(), array('default_value' => implode(',', $attributeDefaultValue)), $write->quoteInto($this->getIdFieldName() . '=?', $object->getId()));
         }
     }
     return $this;
 }
 /**
  * Perform actions before object save
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Attribute
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     $applyTo = $object->getApplyTo();
     if (is_array($applyTo)) {
         $object->setApplyTo(implode(',', $applyTo));
     }
     return parent::_beforeSave($object);
 }
 /**
  * Perform actions before object save
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Customer_Model_Entity_Attribute
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     $inputFilter = $object->getInputFilter();
     if (is_array($inputFilter)) {
         $object->setInputFilter(implode(',', $inputFilter));
     }
     return parent::_beforeSave($object);
 }
Esempio n. 15
0
 protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
 {
     // CHECK IF ATTRIBUTE EXISTS
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $attribute_id = $eavAttribute->getIdByCode('catalog_product', 'created_at');
     if ($attribute_id) {
         $attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'created_at');
         $sort = $attributeModel['used_for_sort_by'];
         if ($sort) {
             $html = '<strong>' . Mage::helper('sortbydate')->__('Installed!') . '</strong>';
         } else {
             $html = '<strong>' . Mage::helper('sortbydate')->__('Not Installed') . '</strong>';
         }
     } else {
         $html = '<strong>' . Mage::helper('sortbydate')->__('Not Installed') . '</strong>';
     }
     return $html;
 }
 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->detectMagento($output);
     if ($this->initMagento()) {
         $eavAttribute = new \Mage_Eav_Model_Mysql4_Entity_Attribute();
         $thumbnailAttrId = $eavAttribute->getIdByCode('catalog_product', 'thumbnail');
         $smallImageAttrId = $eavAttribute->getIdByCode('catalog_product', 'small_image');
         $imageAttrId = $eavAttribute->getIdByCode('catalog_product', 'image');
         $mediaGalleryAttributeId = $eavAttribute->getIdByCode('catalog_product', 'media_gallery');
         $prefix_table = \Mage::getConfig()->getTablePrefix();
         $dialog = $this->getHelperSet()->get('dialog');
         $resource = \Mage::getModel('core/resource');
         $db = $resource->getConnection('core_write');
         $dryRun = $dialog->askConfirmation($output, '<question>Dry run?</question> <comment>[no]</comment> ', false);
         $products = $db->fetchAll('SELECT sku,entity_id FROM ' . $prefix_table . 'catalog_product_entity');
         foreach ($products as $product) {
             $chooseDefaultImage = false;
             $images = $db->fetchAll('select * from ' . $prefix_table . 'catalog_product_entity_varchar where `entity_id` = ? AND (`attribute_id` = ? OR `attribute_id` = ? OR `attribute_id` = ?)', array($product['entity_id'], $imageAttrId, $smallImageAttrId, $thumbnailAttrId));
             if (count($images) == 0) {
                 $chooseDefaultImage = true;
             } else {
                 foreach ($images as $image) {
                     if ($image['value'] == 'no_selection') {
                         $chooseDefaultImage = true;
                         break;
                     }
                 }
             }
             if ($chooseDefaultImage) {
                 $defaultImage = $db->fetchOne('SELECT value FROM ' . $prefix_table . 'catalog_product_entity_media_gallery WHERE entity_id = ? AND attribute_id = ? LIMIT 1', array($product['entity_id'], $mediaGalleryAttributeId));
                 if ($defaultImage && !$dryRun) {
                     $db->query('INSERT INTO ' . $prefix_table . 'catalog_product_entity_varchar SET entity_type_id = ?, attribute_id = ?, store_id = ?, entity_id = ?, value = ? ON DUPLICATE KEY UPDATE value = ?', array(4, $imageAttrId, 0, $product['entity_id'], $defaultImage, $defaultImage));
                     $db->query('INSERT INTO ' . $prefix_table . 'catalog_product_entity_varchar SET entity_type_id = ?, attribute_id = ?, store_id = ?, entity_id = ?, value = ? ON DUPLICATE KEY UPDATE value = ?', array(4, $smallImageAttrId, 0, $product['entity_id'], $defaultImage, $defaultImage));
                     $db->query('INSERT INTO ' . $prefix_table . 'catalog_product_entity_varchar SET entity_type_id = ?, attribute_id = ?, store_id = ?, entity_id = ?, value = ? ON DUPLICATE KEY UPDATE value = ?', array(4, $thumbnailAttrId, 0, $product['entity_id'], $defaultImage, $defaultImage));
                     $output->writeln('New default image has been set for ' . $product['sku']);
                 } elseif ($defaultImage) {
                     $output->writeln('New default image would be set for ' . $product['sku']);
                 }
             }
         }
     }
 }
 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->detectMagento($output);
     if ($this->initMagento()) {
         $eavAttribute = new \Mage_Eav_Model_Mysql4_Entity_Attribute();
         $thumbnailAttrId = $eavAttribute->getIdByCode('catalog_product', 'thumbnail');
         $smallImageAttrId = $eavAttribute->getIdByCode('catalog_product', 'small_image');
         $imageAttrId = $eavAttribute->getIdByCode('catalog_product', 'image');
         $prefix_table = \Mage::getConfig()->getTablePrefix();
         $dialog = $this->getHelperSet()->get('dialog');
         $resource = \Mage::getModel('core/resource');
         $db = $resource->getConnection('core_write');
         $cleanUpTableRowsMediaGallery = $dialog->askConfirmation($output, '<question>Clean catalog_product_entity_media_gallery(_value)?</question> <comment>[yes]</comment> ', true);
         $cleanUpTableRowsVarchar = $dialog->askConfirmation($output, '<question>Clean catalog_product_entity_varchar?</question> <comment>[yes]</comment> ', true);
         $dryRun = $dialog->askConfirmation($output, '<question>Dry run?</question> <comment>[no]</comment> ', false);
         if ($cleanUpTableRowsMediaGallery) {
             /* Clean up images from media gallery tables */
             $images = $db->fetchAll('SELECT value,value_id FROM ' . $prefix_table . 'catalog_product_entity_media_gallery');
             foreach ($images as $image) {
                 if (!file_exists(\Mage::getBaseDir('media') . DS . 'catalog' . DS . 'product' . $image['value'])) {
                     $output->writeln($image['value'] . ' does not exist on disk; deleting row from database.');
                     if (!$dryRun) {
                         $db->query('DELETE FROM ' . $prefix_table . 'catalog_product_entity_media_gallery WHERE value_id = ?', $image['value_id']);
                         $db->query('DELETE FROM ' . $prefix_table . 'catalog_product_entity_media_gallery_value WHERE value_id = ?', $image['value_id']);
                     }
                 }
             }
         }
         if ($cleanUpTableRowsVarchar) {
             /* Clean up images from varchar table */
             $images = $db->fetchAll('SELECT value,value_id FROM ' . $prefix_table . 'catalog_product_entity_varchar WHERE attribute_id = ? OR attribute_id = ? OR attribute_id = ?', array($thumbnailAttrId, $smallImageAttrId, $imageAttrId));
             foreach ($images as $image) {
                 if (!file_exists(\Mage::getBaseDir('media') . DS . 'catalog' . DS . 'product' . $image['value'])) {
                     $output->writeln($image['value'] . ' does not exist on disk; deleting row from database.');
                     if (!$dryRun) {
                         $db->query('DELETE FROM ' . $prefix_table . 'catalog_product_entity_varchar WHERE value_id = ?', $image['value_id']);
                     }
                 }
             }
         }
     }
 }
Esempio n. 18
0
 protected function _prepareCollection()
 {
     $collection = Mage::getModel('mpassignproduct/mpassignproduct')->getCollection();
     $customerModel = Mage::getModel('customer/customer');
     $prefix = Mage::getConfig()->getTablePrefix();
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $pro_att_id = $eavAttribute->getIdByCode("catalog_product", "name");
     $fnameid = Mage::getModel("eav/entity_attribute")->loadByCode("1", "firstname")->getAttributeId();
     $lnameid = Mage::getModel("eav/entity_attribute")->loadByCode("1", "lastname")->getAttributeId();
     $collection->getSelect()->join(array("ce1" => $prefix . "customer_entity_varchar"), "ce1.entity_id = main_table.seller_id", array("fname" => "value"))->where("ce1.attribute_id = " . $fnameid)->join(array("ce2" => $prefix . "customer_entity_varchar"), "ce2.entity_id = main_table.seller_id", array("lname" => "value"))->where("ce2.attribute_id = " . $lnameid)->columns(new Zend_Db_Expr("CONCAT(`ce1`.`value`, ' ',`ce2`.`value`) AS fullname"));
     $collection->addFilterToMap("fullname", "`ce1`.`value`");
     $pro_att_id = $eavAttribute->getIdByCode("catalog_product", "name");
     $collection->getSelect()->join(array("pn" => $prefix . "catalog_product_entity_varchar"), "pn.entity_id = main_table.product_id", array("proname" => "value"))->where("pn.attribute_id = " . $pro_att_id . " AND pn.store_id = " . Mage::app()->getStore()->getStoreId());
     $collection->addFilterToMap("proname", "pn.value");
     $pro_att_id = $eavAttribute->getIdByCode("catalog_product", "name");
     $this->setCollection($collection);
     parent::_prepareCollection();
     foreach ($this->getCollection() as $item) {
         $item->prev = sprintf('<span data="%s" product-id="%s" customer-id="%s" title="Click to Review" class="prev btn">prev</span>', $this->getUrl('mpassignproduct/front/prev/id/' . $item->getMpassignproductId()), $item['product_id'], $item['seller_id']);
         $item->deny = sprintf('<button type="button" class="wk_denyproduct" customer-id ="%s" product-id="%s"><span><span title="Deny">Deny</span></span></button>', $item->getsellerId(), $item->getMpassignproductId());
         if ($item['flag'] == 0) {
             $item->status = 'unapproved';
         } elseif ($item['flag'] == 2) {
             $item->status = 'Unapproved';
         } else {
             $item->status = 'Approved';
         }
         $quantity = Mage::getModel('mpassignproduct/mpassignproduct')->detailsale($item->getId(), $item['seller_id']);
         $item->qty_sold = (int) $quantity['quantitysold'];
         $item->qty_soldconfirmed = (int) $quantity['quantitysoldconfirmed'];
         $item->qty_soldpending = (int) $quantity['quantitysoldpending'];
         $symbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
         $item->amount_earned = $symbol . $quantity['amountearned'];
         foreach ($quantity['clearedat'] as $clear) {
             if (isset($clear) && $clear != '0000-00-00 00:00:00') {
                 $item->cleared_at = $clear;
             }
         }
     }
 }
Esempio n. 19
0
 private function _prepareCollection()
 {
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $supplier_id = Mage::helper('supplierfrontendproductuploader')->getSupplierId();
     $code = $eavAttribute->getIdByCode('catalog_product', 'creator_id');
     $table = "catalog_product_entity_int";
     $tableName = Mage::getSingleton("core/resource")->getTableName($table);
     $orderTable = Mage::getSingleton('core/resource')->getTableName('sales/order');
     $collection = Mage::getModel('sales/order_item')->getCollection();
     $page = Mage::app()->getRequest()->getParam('p', 1);
     $collection->setPageSize(10)->setCurPage($page)->addExpressionFieldToSelect('item_count', 'SUM({{qty_ordered}})', 'qty_ordered');
     $collection->getSelect()->joinInner(array('o' => $orderTable), 'o.entity_id = main_table.order_id', array())->joinInner(array('e' => $tableName), 'e.entity_id = main_table.product_id AND e.attribute_id = ' . $code, array())->where('main_table.parent_item_id is null')->where('e.value = ?', $supplier_id)->where('o.state != ?', 'canceled');
     if ($this->getFilter('from') && strtotime($this->getFilter('from'))) {
         $datetime = new DateTime($this->getFilter('from'));
         $collection->getSelect()->where('main_table.created_at >= ?', $datetime->format('Y-m-d'));
     }
     if ($this->getFilter('to') && strtotime($this->getFilter('to'))) {
         $datetime = new DateTime($this->getFilter('to'));
         $collection->getSelect()->where('main_table.created_at <= ?', $datetime->format('Y-m-d'));
     }
     $collection->getSelect()->group('main_table.product_id');
     return $collection;
 }
Esempio n. 20
0
 public function indexAction()
 {
     // CHECK IF ATTRIBUTE EXISTS
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $attribute_id = $eavAttribute->getIdByCode('catalog_product', 'created_at');
     if ($attribute_id) {
         $attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'created_at');
         $sort = $attributeModel['used_for_sort_by'];
         $id = $attributeModel['attribute_id'];
         if ($sort) {
             $attributeModel->setUsedForSortBy(0);
             $attributeModel->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('sortbydate')->__('Sort by date has been removed as listing option'));
         } else {
             $attributeModel->setUsedForSortBy(1);
             $attributeModel->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('sortbydate')->__('Sort by date has been added to the listing options'));
         }
     } else {
         $installed = '0';
         Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('sortbydate')->__('Sort by date has been added to the listing options'));
     }
     $this->_redirect('adminhtml/system_config/edit/section/sortbydate');
 }
Esempio n. 21
0
 /**
  * Save attribute/form relations after attribute save
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Customer_Model_Entity_Attribute
  */
 protected function _afterSave(Mage_Core_Model_Abstract $object)
 {
     $forms = $object->getData('used_in_forms');
     if (is_array($forms)) {
         $where = array('attribute_id=?' => $object->getId());
         $this->_getWriteAdapter()->delete($this->getTable('customer/form_attribute'), $where);
         $data = array();
         foreach ($forms as $formCode) {
             $data[] = array('form_code' => $formCode, 'attribute_id' => intval($object->getId()));
         }
         if ($data) {
             $this->_getWriteAdapter()->insertMultiple($this->getTable('customer/form_attribute'), $data);
         }
     }
     // update sort order
     if (!$object->isObjectNew() && $object->dataHasChangedFor('sort_order')) {
         $bind = array('sort_order' => $object->getSortOrder());
         $where = $this->_getWriteAdapter()->quoteInto('attribute_id=?', $object->getId());
         $this->_getWriteAdapter()->update($this->getTable('eav/entity_attribute'), $bind, $where);
     }
     // save scope attributes
     $websiteId = $object->getWebsite()->getId();
     if ($websiteId) {
         $table = $this->getTable('customer/eav_attribute_website');
         $describe = $this->_getReadAdapter()->describeTable($table);
         $data = array();
         if (!$object->getScopeWebsiteId() || $object->getScopeWebsiteId() != $websiteId) {
             $data = $this->getScopeValues($object);
         }
         $data['attribute_id'] = $object->getId();
         $data['website_id'] = $websiteId;
         $updateColumns = array();
         foreach (array_keys($describe) as $columnName) {
             if ($columnName != 'attribute_id' && $columnName != 'website_id') {
                 $data[$columnName] = $object->getData('scope_' . $columnName);
                 $updateColumns[] = $columnName;
             }
         }
         $this->_getWriteAdapter()->insertOnDuplicate($table, $data, $updateColumns);
     }
     return parent::_afterSave($object);
 }
 protected function _setupAttributes()
 {
     $configurableAttributes = array('ids' => array());
     $attributes = $this->getRequest()->getParam('attribute');
     foreach ($attributes as $code) {
         $options = array();
         // Load the attribute
         $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $code);
         if (!$attribute->getId()) {
             $this->_eavSetup->addAttribute('catalog_product', $code, array('group' => 'Configurable Data', 'type' => 'int', 'backend' => '', 'frontend' => '', 'label' => ucfirst($code), 'input' => 'select', 'class' => '', 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 'configurable' => true, 'visible' => true, 'required' => false, 'user_defined' => true, 'visible_on_front' => true));
             $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
             $configurableAttributes[$code] = array('attribute_id' => $eavAttribute->getIdByCode('catalog_product', $code), 'options' => $options);
             Mage::getSingleton('adminhtml/session')->addSuccess('Attribute "' . $code . '" has been created.');
         } else {
             if ($attribute->usesSource()) {
                 foreach ($attribute->getSource()->getAllOptions(false) as $option) {
                     $options[$option['label']] = $option['value'];
                 }
             }
             $configurableAttributes[$code] = array('attribute_id' => $attribute->getId(), 'options' => $options);
         }
         $configurableAttributes['ids'][] = $configurableAttributes[$code]['attribute_id'];
     }
     return $configurableAttributes;
 }
Esempio n. 23
0
 protected function _getAttributeId()
 {
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     return $eavAttribute->getIdByCode('catalog_product', 'creator_id');
 }
Esempio n. 24
0
 /**
  * @param Goodahead_Etm_Model_Attribute|Mage_Core_Model_Abstract $object
  * @return Mage_Eav_Model_Resource_Entity_Attribute|void
  */
 protected function _afterSave(Mage_Core_Model_Abstract $object)
 {
     parent::_afterSave($object);
     $tableName = $this->getTable('goodahead_etm/eav_attribute');
     $this->_getWriteAdapter()->insertOnDuplicate($tableName, $this->_prepareDataForTable($object, $tableName));
 }
 protected function updateId($id, $iteration)
 {
     $resource = Mage::getSingleton('core/resource');
     $table = $resource->getTableName('catalog_product_entity_int');
     $writeConnection = $resource->getConnection('core_write');
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $code = $eavAttribute->getIdByCode('catalog_product', "factfinder_exists");
     $query = "REPLACE INTO {$table} (entity_id, entity_type_id, attribute_id, value) VALUES ('{$id}', 4, '{$code}', '1');";
     if (!defined('DEBUG_NO_SAVE') || !DEBUG_NO_SAVE) {
         $writeConnection->query($query);
     }
     if (defined('DEBUG_LOG_STEPS') && DEBUG_LOG_STEPS) {
         $this->log('Updated %s', $id);
     }
 }
Esempio n. 26
0
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to info@magmodules.eu so we can send you a copy immediately.
 *
 * @category    Magmodules
 * @package     Magmodules_Sortbydate
 * @author      Magmodules <info@magmodules.eu)
 * @copyright   Copyright (c) 2013 (http://www.magmodules.eu)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
// Load Magento
require 'app/Mage.php';
Mage::app();
// Load attribute_id of created_at
$eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
$attribute_id = $eavAttribute->getIdByCode('catalog_product', 'created_at');
// Update database
if ($attribute_id) {
    $write = Mage::getSingleton('core/resource')->getConnection('core_write');
    $sql = "UPDATE catalog_eav_attribute SET used_for_sort_by = 1 WHERE attribute_id = '{$attribute_id}' LIMIT 1";
    $write->query($sql);
    echo 'Uninstalled!';
} else {
    echo 'Error!';
}
 public function inserttagAction()
 {
     $tagvalue = Mage::app()->getRequest()->getParam('tag');
     $productid = Mage::app()->getRequest()->getParam('productid');
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $code = $eavAttribute->getIdByCode('catalog_product', 'tag_custom');
     $option['attribute_id'] = $code;
     //local
     $option['value']['tagvalue'][0] = $tagvalue;
     $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
     $setup->addAttributeOption($option);
     $optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')->setAttributeFilter($code);
     //live
     $newInsertedOption = $optionCollection->getLastItem();
     $_option = $newInsertedOption->getData();
     $lastId = $_option['option_id'];
     $tag_id[] = 0;
     $tag_id[] = $lastId;
     $product = Mage::getModel('catalog/product')->load($productid);
     $tags = $product->getTagCustom();
     $tag_values = implode(',', $tag_id);
     if ($tag_values) {
         $glue = ",";
     }
     $tag_values = $tag_values . $glue . $tags;
     $product->addData(array('tag_custom' => $tag_values));
     $product->save();
     $insert_data['tag_id'] = $tag_id;
     $product_id[] = 0;
     $product_id[] = $productid;
     $insert_data['product_id'] = $productid;
     return $insert_data;
 }
Esempio n. 28
0
 private function getEavAttrCode()
 {
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     return $eavAttribute->getIdByCode('catalog_product', 'creator_id');
 }
Esempio n. 29
0
 public function getCategoryList()
 {
     $sellerid = $this->getProfileDetail()->getmageuserid();
     $querydata = Mage::getModel('marketplace/product')->getCollection()->addFieldToFilter('userid', array('eq' => $sellerid))->addFieldToFilter('status', array('neq' => 2))->addFieldToSelect('mageproductid')->setOrder('mageproductid');
     $collection = Mage::getModel('catalog/product')->getCollection();
     $collection->addAttributeToSelect('*');
     $collection->addAttributeToFilter('entity_id', array('in' => $querydata->getData()));
     $collection->addAttributeToFilter('visibility', array('in' => array(4)));
     $collection->addStoreFilter();
     //Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
     Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
     Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
     //Mage::getSingleton("catalog/product_visibility")->addVisibleInSearchFilterToCollection($collection);
     $collectionConfigurable = Mage::getResourceModel('catalog/product_collection')->addAttributeToFilter('type_id', array('eq' => 'configurable'))->addAttributeToFilter('entity_id', array('in' => $querydata->getData()));
     $outOfStockConfis = array();
     foreach ($collectionConfigurable as $_configurableproduct) {
         $product = Mage::getModel('catalog/product')->load($_configurableproduct->getId());
         if (!$product->getData('is_salable')) {
             $outOfStockConfis[] = $product->getId();
         }
     }
     if (count($outOfStockConfis)) {
         $collection->addAttributeToFilter('entity_id', array('nin' => $outOfStockConfis));
     }
     $collectionBundle = Mage::getResourceModel('catalog/product_collection')->addAttributeToFilter('type_id', array('eq' => 'bundle'))->addAttributeToFilter('entity_id', array('in' => $querydata->getData()));
     $outOfStockConfis = array();
     foreach ($collectionBundle as $_bundleproduct) {
         $product = Mage::getModel('catalog/product')->load($_bundleproduct->getId());
         if (!$product->getData('is_salable')) {
             $outOfStockConfis[] = $product->getId();
         }
     }
     if (count($outOfStockConfis)) {
         $collection->addAttributeToFilter('entity_id', array('nin' => $outOfStockConfis));
     }
     $collectionGrouped = Mage::getResourceModel('catalog/product_collection')->addAttributeToFilter('type_id', array('eq' => 'bundle'))->addAttributeToFilter('entity_id', array('in' => $querydata->getData()));
     $outOfStockConfis = array();
     foreach ($collectionGrouped as $_groupedproduct) {
         $product = Mage::getModel('catalog/product')->load($_groupedproduct->getId());
         if (!$product->getData('is_salable')) {
             $outOfStockConfis[] = $product->getId();
         }
     }
     if (count($outOfStockConfis)) {
         $collection->addAttributeToFilter('entity_id', array('nin' => $outOfStockConfis));
     }
     $products = Mage::getModel('marketplace/product')->getCollection()->addFieldToFilter('mageproductid', array('in' => $collection->getData()))->addFieldToSelect('mageproductid');
     $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
     $pro_att_id = $eavAttribute->getIdByCode("catalog_category", "name");
     $storeId = Mage::app()->getStore()->getStoreId();
     if (!isset($_GET["c"])) {
         $_GET["c"] = '';
     }
     if (!$_GET["c"]) {
         $parentid = Mage::app()->getStore($storeId)->getRootCategoryId();
     } else {
         $parentid = $_GET["c"];
     }
     $prefix = Mage::getConfig()->getTablePrefix();
     $products->getSelect()->join(array("ccp" => $prefix . "catalog_category_product"), "ccp.product_id = main_table.mageproductid", array("category_id" => "category_id"))->join(array("cce" => $prefix . "catalog_category_entity"), "cce.entity_id = ccp.category_id", array("parent_id" => "parent_id"))->where("cce.parent_id = '" . $parentid . "'")->columns('COUNT(*) AS countCategory')->group('category_id')->join(array("ce1" => $prefix . "catalog_category_entity_varchar"), "ce1.entity_id = ccp.category_id", array("name" => "value"))->where("ce1.attribute_id = " . $pro_att_id)->order('name');
     return $products;
 }