本文整理汇总了PHP中Magento\Catalog\Model\Product::getProductUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getProductUrl方法的具体用法?PHP Product::getProductUrl怎么用?PHP Product::getProductUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Product
的用法示例。
在下文中一共展示了Product::getProductUrl方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertAttribute
/**
* Set current attribute to entry (for specified product)
*
* @param \Magento\Catalog\Model\Product $product
* @param \Magento\Framework\Gdata\Gshopping\Entry $entry
* @return \Magento\Framework\Gdata\Gshopping\Entry
*/
public function convertAttribute($product, $entry)
{
$url = $product->getProductUrl(false);
if ($url) {
$isStoreInUrl = $this->_scopeConfig->isSetFlag(\Magento\Store\Model\Store::XML_PATH_STORE_IN_URL, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
if (!$isStoreInUrl) {
$urlInfo = parse_url($url);
$store = $product->getStore()->getCode();
if (isset($urlInfo['query']) && $urlInfo['query'] != '') {
$url .= '&___store=' . $store;
} else {
$url .= '?___store=' . $store;
}
}
$links = $entry->getLink();
if (!is_array($links)) {
$links = [];
}
$link = $entry->getService()->newLink();
$link->setHref($url);
$link->setRel('alternate');
$link->setType('text/html');
if ($product->getName()) {
$link->setTitle($product->getName());
}
$links[0] = $link;
$entry->setLink($links);
}
return $entry;
}
示例2: testGetProductUrl
/**
* @covers \Magento\Catalog\Model\Product::getProductUrl
* @covers \Magento\Catalog\Model\Product::getUrlInStore
*/
public function testGetProductUrl()
{
$this->assertStringEndsWith('catalog/product/view/', $this->_model->getProductUrl());
$this->assertStringEndsWith('catalog/product/view/', $this->_model->getUrlInStore());
$this->_model->setId(999);
$url = $this->_model->getProductUrl();
$this->assertContains('catalog/product/view', $url);
$this->assertContains('id/999', $url);
$storeUrl = $this->_model->getUrlInStore();
$this->assertEquals($storeUrl, $url);
}
示例3: getProductUrl
/**
* Retrieve product view page url
*
* @param int|ModelProduct $product
* @return string|false
*/
public function getProductUrl($product)
{
if ($product instanceof ModelProduct) {
return $product->getProductUrl();
} elseif (is_numeric($product)) {
return $this->productRepository->getById($product)->getProductUrl();
}
return false;
}
示例4: getProductUrl
/**
* {@inheritdoc}
*/
public function getProductUrl($useSid = null)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'getProductUrl');
if (!$pluginInfo) {
return parent::getProductUrl($useSid);
} else {
return $this->___callPlugins('getProductUrl', func_get_args(), $pluginInfo);
}
}
示例5: getObject
public function getObject(Product $product)
{
$type = $product->getTypeId();
$this->logger->start('CREATE RECORD ' . $product->getId() . ' ' . $this->logger->getStoreName($product->getStoreId()));
$defaultData = [];
$transport = new DataObject($defaultData);
$this->eventManager->dispatch('algolia_product_index_before', ['product' => $product, 'custom_data' => $transport]);
$defaultData = $transport->getData();
$visibility = (int) $product->getVisibility();
$visibleInCatalog = $this->visibility->getVisibleInCatalogIds();
$visibleInSearch = $this->visibility->getVisibleInSearchIds();
$customData = ['objectID' => $product->getId(), 'name' => $product->getName(), 'url' => $product->getProductUrl(false), 'visibility_search' => (int) in_array($visibility, $visibleInSearch), 'visibility_catalog' => (int) in_array($visibility, $visibleInCatalog)];
$additionalAttributes = $this->getAdditionalAttributes($product->getStoreId());
$groups = null;
if ($this->isAttributeEnabled($additionalAttributes, 'description')) {
$customData['description'] = $product->getDescription();
}
$categories = [];
$categories_with_path = [];
$_categoryIds = $product->getCategoryIds();
if (is_array($_categoryIds) && count($_categoryIds) > 0) {
$categoryCollection = $this->getAllCategories($_categoryIds);
$rootCat = $this->storeManager->getStore($product->getStoreId())->getRootCategoryId();
foreach ($categoryCollection as $category) {
// Check and skip all categories that is not
// in the path of the current store.
$path = $category->getPath();
$path_parts = explode('/', $path);
if (isset($path_parts[1]) && $path_parts[1] != $rootCat) {
continue;
}
$categoryName = $category->getName();
if ($categoryName) {
$categories[] = $categoryName;
}
$category->getUrlInstance()->setStore($product->getStoreId());
$path = [];
foreach ($category->getPathIds() as $treeCategoryId) {
$name = $this->getCategoryName($treeCategoryId, $product->getStoreId());
if ($name) {
$path[] = $name;
}
}
$categories_with_path[] = $path;
}
}
foreach ($categories_with_path as $result) {
for ($i = count($result) - 1; $i > 0; $i--) {
$categories_with_path[] = array_slice($result, 0, $i);
}
}
$categories_with_path = array_intersect_key($categories_with_path, array_unique(array_map('serialize', $categories_with_path)));
$categories_hierarchical = [];
$level_name = 'level';
foreach ($categories_with_path as $category) {
for ($i = 0; $i < count($category); $i++) {
if (isset($categories_hierarchical[$level_name . $i]) === false) {
$categories_hierarchical[$level_name . $i] = [];
}
$categories_hierarchical[$level_name . $i][] = implode(' /// ', array_slice($category, 0, $i + 1));
}
}
foreach ($categories_hierarchical as &$level) {
$level = array_values(array_unique($level));
}
foreach ($categories_with_path as &$category) {
$category = implode(' /// ', $category);
}
$customData['categories'] = $categories_hierarchical;
$customData['categories_without_path'] = $categories;
/** @var Image $imageHelper */
$imageHelper = $this->objectManager->create('Algolia\\AlgoliaSearch\\Helper\\Image');
if (false === isset($defaultData['thumbnail_url'])) {
$thumb = $imageHelper->init($product, 'thumbnail')->resize(75, 75);
$customData['thumbnail_url'] = $thumb->getUrl();
}
if (false === isset($defaultData['image_url'])) {
$image = $imageHelper->init($product, $this->config->getImageType())->resize($this->config->getImageWidth(), $this->config->getImageHeight());
$customData['image_url'] = $image->getUrl();
if ($this->isAttributeEnabled($additionalAttributes, 'media_gallery')) {
$product->load('media_gallery');
$customData['media_gallery'] = [];
$images = $product->getMediaGalleryImages();
if ($images) {
foreach ($images as $image) {
$customData['media_gallery'][] = str_replace(['https://', 'http://'], '//', $image->getUrl());
}
}
}
}
$sub_products = [];
$ids = null;
if ($type == 'configurable' || $type == 'grouped' || $type == 'bundle') {
if ($type == 'bundle') {
$ids = [];
$selection = $product->getTypeInstance(true)->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product);
foreach ($selection as $option) {
$ids[] = $option->getProductId();
}
}
//.........这里部分代码省略.........
示例6: getProductUrl
/**
* Retrieve product view page url
*
* @param int|ModelProduct $product
* @return string|false
*/
public function getProductUrl($product)
{
if ($product instanceof ModelProduct) {
return $product->getProductUrl();
} elseif (is_numeric($product)) {
return $this->_productFactory->create()->load($product)->getProductUrl();
}
return false;
}