本文整理汇总了PHP中Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection::getItems方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractCollection::getItems方法的具体用法?PHP AbstractCollection::getItems怎么用?PHP AbstractCollection::getItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
的用法示例。
在下文中一共展示了AbstractCollection::getItems方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: _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;
}
示例3: _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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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);
}
//.........这里部分代码省略.........
示例8: applySalableProductTypesFilter
/**
* Filter collection by removing not available product types
*
* @param \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection $collection
* @return \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
*/
public function applySalableProductTypesFilter($collection)
{
$productTypes = $this->_salesConfig->getAvailableProductTypes();
foreach ($collection->getItems() as $key => $item) {
if ($item instanceof \Magento\Catalog\Model\Product) {
$type = $item->getTypeId();
} elseif ($item instanceof \Magento\Sales\Model\Order\Item) {
$type = $item->getProductType();
} elseif ($item instanceof \Magento\Quote\Model\Quote\Item) {
$type = $item->getProductType();
} else {
$type = '';
}
if (!in_array($type, $productTypes)) {
$collection->removeItemByKey($key);
}
}
return $collection;
}