Exemplo n.º 1
0
 /**
  * Add custom attributes selected by magento admin to query
  *
  * @param Varien_Data_Collection_Db $collection Collection of data which will be spit out as feed
  * @param string $customAttribs Comma separated list of attribute codes
  * @param array $fieldMap Reference to fieldmap where attribute codes should also be added
  */
 protected function addCustomAttributes($collection, $customAttribs, &$fieldMap)
 {
     // Log
     Mage::helper('mybuys')->log("Adding custom attributes include in query: {$customAttribs}", Zend_Log::INFO, Mybuys_Connector_Helper_Data::LOG_FILE);
     // Check if we have any custom attribs
     if (strlen(trim($customAttribs)) > 0) {
         // Iterate custom attribs
         foreach (explode(',', $customAttribs) as $curAttrib) {
             // Trim attribute code
             $curAttrib = trim($curAttrib);
             // Check if attribute exists
             $_attribute = $collection->getAttribute($curAttrib);
             if ($_attribute === false) {
                 // Attribute not found
                 Mage::throwException("Attribte not found: {$curAttrib}");
             }
             // Log
             Mage::helper('mybuys')->log("Adding attribute to query: {$curAttrib}", Zend_Log::DEBUG, Mybuys_Connector_Helper_Data::LOG_FILE);
             if ($_attribute->getFrontendInput() == "select" || $_attribute->getFrontendInput() == "multiselect") {
                 // attribute is a select of multi-select input and attribute id to value translation is needed
                 // Log
                 Mage::helper('mybuys')->log("Note - Attribute needs translation", Zend_Log::DEBUG, Mybuys_Connector_Helper_Data::LOG_FILE);
                 $this->_optionValueMap['custom_' . $curAttrib] = true;
             }
             // Add attribute to select
             $collection->addExpressionAttributeToSelect('custom_' . $curAttrib, "{{" . $curAttrib . "}}", $curAttrib)->addAttributeToSelect($curAttrib);
             // Add attribute to map
             $fieldMap['custom_' . $curAttrib] = 'custom_' . $curAttrib;
         }
     }
     // Return the original collection object
     return $collection;
 }
Exemplo n.º 2
0
 protected function _prepareCollection()
 {
     /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
     $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
     // Prepare selling format collection
     // ---------------------------------------
     $collectionSellingFormat = Mage::getModel('M2ePro/Template_SellingFormat')->getCollection();
     $collectionSellingFormat->getSelect()->reset(Varien_Db_Select::COLUMNS);
     $collectionSellingFormat->getSelect()->columns(array('id as template_id', 'title', new Zend_Db_Expr('\'' . self::TEMPLATE_SELLING_FORMAT . '\' as `type`'), 'create_date', 'update_date'));
     $collectionSellingFormat->getSelect()->where('component_mode = (?)', $this->nick);
     // ---------------------------------------
     // Prepare synchronization collection
     // ---------------------------------------
     $collectionSynchronization = Mage::getModel('M2ePro/Template_Synchronization')->getCollection();
     $collectionSynchronization->getSelect()->reset(Varien_Db_Select::COLUMNS);
     $collectionSynchronization->getSelect()->columns(array('id as template_id', 'title', new Zend_Db_Expr('\'' . self::TEMPLATE_SYNCHRONIZATION . '\' as `type`'), 'create_date', 'update_date'));
     $collectionSynchronization->getSelect()->where('component_mode = (?)', $this->nick);
     // ---------------------------------------
     // Prepare union select
     // ---------------------------------------
     $unionSelect = $connRead->select();
     $unionSelect->union(array($collectionSellingFormat->getSelect(), $collectionSynchronization->getSelect()));
     // ---------------------------------------
     // Prepare result collection
     // ---------------------------------------
     $resultCollection = new Varien_Data_Collection_Db($connRead);
     $resultCollection->getSelect()->reset()->from(array('main_table' => $unionSelect), array('template_id', 'title', 'type', 'create_date', 'update_date'));
     // ---------------------------------------
     //        echo $resultCollection->getSelectSql(true); exit;
     $this->setCollection($resultCollection);
     return parent::_prepareCollection();
 }
