首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >比较magento中未注册用户不允许的产品功能

比较magento中未注册用户不允许的产品功能
EN

Stack Overflow用户
提问于 2016-08-02 09:40:20
回答 1查看 161关注 0票数 0

当非注册用户单击add以进行比较时,它将显示注册警报(带有消息“注册是必需的”)。请帮帮忙。我用的是magento 1.9。任何人都知道答案,请分享。

这是我的list.phtml文件

代码语言:javascript
复制
<?php  
$_productCollection=$this->getLoadedProductCollection();   
$_helper = $this->helper('catalog/output');  

//var_dump(Mage::app()->getRequest()->getControllerName());  
//get list layout
$currentCat = Mage::getSingleton('catalog/layer')->getCurrentCategory()->getName();
//echo $currentCat;exit;
if ('Retail POS Software' == $currentCat && !$this->getRequest()->isAjax()) {
$displayMode =  'list';  
} else {
$displayMode =  $this->getMode();
}
//get list layout end
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<?php if (!$this->getRequest()->isAjax()): ?>
<div id="ajax-errors" style="display: none;">
<ul class="messages">
    <li class="error-msg">
        <ul>
            <li><span><?php echo $this->__('An error occurred, please try again later.'); ?></span></li>
        </ul>
    </li>
</ul>
 </div>
 <div id="loading" style="display: none; margin-bottom: 10px; text-align: center;">
<img class="v-middle" alt="" src="<?php echo $this->getSkinUrl('images/loader  
shopby.gif'); ?>"> <?php echo $this->__('Loading, please wait...'); ?>
</div>
<div id="catalog-listing">
<?php endif; ?>
<div class="category-products">

<div class="toolbar-top">
    <?php echo $this->getToolbarHtml() ?>
<?php // List mode 
    //change $this->getMode() to $displayMode
    ?>

