1

I am installing Marketplace Extension In My website. In Product details Page i need to display seller Product count(How many Product have) and display 3 image of current Seller.

This is my .phtml

    $active = Mage::getStoreConfig('marketplace/admin_approval_seller_registration/displayproductpage');
    if ($active == 1) { 
        $productId = Mage::registry('current_product')->getEntityId();      
        $sellerId      = Mage::registry('current_product')->getSellerId();
        $sellerData    = $this->sellerdisplay($sellerId);
        $showProfile   = $this->sellerprofiledisplay($sellerId);
        if ($showProfile == 1) { 
            $targetPath = 'marketplace/seller/displayseller/id/' . $sellerId;
            $mainUrlRewrite     = Mage::getModel('core/url_rewrite')->load($targetPath, 'target_path');
            $getRequestPath     = $mainUrlRewrite->getRequestPath();
            $getRequestPath    = Mage::getUrl($getRequestPath);
            ?>
             <div  class="linker_seller"> 
            <strong><?php echo $this->__('Seller'); ?></strong>: 
            <a href='<?php echo $getRequestPath; ?>' class="link_seller"><?php echo $sellerData['store_title']; ?></a>
           <address><?php  $_countries = Mage::getResourceModel('directory/country_collection')->loadData()->toOptionArray(false); ?>
            <?php foreach ($_countries as $_country) {?>
                <?php if($sellerData['country'] == $_country['value']){?>
                    <?php $sellerCountry = $_country['label'];?>
                <?php } ?>
            <?php } ?>
            <?php echo $sellerData['state'].','.$sellerCountry;?></address> 
            <p><?php $description = strip_tags($sellerData['description']);
            $newLengthDescription = strlen( $description);
            $newSubDescription = substr($description, 0, 160);
            if ($newLengthDescription >= 160) {
                $newDescriptionFix = $newSubDescription . "...";
            } else {
                $newDescriptionFix = $description;
            }
            echo $newDescriptionFix; ?>
            <!-- Test -->
<?php
    //Get seller data collection
    /*$seller_collection = $this->getCollection();
    $seller_count = count($seller_collection);*/

    $collection          = Mage::getResourceModel('catalog/product_collection');
        $collection->addAttributeToFilter('status',1); //only enabled product
        $collection->addAttributeToSelect('*'); //add product attribute to be fetched
        $collection->addAttributeToFilter('seller_id',$sellerId);
        $collection->addStoreFilter();?>

            <div class="my-account-wrapper"><ul class="mp_all_sellers_container f-left" border="0" cellspacing="0" cellpadding="0">
   <?php 
        foreach ($collection as $_seller_collection) {
          $sellerId = $_seller_collection['entity_id'];
          $get_requestPath = Mage::helper('marketplace/marketplace')->getSellerRewriteUrl($sellerId);?>
          <li class="f-left">
            <a class="mp_all_sellers_view" href="<?php echo $get_requestPath; ?>" title="<?php echo $_seller_collection['store_title']; ?>">
            <?php if (strpos($_seller_collection['store_logo'], '.') && $_seller_collection['store_title'] != '') {?>                    
                <img src="<?php echo Mage::getBaseUrl('media') . "marketplace/resized/" . $_seller_collection['store_logo']; ?>" style="vertical-align: middle;" /> 
            <?php } elseif (!strpos($_seller_collection['store_logo'], '.') && $_seller_collection['store_title'] != '') { ?>
                <img src="<?php echo $this->getSkinUrl('images/no-image-thumbnail.png'); ?>" style="vertical-align: middle;" />
            <?php } ?>
            </a>
            <div class="store-title">
                    <a href="<?php echo $get_requestPath; ?>" title="<?php echo $_seller_collection['store_title']; ?>"><?php echo $_seller_collection['store_title']; ?></a>
                    <address><?php $country = Mage::getModel('directory/country')->loadByCode($_seller_collection['country']);
                        echo $_seller_collection['state'].','."<br/>".$country->getName();?>
                    </address>
<?php //echo $seller_id;?>
            </div>

            <!-- Products for the Sellers -->
                <div class="seller-products">
                <ul id = "seller-product-list" class="products-grid product_snipt f-left">
                    <?php 
                    $sellerProductsCollection = $this->getSellerProducts($sellerId);
                    //echo count($sellerProductsCollection);
                    if (count($sellerProductsCollection) > 0) {
                       $a=1;
                            foreach($sellerProductsCollection as $sellerProduct){
                            if($a%3==0){ 
                                break;
                            }
                                ?>
                            <li class="item <?php if($limit==0):?> bigimage<?php endif;?>">
                                <a href="<?php echo $sellerProduct->getProductUrl(); ?>">
                                    <img class="product-image" 
                                    <?php if($limit==0):?>
                                    src="<?php echo $this->helper('catalog/image')->init($sellerProduct, 'thumbnail')->resize(230); ?>" 
                                    <?php else:?>
                                    src="<?php echo $this->helper('catalog/image')->init($sellerProduct, 'thumbnail')->resize(125); ?>" 
                                    <?php endif;?>
                                    alt="<?php echo $this->stripTags($this->getImageLabel($sellerProduct, 'small_image'), null, true) ?>" />
                                </a>
                            </li>

                            <?php 
                        $a++;}

                    }
                    ?>
                </ul>
                <div class="productslist_bottom">
                <p><span class="totalproducts"><?php echo count($sellerProductsCollection)?></span>
                <span style="font-size:12px">product(s)</span></p>
                <a href="<?php echo $get_requestPath; ?>" title="<?php echo $_seller_collection['store_title']; ?>"><?php echo $this->__("View More")?></a>
                </div>
                </div>
                <!-- Products End here -->

         </li>
    <?php } ?> 
    </ul>
    </div>

            <!-- Test -->
            <a href="<?php echo $getRequestPath; ?>"><?php echo $this->__('Read More'); ?></a></p>
            <?php 
            $country = str_replace(" ", "+",$sellerData->getCountry());
            $state = str_replace(" ", "+",$sellerData->getState());
            $url = 'http://maps.google.com/maps/api/geocode/json?address="'.$state.'"&sensor=false&region="'.$country.'"';
            $response = file_get_contents($url);
            $response = json_decode($response, true);
            $lat = $long = '';
            if(isset($response['results'][0]['geometry']['location']['lat'])){
            $lat = $response['results'][0]['geometry']['location']['lat'];
            }
            if(isset($response['results'][0]['geometry']['location']['lng'])){
            $long = $response['results'][0]['geometry']['location']['lng'];
            }

            if(!empty($lat) && !empty($long)){
            ?>
           <script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>
    <script>
    var myCenter=new google.maps.LatLng(<?php echo $lat; ?>,<?php echo $long;?>);

    function initialize()
    {
    var mapProp = {
      center:myCenter,
      zoom:5,
      mapTypeId:google.maps.MapTypeId.ROADMAP
      };

    var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);

    var marker=new google.maps.Marker({
      position:myCenter,
      });

    marker.setMap(map);
    }

    google.maps.event.addDomListener(window, 'load', initialize);


    </script>
            <div id="googleMap"  style="height:150px"></div>

      <?php } 

      /**
       * Ends map functionality
       */
       ?>      

        <?php 

    $displaySeller  = Mage::getModel('marketplace/sellerreview')->displayReview($sellerId);
    $firstStar     = $secondStar = $thirdStar = $fourthStar = $fifthStar = $advancedTotal = $ratingbar_color = 0;

    /**
     * ITERATING ALL RATINGS
     */ 
    $advancedTotal=0;
    foreach ($displaySeller as $individualStar) {
        $advancedTotal = $advancedTotal + 1;
        if ($individualStar['rating'] == 1) {
            $firstStar = $firstStar + 1;
        } elseif ($individualStar['rating'] == 2) {
            $secondStar = $secondStar + 1;
        } elseif ($individualStar['rating'] == 3) {
            $thirdStar = $thirdStar + 1;
        } elseif ($individualStar['rating'] == 4) {
            $fourthStar = $fourthStar + 1;
        } elseif($individualStar['rating'] == 5) {
            $fifthStar = $fifthStar + 1;
        }
    }

    /**
     *  CALCULATING INDIVIDUAL RATINGS 
     */  

    $advancedOne = $advancedTwo = $advancedThree = $advancedFour = $advancedFive = 0;

    if($advancedTotal >= 1){
    $advancedOne   = ($firstStar / $advancedTotal) * 100;
    $advancedTwo   = ($secondStar / $advancedTotal) * 100;
    $advancedThree = ($thirdStar / $advancedTotal) * 100;
    $advancedFour  = ($fourthStar / $advancedTotal) * 100;
    $advancedFive  = ($fifthStar / $advancedTotal) * 100;
    }

    $positiveFeedBack = ($advancedFour + $advancedFive)/2;
    $totalRatings = $firstStar + $secondStar + $thirdStar + $fourthStar + $fifthStar;
    if($totalRatings != ''){
        echo round($positiveFeedBack,1);
        echo $this->__('% positive feedback. (');
        echo number_format($totalRatings).' ';
        echo $this->__('ratings )');
    }
    ?>      
   <span class="title-sp"><?php $sellerProducts = $this->sellerproduct($sellerId);
   $sellerProducts->addFieldToFilter('entity_id',array('neq' => $productId));
   $sellerProducts->getSelect()->limit(4);
   ?>
    <?php if(count($sellerProducts) >= 1){ ?>
    <?php echo $this->__('Other products from this seller');?>
    <?php foreach($sellerProducts as $_sellerProducts){ ?>
        <?php if($productId != $_sellerProducts['entity_id']){
            $productInfo = Mage::helper('marketplace/marketplace')->getProductInfo($_sellerProducts['entity_id']);
        ?></span> 
<img src="<?php echo Mage::helper('catalog/image')->init($productInfo, 'small_image')->resize(50); ?>" width="50" height="50" />

    <?php } } ?>

<a href='<?php echo $getRequestPath; ?>' class="btn_more"><?php echo $this->__('More')?></a>
   <?php  } ?>
   </div>
<?php } ?>

