IF(此产品位于任何可配置产品中)重定向(ThatConfigurableProduct)

发布于 2024-11-05 09:13:38 字数 2497 浏览 0 评论 0原文

这就是我正在尝试做的事情。我的所有简单产品最多都是 1 个可配置产品的一部分,因此不可能出现问题。

这是必要的,因为我希望我的简单产品(设计 X 的枕头,颜色 Y)显示在搜索、目录中,但我需要用户知道,一旦他们点击,该设计就会以不同的颜色存在(大概是因为他们喜欢设计 X,但不喜欢)不一定以颜色 Y 出售)。此外,我对颜色样本(扩展)的实现导致我的简单产品(属于可配置的一部分)在直接访问时表现得很有趣。

感谢您的任何帮助。

编辑:

这是我最终使用的代码。我不是一个很好的编码员,所以请确保在部署之前改进它...(~In app/design/frontend/blah/blah/template/catalog/product/view.media.phtml)

<?php
/* THIS BLOCK ADDED BY __ ON 5/5/2011 */

$thisProductId = $_product['entity_id'];

$thisProductParentId = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($thisProductId);

if (!$thisProductParentId)
{
?>
<div class="more-views">
    <h2><?php echo $this->__('More Views') ?></h2>
    <ul>
    <?php foreach ($this->getGalleryImages() as $_image): ?>
        <li>
            <a href="#" onclick="popWin('<?php echo $this->getGalleryUrl($_image) ?>', 'gallery', 'width=300,height=300,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(56); ?>" width="56" height="56" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
        </li>
    <?php endforeach; ?>
    </ul>
</div>
<?php 
}
else if ($thisProductParentId)
{
    $_product_temp = Mage::getModel('catalog/product')->load($thisProductParentId);

        if($_product_temp->getStatus()==1)
        {       
            $_categories = $_product_temp->getCategoryIds();
            $_category = Mage::getModel('catalog/category')->load($_categories[0]);
            $url = $this->getUrl($_category->getUrlPath()).$_product_temp->getUrlPath();
            echo '<h1><a style="color:red;" href="'.$url.'">Click here to view this pillow design in different colors and styles.</a></h1>';
            // redirect disabled because it won't preload the new color on the configurable image page anyway. (haven't attempted)
            /* echo '<script type="text/javascript">
                <!--
                    window.location = "'.$url.'"
                //-->
            </script>'; */
        }
}
// -- end --
?>

更多图像的覆盖图库位是特定于项目的自定义,因此请记住这一点。

That's pretty much what I'm trying to do. All of my simple products are part of, at most, 1 configurable product, so there's no possibility for issues there.

This is necessary because I want my simple products (pillow in design X, color Y) to show in search, catalog but I need the user to know that the design exists in different colors once they click (presumably because they like design X but aren't necessarily sold on color Y). Further, my implementation of Color Swatches (extension) is causing my simple products (that are part of configurables) to behave funnily when accessed directly.

Thanks for any help.

Edit:

Here's the code I ended up using. I'm not a very good coder so make sure to improve it before deploying... (~In app/design/frontend/blah/blah/template/catalog/product/view.media.phtml)

<?php
/* THIS BLOCK ADDED BY __ ON 5/5/2011 */

$thisProductId = $_product['entity_id'];

$thisProductParentId = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($thisProductId);

if (!$thisProductParentId)
{
?>
<div class="more-views">
    <h2><?php echo $this->__('More Views') ?></h2>
    <ul>
    <?php foreach ($this->getGalleryImages() as $_image): ?>
        <li>
            <a href="#" onclick="popWin('<?php echo $this->getGalleryUrl($_image) ?>', 'gallery', 'width=300,height=300,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(56); ?>" width="56" height="56" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
        </li>
    <?php endforeach; ?>
    </ul>
</div>
<?php 
}
else if ($thisProductParentId)
{
    $_product_temp = Mage::getModel('catalog/product')->load($thisProductParentId);

        if($_product_temp->getStatus()==1)
        {       
            $_categories = $_product_temp->getCategoryIds();
            $_category = Mage::getModel('catalog/category')->load($_categories[0]);
            $url = $this->getUrl($_category->getUrlPath()).$_product_temp->getUrlPath();
            echo '<h1><a style="color:red;" href="'.$url.'">Click here to view this pillow design in different colors and styles.</a></h1>';
            // redirect disabled because it won't preload the new color on the configurable image page anyway. (haven't attempted)
            /* echo '<script type="text/javascript">
                <!--
                    window.location = "'.$url.'"
                //-->
            </script>'; */
        }
}
// -- end --
?>

The overwriting of the More Images gallery bit is a project-specific customization, so keep that in mind.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事还在继续 2024-11-12 09:13:38

我写了一堆代码来尝试做到这一点,却忘记了这已经是一个简单的用例,Magento 已经为您编写了它:

Mage::getResourceSingleton('catalog/product_type_configurable')
        ->getParentIdsByChild($childId);

该代码片段应该为您提供子级的所有父级产品。如果有,则重定向到它。否则,按请求呈现页面。

I went and wrote a bunch of code to try to do this, and forgot that this is already a simple use case, and Magento has it written for you:

Mage::getResourceSingleton('catalog/product_type_configurable')
        ->getParentIdsByChild($childId);

That snippet should give you all parent products for the child. If there is one, redirect to it. Otherwise, render the page as requested.

南街九尾狐 2024-11-12 09:13:38

这里有两个选项:

  1. 添加重写规则表单目录> url 重写管理
  2. 程序是一个扩展,可对产品数据库进行必要的检查并进行重定向

you have two options here :

  1. add rewrite rules form catalog > url rewrite management
  2. program an extension that makes the necessary check against product database and makes the redirect
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文