本文整理汇总了PHP中Magento\Catalog\Helper\Product::canShow方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::canShow方法的具体用法?PHP Product::canShow怎么用?PHP Product::canShow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Helper\Product
的用法示例。
在下文中一共展示了Product::canShow方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLastViewedUrl
/**
* Retrieve Visitor/Customer Last Viewed URL
*
* @return string
*/
public function getLastViewedUrl()
{
$productId = $this->_catalogSession->getLastViewedProductId();
if ($productId) {
try {
$product = $this->productRepository->getById($productId);
} catch (NoSuchEntityException $e) {
return '';
}
/* @var $product \Magento\Catalog\Model\Product */
if ($this->_catalogProduct->canShow($product, 'catalog')) {
return $product->getProductUrl();
}
}
$categoryId = $this->_catalogSession->getLastViewedCategoryId();
if ($categoryId) {
try {
$category = $this->categoryRepository->get($categoryId);
} catch (NoSuchEntityException $e) {
return '';
}
/* @var $category \Magento\Catalog\Model\Category */
if (!$this->_catalogCategory->canShow($category)) {
return '';
}
return $category->getCategoryUrl();
}
return '';
}
示例2: testCanShow
/**
* @magentoDataFixture Magento/Catalog/_files/products.php
*/
public function testCanShow()
{
// non-visible or disabled
/** @var $product \Magento\Catalog\Model\Product */
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
$this->assertFalse($this->_helper->canShow($product));
// enabled and visible
$product->setId(1);
$product->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
$product->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH);
$this->assertTrue($this->_helper->canShow($product));
$this->assertTrue($this->_helper->canShow(1));
}
示例3: getLastViewedUrl
/**
* Retrieve Visitor/Customer Last Viewed URL
*
* @return string
*/
public function getLastViewedUrl()
{
$productId = $this->_catalogSession->getLastViewedProductId();
if ($productId) {
$product = $this->_productFactory->create()->load($productId);
/* @var $product \Magento\Catalog\Model\Product */
if ($this->_catalogProduct->canShow($product, 'catalog')) {
return $product->getProductUrl();
}
}
$categoryId = $this->_catalogSession->getLastViewedCategoryId();
if ($categoryId) {
$category = $this->_categoryFactory->create()->load($categoryId);
/* @var $category \Magento\Catalog\Model\Category */
if (!$this->_catalogCategory->canShow($category)) {
return '';
}
return $category->getCategoryUrl();
}
return '';
}