<div class="yt-products-container clearfix">
    <?php if($displayMode!='grid'): ?>
    <?php $_iterator = 0; ?>
    <ol class="products-list" >
        <?php 
        $count_input_qty = 0;
        foreach ($_productCollection as $_product): 
        $count_input_qty++;
        $now = date("Y-m-d");
        $newsFrom= substr($_product->getData('news_from_date'),0,10);
        $newsTo=  substr($_product->getData('news_to_date'),0,10);
        $specialprice = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialPrice();
        $price = Mage::getModel('catalog/product')->load($_product->getId())->getPrice();
        $saleoff= round(($price - $specialprice)/$price*100) ;
        ?>
        <li class="item <?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
            <div class="item-inner">
                <div class="product-list-left col-lg-4 col-md-4 col-sm-5 col-xs-12">
                    <div class="product-image">
                        <a href="<?php echo $_product->getProductUrl() ?>" class="product-img" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
                            <img id="product-collection-image-<?php echo $_product->getId(); ?>"
                            src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,300); ?>"
                            alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
                        </a>

                        <?php if ( $now>=$newsFrom && $now<=$newsTo ){ ?>
                            <span class="new-product have-ico"><?php echo $this->__('New'); ?></span>
                        <?php }
                        if ( $specialprice ){ ?>
                            <span class="sale-product have-ico"><?php echo $this->__('Sale'); ?></span>
                        <?php } ?>                          
                    </div>
                </div>
                <div class="product-info col-lg-8 col-md-8 col-sm-7 col-xs-12">
                    <div class="product-name">
                        <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
                        <?php if( strlen($_helper->productAttribute($_product, $_product->getName(), 'name')) > 100 ){
                                 echo substr($_helper->productAttribute($_product, $_product->getName(), 'name'), 0, 100);
                            } else {
                                echo $_helper->productAttribute($_product, $_product->getName(), 'name');
                            }?>
                        </a>
                    </div>   
                    <div class="product-review">
                        <?php  echo $this->getReviewsSummaryHtml($_product, "short", true); ?>
                    </div>                     
                    <div class="product-price">
                        <?php echo $this->getPriceHtml($_product, true) ?>
                    </div>      

                    <?php
                        // Provides extra blocks on which to hang some features for products in the list
                        // Features providing UI elements targeting this block will display directly below the product name
                        if ($this->getChild('name.after')) {
                            $_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
                            foreach ($_nameAfterChildren as $_nameAfterChildName) {
                                $_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
                                $_nameAfterChild->setProduct($_product);
                                echo $_nameAfterChild->toHtml();
                            }
                        }
                    ?>

                    <?php if($_product->getshort_description()) { ?>
                    <div class="product-desciption">
                        <?php echo $_product->getshort_description();?>
                    </div>
                    <?php } ?>  

                    <?php /* if($_product->isSaleable()): ?>
                            <p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>
                        <?php else: ?>
                            <p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></p>
                        <?php endif; */?>
                    <div class="product-addto-wrap">
                            <div class="product-addcart">
                                <?php if($_product->isSaleable()): ?>                                    
                                    <a class="btn-cart" title="<?php echo $this->__('Add to cart') ?>" href="javascript:void(0);" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')">
                                        <?php echo $this->__('Add to cart') ?>
                                    </a>                                                                    
                                <?php endif; ?>                             
                            </div>
                            <div class="wishlist-compare">
                                <?php if ( $this->helper('wishlist')->isAllow() ) : ?>
                                <a class="link-wishlist" href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" title="<?php echo $this->__('Add to Wishlist') ?>">
                                    <?php //echo $this->__('Add to Wishlist') ?>
                                </a>
                                <?php endif; ?>

                                <?php if( $_compareUrl=$this->getAddToCompareUrl($_product) ): ?>

                                <a class="link-compare" href="<?php echo $_compareUrl ?>" title="<?php echo $this->__('Add to Compare'); ?>">
                                    <?php //echo $this->__('Add to Compare') ?>
                                </a>

                                <?php endif;?>
                            </div>
                        </div>                                          
                </div>                                                          
            </div>
        </li>
        <?php endforeach; ?>
    </ol>
    <script type="text/javascript">decorateList('products-list', 'none-recursive')</script>

    <?php else: ?>
    <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount();?>
    <?php $i=0; foreach ($_productCollection as $_product):?>
    <?php 
    $now = date("Y-m-d H:m:s");
    $newsFrom= $_product->getNewsFromDate();
    $newsTo=  $_product->getNewsToDate();
    $specialprice = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialPrice();
    $price = Mage::getModel('catalog/product')->load($_product->getId())->getPrice();
    $special_from_date = $_product->getSpecialFromDate();
    $special_to_date = $_product->getSpecialToDate();
    ?>
    <?php if ( $i++ == 0 ){ ?>
    <div class="products-grid">
        <div class="row">
            <?php } ?>
            <div class="item col-lg-4 col-md-4 col-sm-6 col-xs-12">
                <div class="item-inner">

                    <div class="product-image">
                        <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
                            <img id="product-collection-image-<?php echo $_product->getId(); ?>"
                            src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,300); ?>"
                            alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
                        </a>

                        <?php
                        // Provides extra blocks on which to hang some features for products in the list
                        // Features providing UI elements targeting this block will display directly below the product name
                        if ($this->getChild('name.after')) {
                            $_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
                            foreach ($_nameAfterChildren as $_nameAfterChildName) {
                                $_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
                                $_nameAfterChild->setProduct($_product);
                                echo $_nameAfterChild->toHtml();
                            }
                        }
                        ?>

                        <?php if ( $now>=$newsFrom && $now<=$newsTo ){ ?>
                            <span class="new-product have-ico"><?php echo $this->__('New'); ?></span>
                        <?php }
                        if ( $specialprice ){ ?>
                            <span class="sale-product have-ico"><?php echo $this->__('Sale'); ?></span>
                        <?php } ?>                          
                    </div>

                    <div class="product-info">
                        <div class="product-name">
                            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
                            <?php if( strlen($_helper->productAttribute($_product, $_product->getName(), 'name')) > 60 ){
                                 echo substr($_helper->productAttribute($_product, $_product->getName(), 'name'), 0, 60).'...more';
                            } else {
                                echo $_helper->productAttribute($_product, $_product->getName(), 'name');
                            }?>
                            </a>
                        </div>
                        <div class="product-review">
                            <?php echo $this->getReviewsSummaryHtml($_product, "short", true); ?>
                        </div>
                        <div class="product-price">
                            <?php echo $this->getPriceHtml($_product, true) ?>
                        </div>

                        <div class="product-addto-wrap">
                            <div class="product-addcart">
                                <?php if($_product->isSaleable()): ?>

                                    <a class="btn-cart" title="<?php echo $this->__('Add to cart') ?>" href="javascript:void(0);" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')">
                                        <?php echo $this->__('Add to Cart') ?>
                                    </a>

                                <?php else: ?>
                                <p class="availability out-of-stock">
                                    <span><?php echo $this->__('Out of stock') ?> </span>
                                </p>
                                <?php endif; ?>                             
                            </div>
                            <div class="wishlist-compare">
                                <?php if ( $this->helper('wishlist')->isAllow() ) : ?>
                                <a class="link-wishlist" href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" title="<?php echo $this->__('Add to Wishlist') ?>">
                                    <?php echo $this->__('Add to Wishlist') ?>
                                </a>
                                <?php endif; ?>

                                <?php if( $_compareUrl=$this->getAddToCompareUrl($_product) ): ?>

                                <a class="link-compare" href="<?php echo $_compareUrl ?>" title="<?php echo $this->__('Add to Compare'); ?>">
                                    <?php echo $this->__('Add to Compare') ?>
                                </a>

                                <?php endif;?>
                            </div>
                        </div>                          
                    </div>

                </div>
            </div>
    <?php if ( $i == $_collectionSize ){ ?>
        </div>
    </div>
    <?php } ?>
    <?php endforeach ?>
    <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
    <?php endif; ?>
</div>

<div class="toolbar-bottom">
    <?php echo $this->getToolbarHtml() ?>
</div>

</div>    
<?php if (!$this->getRequest()->isAjax()): ?>
</div>
<?php endif; ?>
<?php endif; ?>

