本文整理汇总了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();
}