protected function _prepareCollection() { //-------------------------------- // Get collection //---------------------------- /** @var Mage_Catalog_Model_Resource_Product_Collection $collection */ $collection = Mage::getModel('catalog/product')->getCollection(); $collection->addAttributeToSelect('sku'); $collection->addAttributeToSelect('name'); //-------------------------------- // Join listing product tables //---------------------------- $collection->joinTable(array('lp' => 'M2ePro/Listing_Product'), 'product_id=entity_id', array('id' => 'id', 'status' => 'status'), '{{table}}.listing_id=' . (int) $this->getListing()->getId()); $collection->joinTable(array('elp' => 'M2ePro/Ebay_Listing_Product'), 'listing_product_id=id', array('listing_product_id' => 'listing_product_id', 'template_category_id' => 'template_category_id', 'template_other_category_id' => 'template_other_category_id', 'template_payment_mode' => 'template_payment_mode', 'template_shipping_mode' => 'template_shipping_mode', 'template_return_mode' => 'template_return_mode', 'template_description_mode' => 'template_description_mode', 'template_selling_format_mode' => 'template_selling_format_mode', 'template_synchronization_mode' => 'template_synchronization_mode', 'end_date' => 'end_date', 'start_date' => 'start_date', 'online_title' => 'online_title', 'online_sku' => 'online_sku', 'available_qty' => new Zend_Db_Expr('(online_qty - online_qty_sold)'), 'ebay_item_id' => 'ebay_item_id', 'online_category' => 'online_category', 'online_qty_sold' => 'online_qty_sold', 'online_buyitnow_price' => 'online_buyitnow_price')); $collection->joinTable(array('ei' => 'M2ePro/Ebay_Item'), 'id=ebay_item_id', array('item_id' => 'item_id'), NULL, 'left'); $collection->joinTable(array('etc' => 'M2ePro/Ebay_Template_Category'), 'id=template_category_id', array('category_main_mode' => 'category_main_mode', 'category_main_id' => 'category_main_id', 'category_main_path' => 'category_main_path', 'category_main_attribute' => 'category_main_attribute'), NULL, 'left'); $collection->joinTable(array('etoc' => 'M2ePro/Ebay_Template_OtherCategory'), 'id=template_other_category_id', array('category_secondary_mode' => 'category_secondary_mode', 'category_secondary_id' => 'category_secondary_id', 'category_secondary_path' => 'category_secondary_path', 'category_secondary_attribute' => 'category_secondary_attribute', 'store_category_main_mode' => 'store_category_main_mode', 'store_category_main_id' => 'store_category_main_id', 'store_category_main_path' => 'store_category_main_path', 'store_category_main_attribute' => 'store_category_main_attribute', 'store_category_secondary_mode' => 'store_category_secondary_mode', 'store_category_secondary_id' => 'store_category_secondary_id', 'store_category_secondary_path' => 'store_category_secondary_path', 'store_category_secondary_attribute' => 'store_category_secondary_attribute'), NULL, 'left'); if ($this->motorsSpecificsAttribute) { $collection->addAttributeToSelect($this->motorsSpecificsAttribute->getAttributeCode()); $collection->joinTable(array('eea' => Mage::getSingleton('core/resource')->getTableName('eav_entity_attribute')), 'attribute_set_id=attribute_set_id', array('is_motors_attribute_in_product_attribute_set' => 'entity_attribute_id'), '{{table}}.attribute_id = ' . $this->motorsSpecificsAttribute->getAttributeId(), 'left'); } //---------------------------- // exit($collection->getSelect()->__toString()); // Set collection to grid $this->setCollection($collection); return parent::_prepareCollection(); }
/** * Check is attribute allowed * * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute * @param array $attributes * @return boolean */ protected function _isAllowedAttribute($attribute, array $filter = null) { if (!is_null($filter) && !(in_array($attribute->getAttributeCode(), $filter) || in_array($attribute->getAttributeId(), $filter))) { return false; } return !in_array($attribute->getFrontendInput(), $this->_ignoredAttributeTypes) && !in_array($attribute->getAttributeCode(), $this->_ignoredAttributeCodes); }
/** * Insert or Update attribute data * * @param Mage_Catalog_Model_Abstract $object * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute * @param mixed $value * @return Mage_Catalog_Model_Resource_Abstract */ protected function _saveAttributeValue($object, $attribute, $value) { $write = $this->_getWriteAdapter(); //set default store id $storeId = Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID; $table = $attribute->getBackend()->getTable(); /** * If we work in single store mode all values should be saved just * for default store id * In this case we clear all not default values */ if (Mage::app()->isSingleStoreMode()) { $storeId = $this->getDefaultStoreId(); $write->delete($table, array('attribute_id = ?' => $attribute->getAttributeId(), 'entity_id = ?' => $object->getEntityId(), 'store_id <> ?' => $storeId)); } $data = new Varien_Object(array('entity_type_id' => $attribute->getEntityTypeId(), 'attribute_id' => $attribute->getAttributeId(), 'store_id' => $storeId, 'entity_id' => $object->getEntityId(), 'value' => $this->_prepareValueForSave($value, $attribute))); $bind = $this->_prepareDataForTable($data, $table); if ($attribute->isScopeStore()) { /** * Update attribute value for store */ $this->_attributeValuesToSave[$table][] = $bind; } else { if ($attribute->isScopeWebsite() && $storeId != $this->getDefaultStoreId()) { /** * Update attribute value for website */ $storeIds = Mage::app()->getStore($storeId)->getWebsite()->getStoreIds(true); foreach ($storeIds as $storeId) { $bind['store_id'] = (int) $storeId; $this->_attributeValuesToSave[$table][] = $bind; } } else { /** * Update global attribute value */ $bind['store_id'] = $this->getDefaultStoreId(); $this->_attributeValuesToSave[$table][] = $bind; } } return $this; }
protected function _prepareCollection() { // --------------------------------------- // Get collection // --------------------------------------- /* @var $collection Ess_M2ePro_Model_Mysql4_Magento_Product_Collection */ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection', Mage::getModel('catalog/product')->getResource()); $collection->addAttributeToSelect('sku'); $collection->addAttributeToSelect('name'); // --------------------------------------- // Join listing product tables // --------------------------------------- $collection->joinTable(array('lp' => 'M2ePro/Listing_Product'), 'product_id=entity_id', array('id' => 'id', 'ebay_status' => 'status'), '{{table}}.listing_id=' . (int) $this->getListing()->getId()); $collection->joinTable(array('elp' => 'M2ePro/Ebay_Listing_Product'), 'listing_product_id=id', array('listing_product_id' => 'listing_product_id', 'template_category_id' => 'template_category_id', 'template_other_category_id' => 'template_other_category_id', 'template_payment_mode' => 'template_payment_mode', 'template_shipping_mode' => 'template_shipping_mode', 'template_return_mode' => 'template_return_mode', 'template_description_mode' => 'template_description_mode', 'template_selling_format_mode' => 'template_selling_format_mode', 'template_synchronization_mode' => 'template_synchronization_mode', 'end_date' => 'end_date', 'start_date' => 'start_date', 'online_title' => 'online_title', 'online_sku' => 'online_sku', 'available_qty' => new Zend_Db_Expr('(online_qty - online_qty_sold)'), 'ebay_item_id' => 'ebay_item_id', 'online_category' => 'online_category', 'online_qty_sold' => 'online_qty_sold', 'online_start_price' => 'online_start_price', 'online_current_price' => 'online_current_price', 'online_reserve_price' => 'online_reserve_price', 'online_buyitnow_price' => 'online_buyitnow_price', 'min_online_price' => 'IF( (`t`.`variation_min_price` IS NULL), `elp`.`online_current_price`, `t`.`variation_min_price` )', 'max_online_price' => 'IF( (`t`.`variation_max_price` IS NULL), `elp`.`online_current_price`, `t`.`variation_max_price` )')); $collection->joinTable(array('ei' => 'M2ePro/Ebay_Item'), 'id=ebay_item_id', array('item_id' => 'item_id'), NULL, 'left'); $collection->joinTable(array('etc' => 'M2ePro/Ebay_Template_Category'), 'id=template_category_id', array('category_main_mode' => 'category_main_mode', 'category_main_id' => 'category_main_id', 'category_main_path' => 'category_main_path', 'category_main_attribute' => 'category_main_attribute'), NULL, 'left'); $collection->joinTable(array('etoc' => 'M2ePro/Ebay_Template_OtherCategory'), 'id=template_other_category_id', array('category_secondary_mode' => 'category_secondary_mode', 'category_secondary_id' => 'category_secondary_id', 'category_secondary_path' => 'category_secondary_path', 'category_secondary_attribute' => 'category_secondary_attribute', 'store_category_main_mode' => 'store_category_main_mode', 'store_category_main_id' => 'store_category_main_id', 'store_category_main_path' => 'store_category_main_path', 'store_category_main_attribute' => 'store_category_main_attribute', 'store_category_secondary_mode' => 'store_category_secondary_mode', 'store_category_secondary_id' => 'store_category_secondary_id', 'store_category_secondary_path' => 'store_category_secondary_path', 'store_category_secondary_attribute' => 'store_category_secondary_attribute'), NULL, 'left'); if ($this->motorsAttribute) { $collection->addAttributeToSelect($this->motorsAttribute->getAttributeCode()); $collection->joinTable(array('eea' => Mage::getSingleton('core/resource')->getTableName('eav_entity_attribute')), 'attribute_set_id=attribute_set_id', array('is_motors_attribute_in_product_attribute_set' => 'entity_attribute_id'), '{{table}}.attribute_id = ' . $this->motorsAttribute->getAttributeId(), 'left'); } $collection->getSelect()->joinLeft(new Zend_Db_Expr('( SELECT `mlpv`.`listing_product_id`, MIN(`melpv`.`online_price`) as variation_min_price, MAX(`melpv`.`online_price`) as variation_max_price FROM `' . Mage::getResourceModel('M2ePro/Listing_Product_Variation')->getMainTable() . '` AS `mlpv` INNER JOIN `' . Mage::getResourceModel('M2ePro/Ebay_Listing_Product_Variation')->getMainTable() . '` AS `melpv` ON (`mlpv`.`id` = `melpv`.`listing_product_variation_id`) WHERE `melpv`.`status` != ' . Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED . ' GROUP BY `mlpv`.`listing_product_id` )'), 'elp.listing_product_id=t.listing_product_id', array('variation_min_price' => 'variation_min_price', 'variation_max_price' => 'variation_max_price')); // --------------------------------------- // Set collection to grid $this->setCollection($collection); parent::_prepareCollection(); if ($this->isMotorsAvailable()) { $this->prepareExistingMotorsData(); } return $this; }
/** * Insert entity attribute value * * @param Varien_Object $object * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute * @param mixed $value * @return Mage_Catalog_Model_Resource_Abstract */ protected function _insertAttribute($object, $attribute, $value) { /** * save required attributes in global scope every time if store id different from default */ $storeId = (int) Mage::app()->getStore($object->getStoreId())->getId(); if ($attribute->getIsRequired() && $this->getDefaultStoreId() != $storeId) { $table = $attribute->getBackend()->getTable(); $select = $this->_getReadAdapter()->select()->from($table)->where('entity_type_id = ?', $attribute->getEntityTypeId())->where('attribute_id = ?', $attribute->getAttributeId())->where('store_id = ?', $this->getDefaultStoreId())->where('entity_id = ?', $object->getEntityId()); $row = $this->_getReadAdapter()->fetchOne($select); if (!$row) { $data = new Varien_Object(array('entity_type_id' => $attribute->getEntityTypeId(), 'attribute_id' => $attribute->getAttributeId(), 'store_id' => $this->getDefaultStoreId(), 'entity_id' => $object->getEntityId(), 'value' => $this->_prepareValueForSave($value, $attribute))); $bind = $this->_prepareDataForTable($data, $table); $this->_getWriteAdapter()->insertOnDuplicate($table, $bind, array('value')); } } return $this->_saveAttributeValue($object, $attribute, $value); }
/** * Check if attribute is allowed * * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute * @param array $attributes * @return boolean */ protected function _isAllowedAttribute($attribute, $attributes = null) { $isAllowed = true; if (is_array($attributes) && !(in_array($attribute->getAttributeCode(), $attributes) || in_array($attribute->getAttributeId(), $attributes))) { $isAllowed = false; } return $isAllowed; }
/** * Insert entity attribute value * * @param Varien_Object $object * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute * @param mixed $value * @return Mage_Eav_Model_Entity_Abstract */ protected function _insertAttribute($object, $attribute, $value) { /** * save required attributes in global scope every time if store id different from default */ $storeId = Mage::app()->getStore($object->getStoreId())->getId(); if ($attribute->getIsRequired() && $this->getDefaultStoreId() != $storeId) { $bind = array('entity_type_id' => $attribute->getEntityTypeId(), 'attribute_id' => $attribute->getAttributeId(), 'store_id' => $this->getDefaultStoreId(), 'entity_id' => $object->getEntityId(), 'value' => $this->_prepareValueForSave($value, $attribute)); $this->_getWriteAdapter()->insertOnDuplicate($attribute->getBackend()->getTable(), $bind, array('value')); } return $this->_saveAttributeValue($object, $attribute, $value); // $entityIdField = $attribute->getBackend()->getEntityIdField(); // $row = array( // $entityIdField => $object->getId(), // 'entity_type_id'=> $object->getEntityTypeId(), // 'attribute_id' => $attribute->getId(), // 'value' => $this->_prepareValueForSave($value, $attribute), // 'store_id' => $this->getDefaultStoreId() // ); // // $fields = array(); // $bind = array(); // foreach ($row as $k => $v) { // $fields[] = $this->_getWriteAdapter()->quoteIdentifier($k); // $bind[':' . $k] = $v; // } // // $sql = sprintf('INSERT IGNORE INTO %s (%s) VALUES(%s)', // $this->_getWriteAdapter()->quoteIdentifier($attribute->getBackend()->getTable()), // implode(',', $fields), // implode(',', array_keys($bind))); // // $this->_getWriteAdapter()->query($sql, $bind); // if (!$lastId = $this->_getWriteAdapter()->lastInsertId()) { // $select = $this->_getReadAdapter()->select() // ->from($attribute->getBackend()->getTable(), 'value_id') // ->where($entityIdField . '=?', $row[$entityIdField]) // ->where('entity_type_id=?', $row['entity_type_id']) // ->where('attribute_id=?', $row['attribute_id']) // ->where('store_id=?', $row['store_id']); // $lastId = $select->query()->fetchColumn(); // } // if ($object->getStoreId() != $this->getDefaultStoreId()) { // $this->_updateAttribute($object, $attribute, $lastId, $value); // } // return $this; }
/** * Join customer attribute * * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute */ protected function _joinCustomerAttibute(Mage_Eav_Model_Entity_Attribute_Abstract $attribute) { $tableName = 'at_' . $attribute->getName(); $joinExpr = array($tableName . '.entity_id = wishlist_table.customer_id', $this->getSelect()->getAdapter()->quoteInto($tableName . '.attribute_id = ?', $attribute->getAttributeId())); $this->getSelect()->joinLeft(array($tableName => $attribute->getBackend()->getTable()), implode(' AND ', $joinExpr), array()); }