本文整理汇总了PHP中Magento\Catalog\Model\Product::getData方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getData方法的具体用法?PHP Product::getData怎么用?PHP Product::getData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Product
的用法示例。
在下文中一共展示了Product::getData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetUsedProductAttributeIds
public function testSetUsedProductAttributeIds()
{
$testConfigurable = $this->_getAttributeByCode('test_configurable');
$this->_model->setUsedProductAttributeIds([$testConfigurable->getId()], $this->_product);
$attributes = $this->_product->getData('_cache_instance_configurable_attributes');
$this->assertArrayHasKey(0, $attributes);
$this->assertInstanceOf('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\Attribute', $attributes[0]);
$this->assertSame($testConfigurable, $attributes[0]->getProductAttribute());
}
示例2: getValueByProductInstance
/**
* @param \Magento\Catalog\Model\Product $product
* @return mixed
*/
public function getValueByProductInstance(\Magento\Catalog\Model\Product $product)
{
$status = $product->getData('amazon_status');
$variationChildStatuses = $product->getData('variation_child_statuses');
if ($product->getData('is_variation_parent') && !empty($variationChildStatuses)) {
$status = json_decode($variationChildStatuses, true);
}
return $status;
}
示例3: getValueByProductInstance
public function getValueByProductInstance(\Magento\Catalog\Model\Product $product)
{
$minPrice = $product->getData('min_online_price');
$maxPrice = $product->getData('max_online_price');
if (!empty($minPrice) && !empty($maxPrice) && $minPrice != $maxPrice) {
return array($product->getData('min_online_price'), $product->getData('max_online_price'));
}
return $product->getData('min_online_price');
}
示例4: beforeProcess
public function beforeProcess()
{
$product = $this->getEvent()->getProduct();
if (!$product instanceof \Magento\Catalog\Model\Product) {
throw new \Ess\M2ePro\Model\Exception('Product event doesn\'t have correct Product instance.');
}
$this->product = $product;
$this->productId = (int) $this->product->getId();
$this->storeId = (int) $this->product->getData('store_id');
}
示例5: generateForAutogenerated
/**
* @param UrlRewrite $url
* @param int $storeId
* @param Category|null $category
* @return array
*/
protected function generateForAutogenerated($url, $storeId, $category)
{
if (!$this->product->getData('save_rewrites_history')) {
return [];
}
$targetPath = $this->productUrlPathGenerator->getUrlPathWithSuffix($this->product, $storeId, $category);
if ($url->getRequestPath() === $targetPath) {
return [];
}
return [$this->urlRewriteFactory->create()->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)->setEntityId($this->product->getId())->setRequestPath($url->getRequestPath())->setTargetPath($targetPath)->setRedirectType(OptionProvider::PERMANENT)->setStoreId($storeId)->setDescription($url->getDescription())->setIsAutogenerated(0)->setMetadata($url->getMetadata())];
}
示例6: getValueByProductInstance
/**
* @param \Magento\Catalog\Model\Product $product
* @return int
*/
public function getValueByProductInstance(\Magento\Catalog\Model\Product $product)
{
$generalId = $product->getData('general_id');
if (!empty($generalId)) {
return \Ess\M2ePro\Model\Amazon\Listing\Product::GENERAL_ID_STATE_SET;
}
if ($product->getData('is_general_id_owner') == 1) {
return \Ess\M2ePro\Model\Amazon\Listing\Product::GENERAL_ID_STATE_READY_FOR_NEW_ASIN;
}
$searchStatusActionRequired = \Ess\M2ePro\Model\Amazon\Listing\Product::SEARCH_SETTINGS_STATUS_ACTION_REQUIRED;
$searchStatusNotFound = \Ess\M2ePro\Model\Amazon\Listing\Product::SEARCH_SETTINGS_STATUS_NOT_FOUND;
if ($product->getData('search_settings_status') == $searchStatusActionRequired || $product->getData('search_settings_status') == $searchStatusNotFound) {
return \Ess\M2ePro\Model\Amazon\Listing\Product::GENERAL_ID_STATE_ACTION_REQUIRED;
}
return \Ess\M2ePro\Model\Amazon\Listing\Product::GENERAL_ID_STATE_NOT_SET;
}
示例7: removeTierPrice
/**
* @param \Magento\Catalog\Model\Product $product
* @param int|string $customerGroupId
* @param int $qty
* @param int $websiteId
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\CouldNotSaveException
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function removeTierPrice(\Magento\Catalog\Model\Product $product, $customerGroupId, $qty, $websiteId)
{
$prices = $product->getData('tier_price');
// verify if price exist
if ($prices === null) {
throw new NoSuchEntityException(__('This product doesn\'t have tier price'));
}
$tierPricesQty = count($prices);
foreach ($prices as $key => $tierPrice) {
if ($customerGroupId == 'all' && $tierPrice['price_qty'] == $qty && $tierPrice['all_groups'] == 1 && intval($tierPrice['website_id']) === intval($websiteId)) {
unset($prices[$key]);
} elseif ($tierPrice['price_qty'] == $qty && $tierPrice['cust_group'] == $customerGroupId && intval($tierPrice['website_id']) === intval($websiteId)) {
unset($prices[$key]);
}
}
if ($tierPricesQty == count($prices)) {
throw new NoSuchEntityException(__('Product hasn\'t group price with such data: customerGroupId = \'%1\'' . ', website = %2, qty = %3', [$customerGroupId, $websiteId, $qty]));
}
$product->setData('tier_price', $prices);
try {
$this->productRepository->save($product);
} catch (\Exception $exception) {
throw new CouldNotSaveException(__('Invalid data provided for tier_price'));
}
}
示例8: removeTierPrice
/**
* @param \Magento\Catalog\Model\Product $product
* @param int|string $customerGroupId
* @param int $qty
* @param int $websiteId
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\CouldNotSaveException
* @return void
*/
public function removeTierPrice(\Magento\Catalog\Model\Product $product, $customerGroupId, $qty, $websiteId)
{
$prices = $product->getData('tier_price');
// verify if price exist
if (is_null($prices)) {
throw new NoSuchEntityException("This product doesn't have tier price");
}
$tierPricesQty = count($prices);
foreach ($prices as $key => $tierPrice) {
if ($customerGroupId == 'all' && $tierPrice['price_qty'] == $qty && $tierPrice['all_groups'] == 1 && intval($tierPrice['website_id']) === intval($websiteId)) {
unset($prices[$key]);
} elseif ($tierPrice['price_qty'] == $qty && $tierPrice['cust_group'] == $customerGroupId && intval($tierPrice['website_id']) === intval($websiteId)) {
unset($prices[$key]);
}
}
if ($tierPricesQty == count($prices)) {
throw new NoSuchEntityException("Product hasn't group price with such data: customerGroupId = '{$customerGroupId}'," . "website = {$websiteId}, qty = {$qty}");
}
$product->setData('tier_price', $prices);
try {
$product->save();
} catch (\Exception $exception) {
throw new CouldNotSaveException("Invalid data provided for tier_price");
}
}
示例9: copy
/**
* Create product duplicate
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Catalog\Model\Product
*/
public function copy(\Magento\Catalog\Model\Product $product)
{
$product->getWebsiteIds();
$product->getCategoryIds();
/** @var \Magento\Catalog\Model\Product $duplicate */
$duplicate = $this->productFactory->create();
$duplicate->setData($product->getData());
$duplicate->setOptions([]);
$duplicate->setIsDuplicate(true);
$duplicate->setOriginalId($product->getEntityId());
$duplicate->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
$duplicate->setCreatedAt(null);
$duplicate->setUpdatedAt(null);
$duplicate->setId(null);
$duplicate->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
$this->copyConstructor->build($product, $duplicate);
$isDuplicateSaved = false;
do {
$urlKey = $duplicate->getUrlKey();
$urlKey = preg_match('/(.*)-(\\d+)$/', $urlKey, $matches) ? $matches[1] . '-' . ($matches[2] + 1) : $urlKey . '-1';
$duplicate->setUrlKey($urlKey);
try {
$duplicate->save();
$isDuplicateSaved = true;
} catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
}
} while (!$isDuplicateSaved);
$this->getOptionRepository()->duplicate($product, $duplicate);
$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
$product->getResource()->duplicate($product->getData($metadata->getLinkField()), $duplicate->getData($metadata->getLinkField()));
return $duplicate;
}
示例10: copy
/**
* Create product duplicate
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Catalog\Model\Product
*/
public function copy(\Magento\Catalog\Model\Product $product)
{
$product->getWebsiteIds();
$product->getCategoryIds();
$duplicate = $this->productFactory->create();
$duplicate->setData($product->getData());
$duplicate->setIsDuplicate(true);
$duplicate->setOriginalId($product->getId());
$duplicate->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
$duplicate->setCreatedAt(null);
$duplicate->setUpdatedAt(null);
$duplicate->setId(null);
$duplicate->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
$this->copyConstructor->build($product, $duplicate);
$isDuplicateSaved = false;
do {
$urlKey = $duplicate->getUrlKey();
$urlKey = preg_match('/(.*)-(\\d+)$/', $urlKey, $matches) ? $matches[1] . '-' . ($matches[2] + 1) : $urlKey . '-1';
$duplicate->setUrlKey($urlKey);
try {
$duplicate->save();
$isDuplicateSaved = true;
} catch (DuplicateEntryException $e) {
}
} while (!$isDuplicateSaved);
$product->getOptionInstance()->duplicate($product->getId(), $duplicate->getId());
$product->getResource()->duplicate($product->getId(), $duplicate->getId());
return $duplicate;
}
示例11: getLabel
/**
* Return product image label
*
* @return string
*/
public function getLabel()
{
$label = $this->_product->getData($this->getType() . self::VAR_NAME_SEPARATOR . 'label');
if (empty($label)) {
$label = $this->_product->getName();
}
return $label;
}
示例12: getUrlPath
/**
* Retrieve Product Url path (with category if exists)
*
* @param \Magento\Catalog\Model\Product $product
* @param \Magento\Catalog\Model\Category $category
*
* @return string
*/
public function getUrlPath($product, $category = null)
{
$path = $product->getData('url_path');
if ($path === null) {
$path = $this->generateUrlKey($product);
}
return $category === null ? $path : $this->categoryUrlPathGenerator->getUrlPath($category) . '/' . $path;
}
示例13: getLabel
/**
* Return image label
*
* @return string
*/
public function getLabel()
{
$label = $this->_product->getData($this->getType() . '_' . 'label');
if (empty($label)) {
$label = $this->_product->getName();
}
return $label;
}
示例14: getUrlPath
/**
* Retrieve Product Url path (with category if exists)
*
* @param \Magento\Catalog\Model\Product $product
* @param \Magento\Catalog\Model\Category $category
*
* @return string
*/
public function getUrlPath($product, $category = null)
{
$path = $product->getData('url_path');
if ($path === null) {
$path = $product->getUrlKey() === false ? $this->prepareProductDefaultUrlKey($product) : $this->prepareProductUrlKey($product);
}
return $category === null ? $path : $this->categoryUrlPathGenerator->getUrlPath($category) . '/' . $path;
}
示例15: getUrl
/**
* Returns url to product image
*
* @param \Magento\Catalog\Model\Product $product
*
* @return string|false
*/
public function getUrl($product)
{
$image = $product->getData($this->getAttribute()->getAttributeCode());
$url = false;
if (!empty($image)) {
$url = $this->_storeManager->getStore($product->getStore())->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . 'catalog/product/' . $image;
}
return $url;
}