2016-08-02 5 views
0

登録されていないユーザーが追加するをクリックすると、登録の警告が表示されます(メッセージは「登録が必要です」)。助けてください。私はmagento 1.9を使用しています。誰もが答えを共有してください知っている。商品の機能性を比較すると、登録されていないユーザーにはマゼンタでは許可されません

これは、このようなボタンを比較するために、アドオンで

私が行った変更を更新しました私のlist.phtmlファイル

<?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(); 
} 
} 
?> 

、長い後

<?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>?> 

    } 
     ?>      
+0

あなたがこれまでに試したことを見るためにコードの一部を共有してください。 –

+0

私はすでに機能を比較するために追加しています。私はちょうどこの機能がサイトに登録したユーザーのみを有効にし、未登録のユーザーが「比較する」ボタンをクリックすると、「登録が必要です」という警告が表示されます。 –

+0

はい、あなたの質問については、上記の理由と同じ理由であなたの質問に投票する人がいるかもしれないと感じているからです。 –

答えて

0

ガット・ソリューションであります時間。

私はボタンを

<?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を追加したり、これは本当に働いている

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/"; 
    }  
}); 
}); 

アカウントを作成しています私のために良い。

関連する問題