本文整理汇总了PHP中Magento\Framework\Model\AbstractModel::getEntityId方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractModel::getEntityId方法的具体用法?PHP AbstractModel::getEntityId怎么用?PHP AbstractModel::getEntityId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Model\AbstractModel
的用法示例。
在下文中一共展示了AbstractModel::getEntityId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: aroundDelete
/**
* Reindex on product delete
*
* @param \Magento\Catalog\Model\ResourceModel\Product $productResource
* @param \Closure $proceed
* @param \Magento\Framework\Model\AbstractModel $product
* @return \Magento\Catalog\Model\ResourceModel\Product
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundDelete(\Magento\Catalog\Model\ResourceModel\Product $productResource, \Closure $proceed, \Magento\Framework\Model\AbstractModel $product)
{
$productResource->addCommitCallback(function () use($product) {
$this->reindexRow($product->getEntityId());
});
return $proceed($product);
}
示例2: aggregate
/**
* Aggregate
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return void
*/
public function aggregate($object)
{
$readAdapter = $this->_getReadAdapter();
$writeAdapter = $this->_getWriteAdapter();
if (!$object->getEntityPkValue() && $object->getId()) {
$object->load($object->getReviewId());
}
$ratingModel = $this->_ratingFactory->create();
$ratingSummaries = $ratingModel->getEntitySummary($object->getEntityPkValue(), false);
foreach ($ratingSummaries as $ratingSummaryObject) {
if ($ratingSummaryObject->getCount()) {
$ratingSummary = round($ratingSummaryObject->getSum() / $ratingSummaryObject->getCount());
} else {
$ratingSummary = $ratingSummaryObject->getSum();
}
$reviewsCount = $this->getTotalReviews($object->getEntityPkValue(), true, $ratingSummaryObject->getStoreId());
$select = $readAdapter->select()->from($this->_aggregateTable)->where('entity_pk_value = :pk_value')->where('entity_type = :entity_type')->where('store_id = :store_id');
$bind = [':pk_value' => $object->getEntityPkValue(), ':entity_type' => $object->getEntityId(), ':store_id' => $ratingSummaryObject->getStoreId()];
$oldData = $readAdapter->fetchRow($select, $bind);
$data = new \Magento\Framework\Object();
$data->setReviewsCount($reviewsCount)->setEntityPkValue($object->getEntityPkValue())->setEntityType($object->getEntityId())->setRatingSummary($ratingSummary > 0 ? $ratingSummary : 0)->setStoreId($ratingSummaryObject->getStoreId());
$writeAdapter->beginTransaction();
try {
if ($oldData['primary_id'] > 0) {
$condition = ["{$this->_aggregateTable}.primary_id = ?" => $oldData['primary_id']];
$writeAdapter->update($this->_aggregateTable, $data->getData(), $condition);
} else {
$writeAdapter->insert($this->_aggregateTable, $data->getData());
}
$writeAdapter->commit();
} catch (\Exception $e) {
$writeAdapter->rollBack();
}
}
}
示例3: aggregateReviewSummary
/**
* Aggregate review summary
*
* @param \Magento\Framework\Model\AbstractModel $object
* @param \Magento\Review\Model\Rating $ratingSummaryObject
* @return void
*/
protected function aggregateReviewSummary($object, $ratingSummaryObject)
{
$readAdapter = $this->_getReadAdapter();
if ($ratingSummaryObject->getCount()) {
$ratingSummary = round($ratingSummaryObject->getSum() / $ratingSummaryObject->getCount());
} else {
$ratingSummary = $ratingSummaryObject->getSum();
}
$reviewsCount = $this->getTotalReviews($object->getEntityPkValue(), true, $ratingSummaryObject->getStoreId());
$select = $readAdapter->select()->from($this->_aggregateTable)->where('entity_pk_value = :pk_value')->where('entity_type = :entity_type')->where('store_id = :store_id');
$bind = [':pk_value' => $object->getEntityPkValue(), ':entity_type' => $object->getEntityId(), ':store_id' => $ratingSummaryObject->getStoreId()];
$oldData = $readAdapter->fetchRow($select, $bind);
$data = new \Magento\Framework\Object();
$data->setReviewsCount($reviewsCount)->setEntityPkValue($object->getEntityPkValue())->setEntityType($object->getEntityId())->setRatingSummary($ratingSummary > 0 ? $ratingSummary : 0)->setStoreId($ratingSummaryObject->getStoreId());
$this->writeReviewSummary($oldData, $data);
}