문제

고객이 특정 그룹에 로그인하고 해당 그룹이 특별 가격이있는 경우 제품 이미지의 모서리에 이미지를 표시하고 싶습니다.

고객이 로그인했는지 여부를 확인하기위한 코드가 있으며 어떤 그룹이 있는지 확인하고 A가 사실 인 경우를 추가 할 수 있습니다.이것은 내가 가진 코드입니다.

<?php       
        $_isLoggedIn = $this->helper('customer')->isLoggedIn();
        if($_isLoggedIn == true){
        $_myGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();          
        if($_myGroupId == 5){
        ?><div class="special"> </div><?php
                }
            }
    ?>
.

그러나 해당 제품에도 해당 고객 그룹에 대한 특별 가격이 있는지 확인하는 것이 또 다른 경우가 필요합니다.나는이 코드를 사용하여 price.phtml 전에 이것을 해냈습니다

<?php $login = Mage::getSingleton( 'customer/session' )->isLoggedIn(); //Check if User is Logged In
        if($login && Mage::getSingleton('customer/session')->getCustomerGroupId()==5)
        {
        $groupPrices = $_product->getData('group_price');
        $Groupprice= $groupPrices;
            if (is_null($groupPrices)) {
                $attribute = $_product->getResource()->getAttribute('group_price');
                if ($attribute){
                    $attribute->getBackend()->afterLoad($_product);
                    $groupPrices = $_product->getData('group_price');}} 
            /* check group price exit nor not */
             if (!is_null($groupPrices) || is_array($groupPrices)) {
                foreach ($groupPrices as $groupPrice) {  
                if($groupPrice['cust_group'] == Mage::getSingleton('customer/session')->getCustomerGroupId()){
                $Groupprice = $groupPrice['website_price'];   
                 $Groupprice=$groupPrice['cust_group'];
                break;}} }
             /* $Groupprice  is null mean group price is not  exit*/
             if(!is_null($Groupprice)){
           //group price exits ?>
           <span class="price-label"><?php echo "Your Special Price " ?></span><?php}?>
.

그러나이 코드는 View.phtml에서 작동하지 않습니다.나는 약간의 놀이를했고, 나는 일하기 위해 그것을 얻을 수없는 것처럼 보일 수 없으며, 누군가가 내 원래 if 문에 다른 IF 진술을 추가하는 데 도움이 될 수 있었다.

내가 분명하지 않으면 알려주세요.미리 감사드립니다.

도움이 되었습니까?

해결책

안녕하세요 제품 페이지로 제품 개체를 $ _Product로 변경해야합니다.

    <?php 
    $login = Mage::getSingleton( 'customer/session' )->isLoggedIn(); 
//Check if User is Logged In
            if($login)
            {
            $groupPrices = $_product->getData('group_price');
            $Groupprice= $groupPrices;
                /* check group price exit nor not */
                 if (!is_null($groupPrices) || is_array($groupPrices)) {
                    foreach ($groupPrices as $groupPrice) {
                    /* match with current customer group */
                    if($groupPrice['cust_group'] == Mage::getSingleton('customer/session')->getCustomerGroupId()){
                    echo $Groupprice = $groupPrice['website_price'];
                    echo "<br/>";   
                    echo $Groupprice=$groupPrice['cust_group'];
                    break;
                    }
                    }

                 }
                 /* $Groupprice  is null mean group price is not  exit*/
                 if(!is_null($Groupprice)){
                     //group price eixts
                     ?>
                     <span class="price-label"><?php echo "Special Group Price " ?></span>
                    <?php 
                 }else{
                     //Group price is exits.
                     ?>
                     <span class="price-label"><?php echo "Now" ?></span> 
                 <?php }
            ?>
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top