本文整理汇总了PHP中Varien_Data_Collection_Db类的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Data_Collection_Db类的具体用法?PHP Varien_Data_Collection_Db怎么用?PHP Varien_Data_Collection_Db使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Varien_Data_Collection_Db类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addCustomAttributes
/**
* 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;
}
示例2: _prepareCollection
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();
}
示例3: _prepareCollection
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();
}
示例4: _prepareCollection
/**
* 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;
}
示例5: addMotorsSpecificsAttributeToSelect
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'));
}
示例6: applyLogToCollection
/**
* 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');
}
示例7: addThrottleFilter
/**
* 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;
}
示例8: addStatusFilterToOrders
/**
* 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;
}
示例9: unlinkEmails
/**
* 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();
}
}
示例10: _prepareCollection
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();
}
示例11: attachDataToCollection
/**
* 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;
}
示例12: __construct
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'));
}
示例13: __construct
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'));
}
示例14: __construct
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'));
}
示例15: __construct
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');
}