/** * Checking that test data is saving to database * * @magentoDbIsolation enabled */ public function testIsModelSavingDataToDatabase() { $modelId = $this->saveTestData(); $newModel = $this->model->load($modelId); $testData = $this->getTestData(); $newModelData = []; foreach (array_keys($testData) as $key) { $newModelData[$key] = $newModel->getData($key); } $this->assertEquals($testData, $newModelData); }
/** * Load object data * * @param int|null $id * @param string $field * @return $this */ public function load($id, $field = null) { if ($id === null) { return $this->noRoutePage(); } return parent::load($id, $field); }
/** * @param int $modelId * @param null|string $field * @return \Ess\M2ePro\Model\ActiveRecord\AbstractModel * @throws \Ess\M2ePro\Model\Exception\Logic */ public function load($modelId, $field = null) { parent::load($modelId, $field); if (is_null($this->getId())) { throw new \Ess\M2ePro\Model\Exception\Logic('Instance does not exist.', array('id' => $modelId, 'field' => $field, 'model' => $this->_resourceName)); } return $this; }
public function load($modelId, $field = null) { parent::load($modelId, $field); $this->setId($modelId); // array_filter to remove empty items caused by non-magento modules requirements $this->setDepends(array_filter($this->packageInfo->getRequire($this->getCode()))); $this->setVersion($this->packageInfo->getVersion($this->getCode())); $this->setPackageName($this->packageInfo->getPackageName($this->getCode())); return $this; }
/** * Retrieve model object * @return \Magento\Framework\Model\AbstractModel */ protected function _getModel($load = true) { if (is_null($this->_model)) { $this->_model = $this->_objectManager->create($this->_modelClass); $id = (int) $this->getRequest()->getParam($this->_idKey); if ($id && $load) { $this->_model->load($id); } } return $this->_model; }
/** * 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(); } } }
/** * @param \Magento\Framework\Model\AbstractModel $model * @return bool */ public function validate(\Magento\Framework\Model\AbstractModel $model) { if (!$model->hasData($this->getAttribute())) { $model->load($model->getId()); } $attributeValue = $model->getData($this->getAttribute()); return $this->validateAttribute($attributeValue); }
/** * Loading store data * * @param mixed $key * @param string $field * @return $this */ public function load($key, $field = null) { if (!is_numeric($key) && $field === null) { $this->_getResource()->load($this, $key, 'code'); return $this; } return parent::load($key, $field); }
public function loadByMerchantTransactionId($mt_id) { return parent::load($mt_id, self::MERCHANT_TRANSACTION_ID); }
/** * Custom load * * @param int|string $id * @param string $field * @return $this */ public function load($id, $field = null) { if (!is_numeric($id) && is_null($field)) { $this->_getResource()->load($this, $id, 'code'); return $this; } return parent::load($id, $field); }
/** * load info multistore. * * @param mixed $id * @param string $field * * @return $this */ public function load($id, $field = null) { parent::load($id, $field); if ($this->getStoreViewId()) { $this->getStoreViewValue(); } return $this; }
/** * Aggregate * * @param \Magento\Framework\Model\AbstractModel $object * @return void */ public function aggregate($object) { if (!$object->getEntityPkValue() && $object->getId()) { $object->load($object->getReviewId()); } $ratingModel = $this->_ratingFactory->create(); $ratingSummaries = $ratingModel->getEntitySummary($object->getEntityPkValue(), false); foreach ($ratingSummaries as $ratingSummaryObject) { $this->aggregateReviewSummary($object, $ratingSummaryObject); } }
/** * @param int $modelId * @param null $field * @return $this */ public function load($modelId, $field = null) { return parent::load($modelId, $field); // TODO: Change the autogenerated stub }