本文整理匯總了PHP中Magento\Framework\Model\Resource\Db\Collection\AbstractCollection::count方法的典型用法代碼示例。如果您正苦於以下問題:PHP AbstractCollection::count方法的具體用法?PHP AbstractCollection::count怎麽用?PHP AbstractCollection::count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Framework\Model\Resource\Db\Collection\AbstractCollection
的用法示例。
在下文中一共展示了AbstractCollection::count方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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;
}
$order->hold();
$order->save();
$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('sales/*/');
return $resultRedirect;
}
示例2: 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('sales/*/');
return $resultRedirect;
}
示例3: count
/**
* Retrieve count of loaded items
*
* @return int
*/
public function count()
{
$this->filterPool->applyFilters($this->collection);
return $this->collection->count();
}