<?php } ?>
9
  • as far as i understand this code there is not code related to seller product kindly add related or at-least tables name of seller product. Mar 2, 2016 at 11:12
  • I used this $sellerProductsCollection = $this->getSellerProducts($sellerid);<p><span class="totalproducts"><?php echo count($sellerProductsCollection)?></span> it always return 0 only
    – Magento 2
    Mar 2, 2016 at 11:14
  • did you check current ` $this->getSellerProducts()` function in block and also the variable in code $sellerId not $sellerid Mar 2, 2016 at 11:17
  • Actually this is working code in another phtm so i used but no result
    – Magento 2
    Mar 2, 2016 at 11:19
  • when you using $this it reference to current block check you current have this method or not. enable template/block hint and check if not there add it there. Mar 2, 2016 at 11:21

1 Answer 1

1
 $collection          = Mage::getResourceModel('catalog/product_collection');
        $collection->addAttributeToFilter('status',1); //only enabled product
        $collection->addAttributeToSelect('*'); //add product attribute to be fetched
        $collection->addAttributeToFilter('seller_id',$sellerId);
        $collection->addStoreFilter();

here is you collection add count($collection);

              $a=1;
            foreach($collection as $product)
            {  //show you product here
              if($a%3==0) { break;}
             $a++;
              }
18
  • then i use same code in this file right
    – Magento 2
    Mar 2, 2016 at 12:12
  • yes use it anywhere you want to show seller products. Mar 2, 2016 at 12:14
  • yes in product details page
    – Magento 2
    Mar 2, 2016 at 12:15
  • use that but first check you have $sellerId. Mar 2, 2016 at 12:16
  • apply this code in collection product are loaded just display image of products. Mar 2, 2016 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.