Magento删除添加到购物车与视图.php


magento remove add to cart with view.phtml

我按照[这些说明][1]删除了"add to cart"。我试图删除添加到购物车按钮的属性为"instore_only"的项目,当响应是肯定的,我想要它回应一个静态块,我已经为它。当我做第一部分时,按钮永远不会消失。下面是我的代码:

//Check if the "Available in store only" variable is set to 'Yes':  
        if(($_product->getAttributeText('instore_only')) == "Yes"){
//If set to Yes, tell PHP what to output:
        echo $this->getLayout()->createBlock('cms/block')->setBlockId('instore_only')->toHtml();
}
//If set to No, then show the 'add to cart box' as normal.
        else {
?>
        <?php if (!$this->hasOptions()):?>
            <div class="add-to-box">
                <?php if($_product->isSaleable()): ?>
                    <?php echo $this->getChildHtml('addtocart') ?>
                    <?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
                        <span class="or"><?php echo $this->__('OR') ?></span>
                    <?php endif; ?>
                <?php endif; ?>
                <?php echo $this->getChildHtml('addto') ?>
            </div>
            <?php echo $this->getChildHtml('extra_buttons') ?>
        <?php elseif (!$_product->isSaleable()): ?>
            <div class="add-to-box">
                <?php echo $this->getChildHtml('addto') ?>
            </div>
        <?php endif; ?>
        <?php if ($_product->getShortDescription()):?>
            <div class="short-description">
                <h2><?php echo $this->__('Quick Overview') ?></h2>
                <div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
            </div>
        <?php endif;?>
        <?php echo $this->getChildHtml('other');?>
        <?php if ($_product->isSaleable() && $this->hasOptions()):?>
            <?php echo $this->getChildChildHtml('container1', '', true, true) ?>
        <?php endif;?>
        <?php
        }
        ?>

我已经验证了正确视图的位置。在我的前端使用模板路径提示。

所以,简而言之,这段代码看起来正确吗?如果不正确,我可以在view. php中调用cms块吗?该网站支持小型零售商店,所以有些商品只能在商店里买到,不能在网上购买。

我大约1周的magento和代码。我试图做几个星期的基本网站与一个基本的模板。

我假设,从你的问题,静态块永远不会显示,添加到购物车按钮总是显示。我还将假设您将正在测试的产品的"store Only"属性设置为"Yes",您已经为当前商店创建并启用了标识符为instore_only的CMS静态块,并且您已经清除或禁用了Magento缓存。

检查产品属性配置

$_product->getAttributeText('instore_only')将返回类型为DropdownMultiple select的属性的文本值。

是/否目录输入类型

如果您的产品属性是用Yes/No目录输入类型配置的,那么getAttributeText()将不会为它返回一个值——因此它在您的测试中永远不会等于"Yes",并且您的静态块将永远不会显示。

应该直接请求属性值。Yes/No输入类型直接与布尔运算兼容,因此您可以简单地在if语句中测试值。像这样:

if ($_product->getInstoreOnly()) {
  //output your static block
} else {
  //output the add to cart form
}

文本目录输入类型

如果您的属性配置为TextText area目录输入类型,那么您将进行如下比较:

if ($_product->getInstoreOnly() == "Yes") {
  //output your static block
} else {
  //ouput the add to cart form
}

在这种情况下,您必须在产品编辑器的框中手动输入Yes才能使此工作。

下拉目录输入类型

如果您的属性被配置为DropdownMultiple select选项,并且您已经手动添加了一个名为Yes的选项,那么上面的代码应该是正确的。

产品列表中使用的应该是Yes

您还应该检查目录属性Used in product listing选项设置为Yes,以便通过Magento将属性值加载到产品页面上。

检查您的属性设置以确保它在前端可用。此外,确保"Used in Listing"设置为yes,以便将其添加到索引表中。这样可以更快地打电话。我怀疑这将允许您当前的代码工作…但不测试就不确定。

一种不太优雅的方法是从资源模型调用它。我不建议这样做,因为你会绕过索引表…

试题:

 $_product->getResource()->getAttribute('instore_only')->getFrontend()->getValue($_product);

从视图中隐藏数量框和"添加到购物车"按钮。您可以注释位于template/catalog/product/view/addtocart.phtml

addtocart.phtml中的所有代码。

希望能有所帮助