获得产品或产品ID在Magento [英] Getting Product or ProductID in magento

查看:75
本文介绍了获得产品或产品ID在Magento的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

写新的一组一个.phtml&安培时;块:点击 什么是知道的,如果该块目前是一个产品页面上的推荐方法?点击 如果它是一个产品页面上,然后我怎么到当前正在查看产品的数据?

when writing a new set of .phtml & block:
What is the recommanded way to know if the block is currently on a product page ?
If it is on a product page then how do I get to the data of the currently being viewed product ?

谢谢, 没事

推荐答案

1的问题)如何知道你的产品视图页面上.

1st question) How to know that you're on product view page.

您的问题是不明确的,因为你不说,这样的功能的目的.我将您的问题解释为我怎么能知道它是嵌入在产品视图"页面中而不是其他页面中?".

Your problem is not clear because you don't say the purpose of such functionality. I interpret your question as "How can my blockknow that it's embedded in Product View page and not in some other page?".

最常见的方式是获取页的布局和搜索它设计成视图产品标准块.因此,在你块,你可以做以下要求:

The most common way is to get layout of page and search it for standard block designed to view product. So in your block you can make following request:

$block = $this->getLayout()
    ->getBlock('product.info');

if ($block) {
    // Block exists - you're viewing product page
}


另一种方法是,以检查用于形成当前页面布局布局把手:

The other method is to check layout handles used to form current page layout:

$handles = $this->->getLayout()
    ->getUpdate()
    ->getHandles();
if (in_array('catalog_product_view', $handles)) {
    // Handle exists - you're viewing product page
}

然而,它的更具体的方法中,观察产品页面,而不是使用产品视图块类似设计的网页只有当返回肯定结果.对于,例如产品评测页面将显示你有轻微的差别同样的产品页面,但它使用自己的(不是catalog_product_view")处理它.至于你说的也不关心你的目的,我不建议你第一个或第二个方法可供选择.

However it's more concrete method, it returns positive result only when viewing product page and not pages with similar designs using product view blocks. For, example Product Review page will show you same product page with minor differences but it uses its own (not 'catalog_product_view') handle for it. As far as you said nothing about your purpose I cannot recommend you to choose first or second method.

注意:你的架构可以是错误的,因为通常点击 a)您的代码块不需要知道其嵌入位置,因此不需要检查当前查看的页面
b)或您的块仅用于产品视图页面.但在这种情况下,它的布局XML任务使你的格挡只有在需要的页面和块.

Notice: you architecture can be wrong, because usually
a) your block either doesn't need to know where it's embedded, so it doesn't need not check currently viewed page
b) or your block is used only for product view page. But in this case it's a layout xml task to put your block only in required pages and blocks.

第二个问题)如何获得当前产品的产品视图页面上.

2nd question) How to get current product on product view page.

使用以下代码:

  $product = Mage::registry('current_product');

,你会得到该产品目前观看.

And you'll get the product currently viewed.

这篇关于获得产品或产品ID在Magento的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