Exemplo n.º 3
0
 protected function _prepareCollection()
 {
     // Get collection products in listing
     // ---------------------------------------
     $listingProductCollection = Mage::helper('M2ePro/Component_Buy')->getCollection('Listing_Product');
     $listingProductCollection->getSelect()->distinct();
     $listingProductCollection->getSelect()->join(array('l' => Mage::getResourceModel('M2ePro/Listing')->getMainTable()), '(`l`.`id` = `main_table`.`listing_id`)', array('listing_title' => 'title', 'store_id'))->join(array('bl' => Mage::getResourceModel('M2ePro/Buy_Listing')->getMainTable()), '(`bl`.`listing_id` = `l`.`id`)', array('template_selling_format_id'));
     // ---------------------------------------
     // Communicate with magento product table
     // ---------------------------------------
     $dbSelect = Mage::getResourceModel('core/config')->getReadConnection()->select()->from(Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar'), new Zend_Db_Expr('MAX(`store_id`)'))->where("`entity_id` = `main_table`.`product_id`")->where("`attribute_id` = `ea`.`attribute_id`")->where("`store_id` = 0 OR `store_id` = `l`.`store_id`");
     $listingProductCollection->getSelect()->join(array('cpe' => Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')), '(cpe.entity_id = `main_table`.product_id)', array('magento_sku' => 'sku'))->join(array('cisi' => Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')), '(cisi.product_id = `main_table`.product_id AND cisi.stock_id = 1)', array('is_in_stock'))->join(array('cpev' => Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')), "(`cpev`.`entity_id` = `main_table`.product_id)", array('value'))->join(array('ea' => Mage::getSingleton('core/resource')->getTableName('eav_attribute')), '(`cpev`.`attribute_id` = `ea`.`attribute_id` AND `ea`.`attribute_code` = \'name\')', array())->where('`cpev`.`store_id` = (' . $dbSelect->__toString() . ')');
     // ---------------------------------------
     $listingProductCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
     $listingProductCollection->getSelect()->columns(array('is_m2epro_listing' => new Zend_Db_Expr('1'), 'magento_sku' => 'cpe.sku', 'is_in_stock' => 'cisi.is_in_stock', 'product_name' => 'cpev.value', 'listing_title' => 'l.title', 'store_id' => 'l.store_id', 'account_id' => 'l.account_id', 'marketplace_id' => 'l.marketplace_id', 'listing_product_id' => 'main_table.id', 'product_id' => 'main_table.product_id', 'listing_id' => 'main_table.listing_id', 'status' => 'main_table.status', 'template_new_product_id' => 'second_table.template_new_product_id', 'general_id' => 'second_table.general_id', 'online_sku' => 'second_table.sku', 'online_qty' => 'second_table.online_qty', 'online_price' => 'second_table.online_price'));
     // ---------------------------------------
     $listingOtherCollection = Mage::helper('M2ePro/Component_Buy')->getCollection('Listing_Other');
     $listingOtherCollection->getSelect()->distinct();
     // add stock availability, type id, status & visibility to select
     // ---------------------------------------
     $listingOtherCollection->getSelect()->joinLeft(array('cisi' => Mage::getResourceModel('cataloginventory/stock_item')->getMainTable()), '(`cisi`.`product_id` = `main_table`.`product_id` AND cisi.stock_id = 1)', array('is_in_stock'))->joinLeft(array('cpe' => Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')), '(cpe.entity_id = `main_table`.product_id)', array('magento_sku' => 'sku'));
     // ---------------------------------------
     $listingOtherCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
     $listingOtherCollection->getSelect()->columns(array('is_m2epro_listing' => new Zend_Db_Expr(0), 'magento_sku' => 'cpe.sku', 'is_in_stock' => 'cisi.is_in_stock', 'product_name' => 'second_table.title', 'listing_title' => new Zend_Db_Expr('NULL'), 'store_id' => new Zend_Db_Expr(0), 'account_id' => 'main_table.account_id', 'marketplace_id' => 'main_table.marketplace_id', 'listing_product_id' => new Zend_Db_Expr('NULL'), 'product_id' => 'main_table.product_id', 'listing_id' => new Zend_Db_Expr('NULL'), 'status' => 'main_table.status', 'template_new_product_id' => new Zend_Db_Expr('NULL'), 'general_id' => 'second_table.general_id', 'online_sku' => 'second_table.sku', 'online_qty' => 'second_table.online_qty', 'online_price' => 'second_table.online_price'));
     // ---------------------------------------
     // ---------------------------------------
     $selects = array($listingProductCollection->getSelect(), $listingOtherCollection->getSelect());
     $unionSelect = Mage::getResourceModel('core/config')->getReadConnection()->select();
     $unionSelect->union($selects);
     $resultCollection = new Varien_Data_Collection_Db(Mage::getResourceModel('core/config')->getReadConnection());
     $resultCollection->getSelect()->reset()->from(array('main_table' => $unionSelect), array('is_m2epro_listing', 'magento_sku', 'is_in_stock', 'product_name', 'listing_title', 'store_id', 'account_id', 'marketplace_id', 'listing_product_id', 'product_id', 'listing_id', 'status', 'template_new_product_id', 'general_id', 'online_sku', 'online_qty', 'online_price'));
     // Set collection to grid
     $this->setCollection($resultCollection);
     return parent::_prepareCollection();
 }
Exemplo n.º 4
0
 /**
  * Adding item data using second query because:
  *
  * - Join causes use of temporary table == slow
  * - Wrapping the main query as a subquery is too complex
  * - We want to show all order items for orders that matched filter by sku/name
  *
  * @return $this
  */
 protected function _prepareCollection()
 {
     parent::_prepareCollection();
     if (Mage::getStoreConfig(self::XML_PATH_RENDER_COLUMN) && !$this->_isExport) {
         $orderIds = array();
         $orderCollection = $this->getCollection();
         /** @var $orderCollection Mage_Sales_Model_Mysql4_Order_Grid_Collection */
         foreach ($orderCollection as $order) {
             $orderIds[] = $order->getEntityId();
         }
         $conn = Mage::getSingleton('core/resource')->getConnection('read');
         /* @var $conn Zend_Db_Adapter_Pdo_Abstract */
         // Increase max length of group concat fields for long product names
         $conn->exec('SET SESSION group_concat_max_len = 4096;');
         $itemsCollection = new Varien_Data_Collection_Db($conn);
         $itemsCollection->getSelect()->from(array('soi' => $orderCollection->getTable('sales/order_item')), array('order_id', 'skus' => new Zend_Db_Expr('group_concat(`soi`.sku SEPARATOR " ^ ")'), 'qtys' => new Zend_Db_Expr('group_concat(`soi`.qty_ordered SEPARATOR " ^ ")'), 'names' => new Zend_Db_Expr('group_concat(`soi`.name SEPARATOR " ^ ")')))->where('order_id IN (?)', $orderIds)->group('order_id');
         foreach ($itemsCollection as $object) {
             $order = $orderCollection->getItemById($object->getOrderId());
             $order->setSkus($object->getSkus());
             $order->setQtys($object->getQtys());
             $order->setNames($object->getNames());
         }
     }
     Mage::app()->dispatchEvent('cm_orderproducts_sales_order_grid_prepareCollection', ['block' => $this]);
     return $this;
 }
Exemplo n.º 5
0
 private function addMotorsSpecificsAttributeToSelect(Varien_Data_Collection_Db $collection)
 {
     if (!$this->isMotorsSpecificsAttributeAvailable()) {
         return;
     }
     $attribute = $this->getMotorsSpecificsAttribute();
     $attributeId = (int) $attribute->getAttributeId();
     $collection->getSelect()->joinLeft(array('cpet' => Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')), '(`cpet`.`entity_id` = `main_table`.product_id AND `cpet`.`attribute_id` = ' . $attributeId . ')', array('motors_specifics_attribute_value' => 'value'));
 }
 /**
  * Add events log to a collection
  * The collection id field is used without corellation, so it must be unique.
  * DESC ordering by event will be added to the collection
  *
  * @param Varien_Data_Collection_Db $collection
  * @param int $eventTypeId
  * @param int $eventSubjectId
  * @param int $subtype
  * @param array $skipIds
  */
 public function applyLogToCollection(Varien_Data_Collection_Db $collection, $eventTypeId, $eventSubjectId, $subtype, $skipIds = array())
 {
     $idFieldName = $collection->getResource()->getIdFieldName();
     $derivedSelect = $this->getReadConnection()->select()->from($this->getTable('reports/event'), array('event_id' => new Zend_Db_Expr('MAX(event_id)'), 'object_id'))->where('event_type_id=?', (int) $eventTypeId)->where('subject_id=?', (int) $eventSubjectId)->where('subtype=?', (int) $subtype)->where('store_id IN(?)', $this->getCurrentStoreIds())->group('object_id');
     if ($skipIds) {
         if (!is_array($skipIds)) {
             $skipIds = array((int) $skipIds);
         }
         $derivedSelect->where('object_id NOT IN(?)', $skipIds);
     }
     $collection->getSelect()->joinInner(array('evt' => new Zend_Db_Expr("({$derivedSelect})")), "`{$idFieldName}`=evt.object_id", array())->order('evt.event_id DESC');
 }
Exemplo n.º 7
0
 /**
  * Add throttle parameter to collection to limit output to X number of rows
  *
  * @param Varien_Data_Collection_Db $collection Collection of data which will be spit out as feed
  * @param int|string $throttle Number representing maximum record count which should be included in this feed generation run
  * @param int|string $minEntityId Number representing minimum value for entity Id to export - This acts as a placeholder for where the feed export left off
  */
 protected function addThrottleFilter($collection, $throttle, $minEntityId)
 {
     // Add mim entity id filter
     if ($minEntityId > 0) {
         $collection->getSelect()->where("product_id >= {$minEntityId}");
     }
     // Add throttle param
     if ($throttle > 0) {
         $collection->getSelect()->limit($throttle);
     }
     // Return the modified collection
     return $collection;
 }
Exemplo n.º 8
0
 /**
  * Filter an order collection by status/state depending on MailUp config
  * NOTE that cannot override collection consistently as the class changed name in 1.6
  *
  * @param Varien_Data_Collection_Db $collection
  * @return $this
  */
 public function addStatusFilterToOrders($collection)
 {
     $config = Mage::getModel('mailup/config');
     // Add condition to skip orders that have incorrect statuses
     $allowedStatuses = $config->getQualifyingOrderStatuses();
     // If config options, use the given statuses
     if (count($allowedStatuses) > 0) {
         $collection->addAttributeToFilter('status', $allowedStatuses);
     } else {
         // Else, use complete, closed and processing state only
         $allowedStates = $config->getDefaultQualifyingStates();
         $collection->addAttributeToFilter('state', $allowedStates);
     }
     return $this;
 }
Exemplo n.º 9
0
 /**
  * Remove Bronto Message Connection for Template
  *
  * @param Varien_Data_Collection_Db $collection
  * @param string                    $scope
  * @param string|int                $scopeId
  */
 public function unlinkEmails(Varien_Data_Collection_Db $collection, $scope, $scopeId)
 {
     switch ($scope) {
         case 'stores':
         case 'store':
             $storeId = $scopeId;
             break;
         case 'websites':
         case 'website':
             $storeId = Mage::app()->getWebsite($scopeId)->getStoreIds();
             break;
         default:
             $storeId = false;
             break;
     }
     // create filter
     if ($storeId) {
         if (is_array($storeId)) {
             $filter = array('in' => $storeId);
         } else {
             $filter = array('eq' => $storeId);
         }
         $collection->addFieldToFilter('store_id', $filter);
     }
     // Delete Bronto Message connection to template
     foreach ($collection as $message) {
         $message->delete();
     }
 }
 public function __construct()
 {
     parent::__construct(AO::getSingleton('core/resource')->getConnection('admin_read'));
     $this->_roleTable = AO::getSingleton('core/resource')->getTableName('admin/role');
     $this->_select->from($this->_roleTable);
     $this->setItemObjectClass(AO::getConfig()->getModelClassName('admin/acl_role'));
 }
Exemplo n.º 11
0
 public function __construct()
 {
     parent::__construct(Mage::getSingleton('core/resource')->getConnection('newsletter_read'));
     $this->_templateTable = Mage::getSingleton('core/resource')->getTableName('newsletter/template');
     $this->_select->from($this->_templateTable, array('template_id', 'template_code', 'template_type', 'template_subject', 'template_sender_name', 'template_sender_email', 'added_at', 'modified_at'));
     $this->setItemObjectClass(Mage::getConfig()->getModelClassName('newsletter/template'));
 }
Exemplo n.º 12
0
 public function __construct()
 {
     parent::__construct(Mage::getSingleton('core/resource')->getConnection('directory_read'));
     $this->_countryTable = Mage::getSingleton('core/resource')->getTableName('directory/country');
     $this->_select->from(array('country' => $this->_countryTable));
     $this->setItemObjectClass(Mage::getConfig()->getModelClassName('directory/country'));
 }
Exemplo n.º 13
0
 public function __construct()
 {
     $resources = Mage::getSingleton('core/resource');
     parent::__construct($resources->getConnection('tag_read'));
     $this->_usersTable = $resources->getTableName('admin/user');
     $this->_roleTable = $resources->getTableName('admin/role');
     $this->_ruleTable = $resources->getTableName('admin/rule');
 }
Exemplo n.º 14
0
 public function __construct()
 {
     $resources = Mage::getSingleton('core/resource');
     parent::__construct($resources->getConnection('livechat_read'));
     $this->_livechatTable = $resources->getTableName('livechat/livechat');
     $this->_select->from(array('livechat' => $this->_livechatTable), array('*'));
     $this->setItemObjectClass(Mage::getConfig()->getModelClassName('livechat/livechat'));
 }
 public function __construct()
 {
     parent::__construct(Mage::getSingleton('core/resource')->getConnection('rating_read'));
     $this->_ratingOptionTable = Mage::getSingleton('core/resource')->getTableName('rating/rating_option');
     $this->_ratingVoteTable = Mage::getSingleton('core/resource')->getTableName('rating/rating_vote');
     $this->_select->from($this->_ratingOptionTable);
     $this->setItemObjectClass(Mage::getConfig()->getModelClassName('rating/rating_option'));
 }
Exemplo n.º 16
0
 public function __construct()
 {
     $resources = Mage::getSingleton('core/resource');
     parent::__construct($resources->getConnection('approveorder_read'));
     $this->_kitchenTable = $resources->getTableName('approveorder/kitchen');
     $this->_select->from(array('e' => $this->_kitchenTable), array('*'));
     $this->setItemObjectClass(Mage::getConfig()->getModelClassName('approveorder/kitchen'));
 }
Exemplo n.º 17
0
 protected function _prepareCollection()
 {
     /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
     $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
     // Prepare selling format collection
     // ---------------------------------------
     $collectionSellingFormat = Mage::getModel('M2ePro/Template_SellingFormat')->getCollection();
     $collectionSellingFormat->getSelect()->reset(Varien_Db_Select::COLUMNS);
     $collectionSellingFormat->getSelect()->columns(array('id as template_id', 'title', new Zend_Db_Expr('\'' . self::TEMPLATE_SELLING_FORMAT . '\' as `type`'), new Zend_Db_Expr('\'0\' as `marketplace_id`'), 'create_date', 'update_date', new Zend_Db_Expr('NULL as `category_path`'), new Zend_Db_Expr('NULL as `browsenode_id`'), new Zend_Db_Expr('NULL as `is_new_asin_accepted`')));
     $collectionSellingFormat->getSelect()->where('component_mode = (?)', $this->nick);
     // ---------------------------------------
     // Prepare synchronization collection
     // ---------------------------------------
     $collectionSynchronization = Mage::getModel('M2ePro/Template_Synchronization')->getCollection();
     $collectionSynchronization->getSelect()->reset(Varien_Db_Select::COLUMNS);
     $collectionSynchronization->getSelect()->columns(array('id as template_id', 'title', new Zend_Db_Expr('\'' . self::TEMPLATE_SYNCHRONIZATION . '\' as `type`'), new Zend_Db_Expr('\'0\' as `marketplace_id`'), 'create_date', 'update_date', new Zend_Db_Expr('NULL as `category_path`'), new Zend_Db_Expr('NULL as `browsenode_id`'), new Zend_Db_Expr('NULL as `is_new_asin_accepted`')));
     $collectionSynchronization->getSelect()->where('component_mode = (?)', $this->nick);
     // ---------------------------------------
     // Prepare shipping override collection
     // ---------------------------------------
     $collectionShippingOverride = Mage::getModel('M2ePro/Amazon_Template_ShippingOverride')->getCollection();
     $collectionShippingOverride->getSelect()->reset(Varien_Db_Select::COLUMNS);
     $collectionShippingOverride->getSelect()->columns(array('id as template_id', 'title', new Zend_Db_Expr('\'' . self::TEMPLATE_SHIPPING_OVERRIDE . '\' as `type`'), 'marketplace_id', 'create_date', 'update_date', new Zend_Db_Expr('NULL as `category_path`'), new Zend_Db_Expr('NULL as `browsenode_id`'), new Zend_Db_Expr('NULL as `is_new_asin_accepted`')));
     // ---------------------------------------
     // Prepare shipping override collection
     // ---------------------------------------
     $collectionDescription = Mage::helper('M2ePro/Component_Amazon')->getCollection('Template_Description');
     $collectionDescription->getSelect()->join(array('mm' => Mage::getModel('M2ePro/Marketplace')->getResource()->getMainTable()), 'mm.id=second_table.marketplace_id', array());
     $collectionDescription->addFieldToFilter('mm.status', Ess_M2ePro_Model_Marketplace::STATUS_ENABLE);
     $collectionDescription->getSelect()->reset(Varien_Db_Select::COLUMNS);
     $collectionDescription->getSelect()->columns(array('id as template_id', 'title', new Zend_Db_Expr('\'' . self::TEMPLATE_DESCRIPTION . '\' as `type`'), 'second_table.marketplace_id', 'create_date', 'update_date', 'second_table.category_path', 'second_table.browsenode_id', 'second_table.is_new_asin_accepted'));
     // ---------------------------------------
     // Prepare union select
     // ---------------------------------------
     $unionSelect = $connRead->select();
     $unionSelect->union(array($collectionSellingFormat->getSelect(), $collectionSynchronization->getSelect(), $collectionDescription->getSelect(), $collectionShippingOverride->getSelect()));
     // ---------------------------------------
     // Prepare result collection
     // ---------------------------------------
     $resultCollection = new Varien_Data_Collection_Db($connRead);
     $resultCollection->getSelect()->reset()->from(array('main_table' => $unionSelect), array('template_id', 'title', 'type', 'marketplace_id', 'create_date', 'update_date', 'category_path', 'browsenode_id', 'is_new_asin_accepted'));
     // ---------------------------------------
     //        echo $resultCollection->getSelectSql(true); exit;
     $this->setCollection($resultCollection);
     return parent::_prepareCollection();
 }
Exemplo n.º 18
0
 public function __construct()
 {
     parent::__construct(Mage::getSingleton('core/resource')->getConnection('prescriptioncheckout_read'));
     $this->_shipTable = Mage::getSingleton('core/resource')->getTableName('ecommage_prescription');
     $this->_select->from(array("s" => $this->_shipTable))->order(array("prescription_id"));
     $this->_setIdFieldName('prescription_id');
     return $this;
 }
Exemplo n.º 19
0
 public function __construct()
 {
     $resources = Mage::getSingleton('core/resource');
     $this->_setIdFieldName('primary_id');
     parent::__construct($resources->getConnection('review_read'));
     $this->_summaryTable = $resources->getTableName('review/review_aggregate');
     $this->_select->from($this->_summaryTable);
 }
Exemplo n.º 20
0
 /**
  * Attachs data to collection
  *
  * @param Varien_Data_Collection_Db $collection
  * @return Enterprise_Customer_Model_Resource_Sales_Address_Abstract
  */
 public function attachDataToCollection(Varien_Data_Collection_Db $collection)
 {
     $items = array();
     $itemIds = array();
     foreach ($collection->getItems() as $item) {
         $itemIds[] = $item->getId();
         $items[$item->getId()] = $item;
     }
     if ($itemIds) {
         $select = $this->_getReadAdapter()->select()->from($this->getMainTable())->where("{$this->getIdFieldName()} IN (?)", $itemIds);
         $rowSet = $this->_getReadAdapter()->fetchAll($select);
         foreach ($rowSet as $row) {
             $items[$row[$this->getIdFieldName()]]->addData($row);
         }
     }
     return $this;
 }
Exemplo n.º 21
0
 public function __construct()
 {
     parent::__construct(Mage::getSingleton('core/resource')->getConnection('shipping_read'));
     $this->_shipTable = Mage::getSingleton('core/resource')->getTableName('av5_correios_shipping/correios');
     $this->_select->from(array("s" => $this->_shipTable))->order("valor");
     $this->_setIdFieldName('id');
     return $this;
 }
Exemplo n.º 22
0
 protected function _prepareCollection()
 {
     // Get collection products in listing
     //--------------------------------
     $nameAttribute = Mage::getResourceModel('catalog/product')->getAttribute('name');
     $nameAttributeId = $nameAttribute ? (int) $nameAttribute->getId() : 0;
     $listingProductCollection = Mage::helper('M2ePro/Component_Ebay')->getCollection('Listing_Product');
     $listingProductCollection->getSelect()->distinct();
     $listingProductCollection->getSelect()->join(array('l' => Mage::getResourceModel('M2ePro/Listing')->getMainTable()), '`l`.`id` = `main_table`.`listing_id`');
     $listingProductCollection->getSelect()->join(array('em' => Mage::getResourceModel('M2ePro/Ebay_Marketplace')->getMainTable()), '`em`.`marketplace_id` = `l`.`marketplace_id`');
     $listingProductCollection->getSelect()->join(array('cpe' => Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')), 'cpe.entity_id = `main_table`.product_id');
     $listingProductCollection->getSelect()->joinLeft(array('cpev' => Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')), '`cpev`.`entity_id` = `main_table`.`product_id`' . ' AND `cpev`.`attribute_id` = ' . $nameAttributeId . ' AND `cpev`.`store_id` = 0');
     $listingProductCollection->getSelect()->joinLeft(array('ebit' => Mage::getResourceModel('M2ePro/Ebay_Item')->getMainTable()), '(`ebit`.`id` = `second_table`.`ebay_item_id`)', array('item_id'));
     //------------------------------
     // add stock availability, status & visibility to select
     //------------------------------
     $listingProductCollection->getSelect()->joinLeft(array('cisi' => Mage::getResourceModel('cataloginventory/stock_item')->getMainTable()), '(`cisi`.`product_id` = `main_table`.`product_id` AND `cisi`.`stock_id` = 1)', array('is_in_stock'));
     //------------------------------
     $listingProductCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
     $listingProductCollection->getSelect()->columns(array('account_id' => 'l.account_id', 'marketplace_id' => 'l.marketplace_id', 'product_id' => 'main_table.product_id', 'product_name' => 'cpev.value', 'product_sku' => 'cpe.sku', 'currency' => 'em.currency', 'ebay_item_id' => 'ebit.item_id', 'status' => 'main_table.status', 'online_sku' => 'second_table.online_sku', 'online_title' => 'second_table.online_title', 'online_qty' => new Zend_Db_Expr('(second_table.online_qty - second_table.online_qty_sold)'), 'online_qty_sold' => 'second_table.online_qty_sold', 'online_buyitnow_price' => 'second_table.online_buyitnow_price', 'listing_id' => 'l.id', 'listing_title' => 'l.title', 'is_m2epro_listing' => new Zend_Db_Expr(1), 'is_in_stock' => 'cisi.is_in_stock'));
     //------------------------------
     //------------------------------
     $listingOtherCollection = Mage::helper('M2ePro/Component_Ebay')->getCollection('Listing_Other');
     $listingOtherCollection->getSelect()->distinct();
     // add stock availability, type id, status & visibility to select
     //------------------------------
     $listingOtherCollection->getSelect()->joinLeft(array('cisi' => Mage::getResourceModel('cataloginventory/stock_item')->getMainTable()), '(`cisi`.`product_id` = `main_table`.`product_id` AND cisi.stock_id = 1)', array('is_in_stock'));
     //------------------------------
     $listingOtherCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
     $listingOtherCollection->getSelect()->columns(array('account_id' => 'main_table.account_id', 'marketplace_id' => 'main_table.marketplace_id', 'product_id' => 'main_table.product_id', 'product_name' => 'second_table.title', 'product_sku' => 'second_table.sku', 'currency' => 'second_table.currency', 'ebay_item_id' => 'second_table.item_id', 'status' => 'main_table.status', 'online_sku' => new Zend_Db_Expr('NULL'), 'online_title' => new Zend_Db_Expr('NULL'), 'online_qty' => new Zend_Db_Expr('(second_table.online_qty - second_table.online_qty_sold)'), 'online_qty_sold' => 'second_table.online_qty_sold', 'online_buyitnow_price' => 'second_table.online_price', 'listing_id' => new Zend_Db_Expr('NULL'), 'listing_title' => new Zend_Db_Expr('NULL'), 'is_m2epro_listing' => new Zend_Db_Expr(0), 'is_in_stock' => 'cisi.is_in_stock'));
     //------------------------------
     //------------------------------
     $selects = array($listingProductCollection->getSelect());
     if (Mage::helper('M2ePro/View_Ebay')->isAdvancedMode()) {
         $selects[] = $listingOtherCollection->getSelect();
     }
     $unionSelect = Mage::getResourceModel('core/config')->getReadConnection()->select();
     $unionSelect->union($selects);
     $resultCollection = new Varien_Data_Collection_Db(Mage::getResourceModel('core/config')->getReadConnection());
     $resultCollection->getSelect()->reset()->from(array('main_table' => $unionSelect), array('account_id', 'marketplace_id', 'product_id', 'product_name', 'product_sku', 'currency', 'ebay_item_id', 'status', 'online_sku', 'online_title', 'online_qty', 'online_qty_sold', 'online_buyitnow_price', 'listing_id', 'listing_title', 'is_m2epro_listing', 'is_in_stock'));
     //------------------------------
     $this->setCollection($resultCollection);
     //        exit($resultCollection->getSelect().'');
     return parent::_prepareCollection();
 }
Exemplo n.º 23
0
 /**
  * Test that after cloning collection $this->_select in initial and cloned collections
  * do not reference the same object
  *
  * @covers Varien_Data_Collection_Db::__clone
  */
 public function testClone()
 {
     $adapter = $this->getMockForAbstractClass('Zend_Db_Adapter_Abstract', array(), '', false);
     $this->_collection->setConnection($adapter);
     $this->assertInstanceOf('Zend_Db_Select', $this->_collection->getSelect());
     $clonedCollection = clone $this->_collection;
     $this->assertInstanceOf('Zend_Db_Select', $clonedCollection->getSelect());
     $this->assertNotSame($clonedCollection->getSelect(), $this->_collection->getSelect(), 'Collection was cloned but $this->_select in both initial and cloned collections reference the same object');
 }
Exemplo n.º 24
0
 /**
  * Test that after cloning collection $this->_select in initial and cloned collections
  * do not reference the same object
  *
  * @covers Varien_Data_Collection_Db::__clone
  */
 public function testClone()
 {
     $adapter = $this->_getAdapterMock('Zend_Db_Adapter_Pdo_Mysql', null, null);
     $this->_collection->setConnection($adapter);
     $this->assertInstanceOf('Zend_Db_Select', $this->_collection->getSelect());
     $clonedCollection = clone $this->_collection;
     $this->assertInstanceOf('Zend_Db_Select', $clonedCollection->getSelect());
     $this->assertNotSame($clonedCollection->getSelect(), $this->_collection->getSelect(), 'Collection was cloned but $this->_select in both initial and cloned collections reference the same object');
 }
Exemplo n.º 25
0
 /**
  * Enter description here ...
  *
  */
 public function __construct()
 {
     $resources = Mage::getSingleton('Mage_Core_Model_Resource');
     $this->_setIdFieldName('primary_id');
     parent::__construct($resources->getConnection('review_read'));
     $this->_summaryTable = $resources->getTableName('review_entity_summary');
     $this->_select->from($this->_summaryTable);
     $this->setItemObjectClass(Mage::getConfig()->getModelClassName('Mage_Review_Model_Review_Summary'));
 }
 public function __construct()
 {
     $resources = AO::getSingleton('core/resource');
     $this->_setIdFieldName('primary_id');
     parent::__construct($resources->getConnection('review_read'));
     $this->_summaryTable = $resources->getTableName('review/review_aggregate');
     $this->_select->from($this->_summaryTable);
     $this->setItemObjectClass(AO::getConfig()->getModelClassName('review/review_summary'));
 }
Exemplo n.º 27
0
 public function __construct()
 {
     parent::__construct(Mage::getSingleton('core/resource')->getConnection('shipping_read'));
     $this->_shipTable = Mage::getSingleton('core/resource')->getTableName('matrixrate_shipping/matrixrate');
     $this->_countryTable = Mage::getSingleton('core/resource')->getTableName('directory/country');
     $this->_regionTable = Mage::getSingleton('core/resource')->getTableName('directory/country_region');
     $this->_select->from(array("s" => $this->_shipTable))->joinLeft(array("c" => $this->_countryTable), 'c.country_id = s.dest_country_id', 'iso3_code AS dest_country')->joinLeft(array("r" => $this->_regionTable), 'r.region_id = s.dest_region_id', 'code AS dest_region')->order(array("dest_country", "dest_region", "dest_zip"));
     $this->_setIdFieldName('pk');
     return $this;
 }
Exemplo n.º 28
0
 public function __construct()
 {
     parent::__construct(Mage::getSingleton('core/resource')->getConnection('shipping_read'));
     $this->_shipTable = Mage::getSingleton('core/resource')->getTableName('matrixrate_shipping/matrixrate');
     //        $this->_countryTable = Mage::getSingleton('core/resource')->getTableName('directory/country');
     //        $this->_regionTable = Mage::getSingleton('core/resource')->getTableName('directory/country_region');
     $this->_select->from(array("s" => $this->_shipTable))->order(array("zone"));
     $this->_setIdFieldName('pk');
     return $this;
 }
 public function __construct($idFieldName = NULL)
 {
     $connRead = Mage::getResourceModel('core/config')->getReadConnection();
     parent::__construct($connRead);
     if (!is_null($idFieldName)) {
         $this->_idFieldName = $idFieldName;
     }
     $table = Mage::getSingleton('core/resource')->getTableName('m2epro_ebay_dictionary_motor_ktype');
     $this->getSelect()->reset()->from(array('main_table' => $table));
 }
Exemplo n.º 30
0
 /**
  * Inner join the groupscatalog index table to hide entities not visible to the specified customer group id
  *
  * @param Varien_Data_Collection_Db $collection
  * @param int $groupId The customer group id
  * @return void
  */
 public function addGroupsCatalogFilterToCollection(Varien_Data_Collection_Db $collection, $groupId)
 {
     /* @var $helper Netzarbeiter_GroupsCatalog2_Helper_Data */
     $helper = Mage::helper('netzarbeiter_groupscatalog2');
     /**
      * This is slightly complicated but it works with products and
      * categories whether the flat tables enabled or not
      *
      * @var $entityType string
      * @var $entity Mage_Catalog_Model_Abstract
      */
     $entity = $collection->getNewEmptyItem();
     $entityType = $helper->getEntityTypeCodeFromEntity($entity);
     $this->_init($helper->getIndexTableByEntityType($entityType), 'id');
     if ($this->_doesIndexExists()) {
         $filterTable = $collection->getResource()->getTable($helper->getIndexTableByEntityType($entityType));
         $entityIdField = "{$this->_getCollectionTableAlias($collection)}.entity_id";
         $this->_addGroupsCatalogFilterToSelect($collection->getSelect(), $filterTable, $groupId, $collection->getStoreId(), $entityIdField);
     }
 }