本文整理汇总了PHP中Magento\Framework\Model\AbstractModel::getPrice方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractModel::getPrice方法的具体用法?PHP AbstractModel::getPrice怎么用?PHP AbstractModel::getPrice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Model\AbstractModel
的用法示例。
在下文中一共展示了AbstractModel::getPrice方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Validate Product Rule Condition
*
* @param \Magento\Framework\Model\AbstractModel $model
* @return bool
*/
public function validate(\Magento\Framework\Model\AbstractModel $model)
{
//@todo reimplement this method when is fixed MAGETWO-5713
/** @var \Magento\Catalog\Model\Product $product */
$product = $model->getProduct();
if (!$product instanceof \Magento\Catalog\Model\Product) {
$product = $this->productRepository->getById($model->getProductId());
}
$product->setQuoteItemQty($model->getQty())->setQuoteItemPrice($model->getPrice())->setQuoteItemRowTotal($model->getBaseRowTotal());
return parent::validate($product);
}
示例2: _saveValuePrices
/**
* Save option value price data
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return void
*/
protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $object)
{
$priceTable = $this->getTable('catalog_product_option_type_price');
$price = (double) sprintf('%F', $object->getPrice());
$priceType = $object->getPriceType();
if (!$object->getData('scope', 'price')) {
//save for store_id = 0
$select = $this->_getReadAdapter()->select()->from($priceTable, 'option_type_id')->where('option_type_id = ?', (int) $object->getId())->where('store_id = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID);
$optionTypeId = $this->_getReadAdapter()->fetchOne($select);
if ($optionTypeId) {
if ($object->getStoreId() == '0') {
$bind = array('price' => $price, 'price_type' => $priceType);
$where = array('option_type_id = ?' => $optionTypeId, 'store_id = ?' => \Magento\Store\Model\Store::DEFAULT_STORE_ID);
$this->_getWriteAdapter()->update($priceTable, $bind, $where);
}
} else {
$bind = array('option_type_id' => (int) $object->getId(), 'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID, 'price' => $price, 'price_type' => $priceType);
$this->_getWriteAdapter()->insert($priceTable, $bind);
}
}
$scope = (int) $this->_config->getValue(\Magento\Store\Model\Store::XML_PATH_PRICE_SCOPE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
if ($object->getStoreId() != '0' && $scope == \Magento\Store\Model\Store::PRICE_SCOPE_WEBSITE) {
$baseCurrency = $this->_config->getValue(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE, 'default');
$storeIds = $this->_storeManager->getStore($object->getStoreId())->getWebsite()->getStoreIds();
if (is_array($storeIds)) {
foreach ($storeIds as $storeId) {
if ($priceType == 'fixed') {
$storeCurrency = $this->_storeManager->getStore($storeId)->getBaseCurrencyCode();
/** @var $currencyModel \Magento\Directory\Model\Currency */
$currencyModel = $this->_currencyFactory->create();
$currencyModel->load($baseCurrency);
$rate = $currencyModel->getRate($storeCurrency);
if (!$rate) {
$rate = 1;
}
$newPrice = $price * $rate;
} else {
$newPrice = $price;
}
$select = $this->_getReadAdapter()->select()->from($priceTable, 'option_type_id')->where('option_type_id = ?', (int) $object->getId())->where('store_id = ?', (int) $storeId);
$optionTypeId = $this->_getReadAdapter()->fetchOne($select);
if ($optionTypeId) {
$bind = array('price' => $newPrice, 'price_type' => $priceType);
$where = array('option_type_id = ?' => (int) $optionTypeId, 'store_id = ?' => (int) $storeId);
$this->_getWriteAdapter()->update($priceTable, $bind, $where);
} else {
$bind = array('option_type_id' => (int) $object->getId(), 'store_id' => (int) $storeId, 'price' => $newPrice, 'price_type' => $priceType);
$this->_getWriteAdapter()->insert($priceTable, $bind);
}
}
}
} else {
if ($scope == \Magento\Store\Model\Store::PRICE_SCOPE_WEBSITE && $object->getData('scope', 'price')) {
$where = array('option_type_id = ?' => (int) $object->getId(), 'store_id = ?' => (int) $object->getStoreId());
$this->_getWriteAdapter()->delete($priceTable, $where);
}
}
}
示例3: _saveValuePrices
/**
* Save value prices
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $object)
{
$priceTable = $this->getTable('catalog_product_option_price');
$connection = $this->getConnection();
/*
* Better to check param 'price' and 'price_type' for saving.
* If there is not price skip saving price
*/
if ($object->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_FIELD || $object->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_AREA || $object->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_FILE || $object->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DATE || $object->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DATE_TIME || $object->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_TIME) {
//save for store_id = 0
if (!$object->getData('scope', 'price')) {
$statement = $connection->select()->from($priceTable, 'option_id')->where('option_id = ?', $object->getId())->where('store_id = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID);
$optionId = $connection->fetchOne($statement);
if ($optionId) {
if ($object->getStoreId() == '0') {
$data = $this->_prepareDataForTable(new \Magento\Framework\DataObject(['price' => $object->getPrice(), 'price_type' => $object->getPriceType()]), $priceTable);
$connection->update($priceTable, $data, ['option_id = ?' => $object->getId(), 'store_id = ?' => \Magento\Store\Model\Store::DEFAULT_STORE_ID]);
}
} else {
$data = $this->_prepareDataForTable(new \Magento\Framework\DataObject(['option_id' => $object->getId(), 'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID, 'price' => $object->getPrice(), 'price_type' => $object->getPriceType()]), $priceTable);
$connection->insert($priceTable, $data);
}
}
$scope = (int) $this->_config->getValue(\Magento\Store\Model\Store::XML_PATH_PRICE_SCOPE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
if ($object->getStoreId() != '0' && $scope == \Magento\Store\Model\Store::PRICE_SCOPE_WEBSITE) {
$baseCurrency = $this->_config->getValue(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE, 'default');
$storeIds = $this->_storeManager->getStore($object->getStoreId())->getWebsite()->getStoreIds();
if (is_array($storeIds)) {
foreach ($storeIds as $storeId) {
if ($object->getPriceType() == 'fixed') {
$storeCurrency = $this->_storeManager->getStore($storeId)->getBaseCurrencyCode();
$rate = $this->_currencyFactory->create()->load($baseCurrency)->getRate($storeCurrency);
if (!$rate) {
$rate = 1;
}
$newPrice = $object->getPrice() * $rate;
} else {
$newPrice = $object->getPrice();
}
$statement = $connection->select()->from($priceTable)->where('option_id = ?', $object->getId())->where('store_id = ?', $storeId);
if ($connection->fetchOne($statement)) {
$data = $this->_prepareDataForTable(new \Magento\Framework\DataObject(['price' => $newPrice, 'price_type' => $object->getPriceType()]), $priceTable);
$connection->update($priceTable, $data, ['option_id = ?' => $object->getId(), 'store_id = ?' => $storeId]);
} else {
$data = $this->_prepareDataForTable(new \Magento\Framework\DataObject(['option_id' => $object->getId(), 'store_id' => $storeId, 'price' => $newPrice, 'price_type' => $object->getPriceType()]), $priceTable);
$connection->insert($priceTable, $data);
}
}
}
} elseif ($scope == \Magento\Store\Model\Store::PRICE_SCOPE_WEBSITE && $object->getData('scope', 'price')) {
$connection->delete($priceTable, ['option_id = ?' => $object->getId(), 'store_id = ?' => $object->getStoreId()]);
}
}
return $this;
}