<?phpif($this->helper('sm_shopby')->isAjaxEnabled()&&!$this->getRequest()->isAjax()):?>
<script type="text/javascript">
//<![CDATA[
function pushState(data, link, replace) {
    var History = window.History;
    if ( !History.enabled ) {
        return false;
    }

    if (replace) {
        History.replaceState(data, document.title, link);
    } else {
        History.pushState(data, document.title, link);
    }
}

function handleEvent(el, event) {
    var url, fullUrl;
    if (typeof el === 'string') {
        url = el;
    } else if (el.tagName.toLowerCase() === 'a') {
        url = $(el).readAttribute('href');
    } else if (el.tagName.toLowerCase() === 'select') {
        url = $(el).getValue();
    }

    <?php // Add this to query string for full page caching systems ?>
    if (url.indexOf('?') != -1) {
        fullUrl = url + '&isLayerAjax=1';
    } else {
        fullUrl = url + '?isLayerAjax=1';
    }

    $('loading').show();
    $('ajax-errors').hide();

    pushState(null, url, false);

    new Ajax.Request(fullUrl, {
        method: 'get',
        onSuccess: function(transport) {
            if (transport.responseJSON) {                    
                $('catalog-listing').update(transport.responseJSON.listing);
                $('layered-navigation').update(transport.responseJSON.layer);
                pushState({
                    listing: transport.responseJSON.listing,
                    layer: transport.responseJSON.layer
                }, url, true);
                ajaxListener();
            } else {
                $('ajax-errors').show();
            }
            $('loading').hide();
        }
    });

    if (event) {
        event.preventDefault();
    }
}
function ajaxListener() {
    var els;
    els = $$('div.pager-wrapper a').concat(
        $$('div.sort-by-wrap a'),
        $$('div.view-mode-wrap a'),
       // $$('div.pager select'),
        $$('div.sorter select'),
        $$('div.block-layered-nav a')
    );
    els.each(function(el) {
        if (el.tagName.toLowerCase() === 'a') {
            $(el).observe('click', function(event) {
                handleEvent(this, event);
            });
        } else if (el.tagName.toLowerCase() === 'select') {
            $(el).setAttribute('onchange', '');
            $(el).observe('change', function(event) {
                handleEvent(this, event);
            });
        }
    });
}
document.observe("dom:loaded", function() {
    ajaxListener();

    (function(History) {
        if ( !History.enabled ) {
            return false;
        }

        pushState({
            listing: $('catalog-listing').innerHTML,
            layer: $('layered-navigation').innerHTML
        }, document.location.href, true);

        // Bind to StateChange Event
        History.Adapter.bind(window, 'popstate', function(event) {
            if (event.type == 'popstate') {
                var State = History.getState();
                $('catalog-listing').update(State.data.listing);
                $('layered-navigation').update(State.data.layer);
                ajaxListener();
            }
        });
    })(window.History);
});
//]]>
</script>
<?php endif; ?>

<?php if ($this->getRequest()->isAjax()){ ?>


<?php } ?>

<?php
// Provides a block where additional page components may be    attached,primarily     good for in-page JavaScript
if ($this->getChild('after')) {
$_afterChildren = $this->getChild('after')->getSortedChildren();
foreach ($_afterChildren as $_afterChildName) {
    $_afterChild = $this->getChild('after')->getChild($_afterChildName);
    //set product collection on after blocks
    $_afterChild->setProductCollection($_productCollection);
    echo $_afterChild->toHtml();
}
}
?>

更新的

我在add中做了一些更改,以比较按钮,

代码语言:javascript
复制
 <?php 
   if(Mage::getSingleton('customer/session')->isLoggedIn()){
 <?php if( $_compareUrl=$this->getAddToCompareUrl($_product) ): ?>

                            <a class="link-compare" href="<?php echo $_compareUrl ?>" title="<?php echo $this->__('Add to Compare'); ?>">
                                <?php //echo $this->__('Add to Compare') ?>
                            </a>

                            <?php endif;?>
                            }
                            else
                            {
    <?php echo '<script type="text/javascript"> alert("Registration is required for compare product"); </script>?>

  }
         ?>                     
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-05 06:38:24

过了很长一段时间才找到解决办法。

我在“比较”按钮的位置添加了以下代码

代码语言:javascript
复制
<?php if( $_compareUrl=$this->getAddToCompareUrl($_product) ): ?>
                            <?php if(Mage::getSingleton('customer/session')->isLoggedIn()) { ?>
                            <a class="link-compare" href="<?php echo $_compareUrl ?>" title="<?php echo $this->__('Add to Compare'); ?>"></a>
                        <?php } else { ?>
                        <a class="link-compare loginToCompare" title="<?php echo $this->__('Add to Compare'); ?>"></a>
                        <?php } ?>
                            <?php endif;?>

并在页面底部添加以下jquery,用于重定向登录页或创建帐户。

代码语言:javascript
复制
    jQuery(document).ready(function($){
   $(".loginToCompare").click(function(){
     var r = confirm("You can not compare product without registration please click ok to login or create account!");
    if (r == true) {
         window.location.href="/customer/account/login/";
    }       
});
});

这对我来说真的很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38716901

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档