本文整理汇总了PHP中Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection类的典型用法代码示例。如果您正苦于以下问题:PHP AbstractCollection类的具体用法?PHP AbstractCollection怎么用?PHP AbstractCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AbstractCollection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: massAction
/**
* Unhold selected orders
*
* @param AbstractCollection $collection
* @return \Magento\Backend\Model\View\Result\Redirect
*/
protected function massAction(AbstractCollection $collection)
{
$countUnHoldOrder = 0;
/** @var \Magento\Sales\Model\Order $order */
foreach ($collection->getItems() as $order) {
$order->load($order->getId());
if (!$order->canUnhold()) {
continue;
}
$order->unhold();
$order->save();
$countUnHoldOrder++;
}
$countNonUnHoldOrder = $collection->count() - $countUnHoldOrder;
if ($countNonUnHoldOrder && $countUnHoldOrder) {
$this->messageManager->addError(__('%1 order(s) were not released from on hold status.', $countNonUnHoldOrder));
} elseif ($countNonUnHoldOrder) {
$this->messageManager->addError(__('No order(s) were released from on hold status.'));
}
if ($countUnHoldOrder) {
$this->messageManager->addSuccess(__('%1 order(s) have been released from on hold status.', $countUnHoldOrder));
}
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath($this->getComponentRefererUrl());
return $resultRedirect;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:32,代码来源:MassUnhold.php
示例2: addIsUsedFilterCallback
/**
* Callback function that filters collection by field "Used" from grid
*
* @param AbstractCollection $collection
* @param Column $column
* @return void
*/
public function addIsUsedFilterCallback($collection, $column)
{
$filterValue = $column->getFilter()->getCondition();
$expression = $this->getConnection()->getCheckSql('main_table.times_used > 0', 1, 0);
$conditionSql = $this->_getConditionSql($expression, $filterValue);
$collection->getSelect()->where($conditionSql);
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:14,代码来源:Collection.php
示例3: massAction
/**
* Print shipments for selected orders
*
* @param AbstractCollection $collection
* @return ResponseInterface|\Magento\Backend\Model\View\Result\Redirect
*/
protected function massAction(AbstractCollection $collection)
{
$shipmentsCollection = $this->shipmentCollectionFactotory->create()->setOrderFilter(['in' => $collection->getAllIds()]);
if (!$shipmentsCollection->getSize()) {
$this->messageManager->addError(__('There are no printable documents related to selected orders.'));
return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl());
}
return $this->fileFactory->create(sprintf('packingslip%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), $this->pdfShipment->getPdf($shipmentsCollection->getItems())->render(), DirectoryList::VAR_DIR, 'application/pdf');
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:Pdfshipments.php
示例4: _processAction
/**
* Delete all records in collection. Return count of successful operations.
*
* @param AbstractCollection $collection
*
* @return int
*/
protected function _processAction(AbstractCollection $collection)
{
$count = 0;
/** @var \ISM\Blog\Model\Post $model */
foreach ($collection->getItems() as $model) {
$model->delete();
++$count;
}
return $count;
}
开发者ID:swnsma,项目名称:practice,代码行数:17,代码来源:MassDelete.php
示例5: _processAction
protected function _processAction(AbstractCollection $collection)
{
$count = 0;
foreach ($collection->getItems() as $model) {
/** @var \ISM\Blog\Model\Post $model */
$model->setIsActive(false);
$model->save();
++$count;
}
return $count;
}
开发者ID:swnsma,项目名称:practice,代码行数:11,代码来源:MassDisable.php
示例6: massAction
/**
* Batch print shipping labels for whole shipments.
* Push pdf document with shipping labels to user browser
*
* @param AbstractCollection $collection
* @return ResponseInterface|ResultInterface
*/
protected function massAction(AbstractCollection $collection)
{
$labelsContent = [];
if ($collection->getSize()) {
/** @var \Magento\Sales\Model\Order\Shipment $shipment */
foreach ($collection as $shipment) {
$labelContent = $shipment->getShippingLabel();
if ($labelContent) {
$labelsContent[] = $labelContent;
}
}
}
if (!empty($labelsContent)) {
$outputPdf = $this->labelGenerator->combineLabelsPdf($labelsContent);
return $this->fileFactory->create('ShippingLabels.pdf', $outputPdf->render(), DirectoryList::VAR_DIR, 'application/pdf');
}
$this->messageManager->addError(__('There are no shipping labels related to selected shipments.'));
return $this->resultRedirectFactory->create()->setPath('sales/shipment/');
}
开发者ID:Doability,项目名称:magento2dev,代码行数:26,代码来源:MassPrintShippingLabel.php
示例7: massAction
public function massAction(AbstractCollection $collection)
{
foreach ($collection->getItems() as $order) {
try {
// Check if case already exists for this order
if ($this->_helper->doesCaseExist($order)) {
continue;
}
$orderData = $this->_helper->processOrderData($order);
// Add order to database
$this->_helper->createNewCase($order);
// Post case to signifyd service
$this->_helper->postCaseToSignifyd($orderData, $order);
} catch (\Exception $ex) {
$this->_logger->error($ex->getMessage());
}
}
$this->messageManager->addSuccessMessage(__('Success.'));
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath($this->getComponentRefererUrl());
return $resultRedirect;
}
开发者ID:signifyd,项目名称:magento2,代码行数:22,代码来源:Send.php
示例8: massAction
/**
* Hold selected orders
*
* @param AbstractCollection $collection
* @return \Magento\Backend\Model\View\Result\Redirect
*/
protected function massAction(AbstractCollection $collection)
{
$countHoldOrder = 0;
foreach ($collection->getItems() as $order) {
if (!$order->canHold()) {
continue;
}
$this->orderManagement->hold($order->getEntityId());
$countHoldOrder++;
}
$countNonHoldOrder = $collection->count() - $countHoldOrder;
if ($countNonHoldOrder && $countHoldOrder) {
$this->messageManager->addError(__('%1 order(s) were not put on hold.', $countNonHoldOrder));
} elseif ($countNonHoldOrder) {
$this->messageManager->addError(__('No order(s) were put on hold.'));
}
if ($countHoldOrder) {
$this->messageManager->addSuccess(__('You have put %1 order(s) on hold.', $countHoldOrder));
}
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath($this->getComponentRefererUrl());
return $resultRedirect;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:29,代码来源:MassHold.php
示例9: _prepareCache
/**
* @param \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection $collection
*/
protected function _prepareCache($collection)
{
$stmt = $collection->getSelect()->query();
$ids = array();
foreach ($stmt as $item) {
$ids = array_merge($ids, array_map('intval', explode('/', $item['path'])));
}
$ids = array_unique($ids);
if (empty($ids)) {
return;
}
/* @var $attribute \Magento\Eav\Model\Attribute */
$attribute = $collection->getFirstItem()->getResource()->getAttribute('name');
$resource = $collection->getResource();
$tableName = \Magento\Catalog\Model\Category::ENTITY . '_entity_' . $attribute->getBackendType();
$dbSelect1 = $resource->getConnection()->select()->from($resource->getTable($tableName), new \Zend_Db_Expr('MAX(`store_id`)'))->where("`entity_id` = `ccev`.`entity_id`")->where("`attribute_id` = `ccev`.`attribute_id`")->where("`store_id` = 0 OR `store_id` = ?", $this->getStoreId());
$dbSelect2 = $resource->getConnection()->select()->from(array('ccev' => $resource->getTable($tableName)), array('name' => 'value', 'category_id' => 'entity_id'))->where('ccev.entity_id IN (' . implode(',', $ids) . ')')->where('ccev.attribute_id = ?', $attribute->getAttributeId())->where('ccev.store_id = (' . $dbSelect1->__toString() . ')');
$cacheData = array();
foreach ($resource->getConnection()->fetchAll($dbSelect2) as $row) {
$cacheData[$row['category_id']] = $row['name'];
}
$this->setData('categories_cache', $cacheData);
}
开发者ID:Doability,项目名称:magento2dev,代码行数:26,代码来源:Grid.php
示例10: massAction
/**
* Cancel selected orders
*
* @param AbstractCollection $collection
* @return \Magento\Backend\Model\View\Result\Redirect
*/
protected function massAction(AbstractCollection $collection)
{
$countCancelOrder = 0;
foreach ($collection->getItems() as $order) {
if (!$order->canCancel()) {
continue;
}
$order->cancel();
$order->save();
$countCancelOrder++;
}
$countNonCancelOrder = $collection->count() - $countCancelOrder;
if ($countNonCancelOrder && $countCancelOrder) {
$this->messageManager->addError(__('%1 order(s) cannot be canceled.', $countNonCancelOrder));
} elseif ($countNonCancelOrder) {
$this->messageManager->addError(__('You cannot cancel the order(s).'));
}
if ($countCancelOrder) {
$this->messageManager->addSuccess(__('We canceled %1 order(s).', $countCancelOrder));
}
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath($this->getComponentRefererUrl());
return $resultRedirect;
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:30,代码来源:MassCancel.php
示例11: massAction
/**
* Cancel selected orders
*
* @param AbstractCollection $collection
* @return \Magento\Backend\Model\View\Result\Redirect
*/
protected function massAction(AbstractCollection $collection)
{
$countCancelOrder = 0;
$connection = $this->_resource->getConnection(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION);
$showTables = $connection->fetchCol('show tables');
//start get table name
$tblSalesOrder = $connection->getTableName('sales_order');
$tblSalesCreditmemoComment = $connection->getTableName('sales_creditmemo_comment');
$tblSalesCreditmemoItem = $connection->getTableName('sales_creditmemo_item');
$tblSalesCreditmemo = $connection->getTableName('sales_creditmemo');
$tblSalesCreditmemoGrid = $connection->getTableName('sales_creditmemo_grid');
$tblSalesInvoiceComment = $connection->getTableName('sales_invoice_comment');
$tblSalesInvoiceItem = $connection->getTableName('sales_invoice_item');
$tblSalesInvoice = $connection->getTableName('sales_invoice');
$tblSalesInvoiceGrid = $connection->getTableName('sales_invoice_grid');
$tblQuoteAddressItem = $connection->getTableName('quote_address_item');
$tblQuoteItemOption = $connection->getTableName('quote_item_option');
$tblQuote = $connection->getTableName('quote');
$tblQuoteAddress = $connection->getTableName('quote_address');
$tblQuoteItem = $connection->getTableName('quote_item');
$tblQuotePayment = $connection->getTableName('quote_payment');
$tblQuoteShippingRate = $connection->getTableName('quote_shipping_rate');
$tblQuoteIDMask = $connection->getTableName('quote_id_mask');
$tblSalesShipmentComment = $connection->getTableName('sales_shipment_comment');
$tblSalesShipmentItem = $connection->getTableName('sales_shipment_item');
$tblSalesShipmentTrack = $connection->getTableName('sales_shipment_track');
$tblSalesShipment = $connection->getTableName('sales_shipment');
$tblSalesShipmentGrid = $connection->getTableName('sales_shipment_grid');
$tblSalesOrderAddress = $connection->getTableName('sales_order_address');
$tblSalesOrderItem = $connection->getTableName('sales_order_item');
$tblSalesOrderPayment = $connection->getTableName('sales_order_payment');
$tblSalesOrderStatusHistory = $connection->getTableName('sales_order_status_history');
$tblSalesOrderGrid = $connection->getTableName('sales_order_grid');
$tblLogQuote = $connection->getTableName('log_quote');
$showTablesLog = $connection->fetchCol('SHOW TABLES LIKE ?', '%' . $tblLogQuote);
$tblSalesOrderTax = $connection->getTableName('sales_order_tax');
foreach ($collection->getItems() as $order) {
$orderId = $order->getId();
if ($order->getIncrementId()) {
$incId = $order->getIncrementId();
if (in_array($tblSalesOrder, $showTables)) {
$result1 = $connection->fetchAll('SELECT quote_id FROM `' . $tblSalesOrder . '` WHERE entity_id=' . $orderId);
$quoteId = (int) $result1[0]['quote_id'];
}
$connection->rawQuery('SET FOREIGN_KEY_CHECKS=1');
if (in_array($tblSalesCreditmemoComment, $showTables)) {
$connection->rawQuery('DELETE FROM `' . $tblSalesCreditmemoComment . '` WHERE parent_id IN (SELECT entity_id FROM `' . $tblSalesCreditmemo . '` WHERE order_id=' . $orderId . ')');
}
if (in_array('sales__creditmemo_item', $showTables)) {
$connection->rawQuery('DELETE FROM `' . $tblSalesCreditmemoItem . '` WHERE parent_id IN (SELECT entity_id FROM `' . $tblSalesCreditmemo . '` WHERE order_id=' . $orderId . ')');
}
if (in_array($tblSalesCreditmemo, $showTables)) {
$connection->rawQuery('DELETE FROM `' . $tblSalesCreditmemo . '` WHERE order_id=' . $orderId);
}
if (in_array($tblSalesCreditmemoGrid, $showTables)) {
$connection->rawQuery('DELETE FROM `' . $tblSalesCreditmemoGrid . '` WHERE order_id=' . $orderId);
}
if (in_array($tblSalesInvoiceComment, $showTables)) {
$connection->rawQuery('DELETE FROM `' . $tblSalesInvoiceComment . '` WHERE parent_id IN (SELECT entity_id FROM `' . $tblSalesInvoice . '` WHERE order_id=' . $orderId . ')');
}
if (in_array($tblSalesInvoiceItem, $showTables)) {
$connection->rawQuery('DELETE FROM `' . $tblSalesInvoiceItem . '` WHERE parent_id IN (SELECT entity_id FROM `' . $tblSalesInvoice . '` WHERE order_id=' . $orderId . ')');
}
if (in_array($tblSalesInvoice, $showTables)) {
$connection->rawQuery('DELETE FROM `' . $tblSalesInvoice . '` WHERE order_id=' . $orderId);
}
if (in_array($tblSalesInvoiceGrid, $showTables)) {
$connection->rawQuery('DELETE FROM `' . $tblSalesInvoiceGrid . '` WHERE order_id=' . $orderId);
}
if ($quoteId) {
if (in_array($tblQuoteAddressItem, $showTables)) {
$connection->rawQuery('DELETE FROM `' . $tblQuoteAddressItem . '` WHERE parent_item_id IN (SELECT address_id FROM `' . $tblQuoteAddress . '` WHERE quote_id=' . $quoteId . ')');
}
if (in_array($tblQuoteShippingRate, $showTables)) {
$connection->rawQuery('DELETE FROM `' . $tblQuoteShippingRate . '` WHERE address_id IN (SELECT address_id FROM `' . $tblQuoteAddress . '` WHERE quote_id=' . $quoteId . ')');
}
if (in_array($tblQuoteIDMask, $showTables)) {
$connection->rawQuery('DELETE FROM `' . $tblQuoteIDMask . '` where quote_id=' . $quoteId);
}
if (in_array($tblQuoteItemOption, $showTables)) {
$connection->rawQuery('DELETE FROM `' . $tblQuoteItemOption . '` WHERE item_id IN (SELECT item_id FROM `' . $tblQuoteItem . '` WHERE quote_id=' . $quoteId . ')');
}
if (in_array($tblQuote, $showTables)) {
$connection->rawQuery('DELETE FROM `' . $tblQuote . '` WHERE entity_id=' . $quoteId);
}
if (in_array($tblQuoteAddress, $showTables)) {
$connection->rawQuery('DELETE FROM `' . $tblQuoteAddress . '` WHERE quote_id=' . $quoteId);
}
if (in_array($tblQuoteItem, $showTables)) {
$connection->rawQuery('DELETE FROM `' . $tblQuoteItem . '` WHERE quote_id=' . $quoteId);
}
if (in_array('sales__quotePayment', $showTables)) {
$connection->rawQuery('DELETE FROM `' . $tblQuotePayment . '` WHERE quote_id=' . $quoteId);
}
//.........这里部分代码省略.........
开发者ID:Rukhsar,项目名称:magento2-DeleteOrder-extension,代码行数:101,代码来源:MassDelete.php
示例12: addFieldToFilter
/**
* @inheritdoc
*/
public function addFieldToFilter($field, $condition = null)
{
if (in_array($field, ['created_at', 'updated_at'], true)) {
$field = 'main_table.' . $field;
}
return parent::addFieldToFilter($field, $condition);
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:10,代码来源:Collection.php
示例13: _afterLoad
/**
* {@inheritdoc}
*/
protected function _afterLoad()
{
foreach ($this->_items as $item) {
$item->setIndex($this->index);
}
return parent::_afterLoad();
}
开发者ID:Doability,项目名称:magento2dev,代码行数:10,代码来源:Collection.php
示例14: __construct
/**
* @param EntityFactory $entityFactory
* @param Logger $logger
* @param FetchStrategy $fetchStrategy
* @param EventManager $eventManager
* @param string $mainTable
* @param string $resourceModel
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function __construct(EntityFactory $entityFactory, Logger $logger, FetchStrategy $fetchStrategy, EventManager $eventManager, $mainTable, $resourceModel)
{
$this->_init('Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\Document', $resourceModel);
$this->setMainTable(true);
$this->setMainTable($this->_resource->getTable($mainTable));
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, null, null);
$this->_setIdFieldName($this->getResource()->getIdFieldName());
}
开发者ID:koliaGI,项目名称:magento2,代码行数:17,代码来源:SearchResult.php
示例15: _beforeLoad
/**
* Load collection data
*
* @return $this
*/
public function _beforeLoad()
{
if (!$this->getLoadDefault()) {
$this->setWithoutDefaultFilter();
}
$this->addOrder('main_table.name', self::SORT_ORDER_ASC);
return parent::_beforeLoad();
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:13,代码来源:Collection.php
示例16: __construct
/**
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
* @param \Magento\Framework\Event\ManagerInterface $eventManager
* @param null|\Zend_Db_Adapter_Abstract $mainTable
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $eventPrefix
* @param string $eventObject
* @param string $resourceModel
* @param string $model
* @param string|null $connection
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, $mainTable, $eventPrefix, $eventObject, $resourceModel, $model = 'Magento\\Sales\\Model\\ResourceModel\\Grid\\Document', $connection = null, \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null)
{
$this->_eventPrefix = $eventPrefix;
$this->_eventObject = $eventObject;
$this->_init($model, $resourceModel);
$this->setMainTable($mainTable);
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:23,代码来源:Collection.php
示例17: _afterLoadData
/**
* Process loaded collection data
*
* @return $this
*/
protected function _afterLoadData()
{
parent::_afterLoadData();
$this->addCustomerTaxClassesToResult();
$this->addProductTaxClassesToResult();
$this->addRatesToResult();
return $this;
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:13,代码来源:Collection.php
示例18: _initSelect
/**
* Initialize select object
*
* @return $this
*/
protected function _initSelect()
{
parent::_initSelect();
$locale = $this->_localeResolver->getLocale();
$this->addBindParam(':region_locale', $locale);
$this->getSelect()->joinLeft(['rname' => $this->_regionNameTable], 'main_table.region_id = rname.region_id AND rname.locale = :region_locale', ['name']);
return $this;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:13,代码来源:Collection.php
示例19: _initSelect
public function _initSelect()
{
parent::_initSelect();
$this->_select->joinLeft(['country_table' => $this->_countryTable], 'country_table.country_id = main_table.dest_country_id', ['dest_country' => 'iso3_code'])->joinLeft(['region_table' => $this->_regionTable], 'region_table.region_id = main_table.dest_region_id', ['dest_region' => 'code']);
$this->addOrder('dest_country', self::SORT_ORDER_ASC);
$this->addOrder('dest_region', self::SORT_ORDER_ASC);
$this->addOrder('dest_zip', self::SORT_ORDER_ASC);
}
开发者ID:Doability,项目名称:magento2dev,代码行数:8,代码来源:Collection.php
示例20: __construct
/**
* @param EntityFactory $entityFactory
* @param Logger $logger
* @param FetchStrategy $fetchStrategy
* @param EventManager $eventManager
* @param string $mainTable
* @param string $resourceModel
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function __construct(EntityFactory $entityFactory, Logger $logger, FetchStrategy $fetchStrategy, EventManager $eventManager, $mainTable, $resourceModel)
{
$this->_init($this->document, $resourceModel);
$this->setMainTable(true);
$this->setMainTable($this->_resource->getTable($mainTable));
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, null, null);
$this->_setIdFieldName($this->getResource()->getIdFieldName());
}
开发者ID:Doability,项目名称:magento2dev,代码行数:17,代码来源:SearchResult.php
注:本文中的Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论