Advertisement
Guest User

trending product

a guest
Jul 17th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.44 KB | None | 0 0
  1. <?php
  2. $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
  3. $store = $objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore();
  4.  
  5. $_helper          = $this->helper('Kemana\Homepage\Helper\Data');
  6. $priceHelper      = $objectManager->create('Magento\Framework\Pricing\Helper\Data');
  7.  
  8.  
  9. $_cat1Enable      = $_helper->getConfig('homepage/general/cat1_enable');
  10. $_cat2Enable      = $_helper->getConfig('homepage/general/cat2_enable');
  11. $_cat3Enable      = $_helper->getConfig('homepage/general/cat3_enable');
  12.  
  13. $_cat1Title       = $_helper->getConfig('homepage/general/cat1_title');
  14. $_cat2Title       = $_helper->getConfig('homepage/general/cat2_title');
  15. $_cat3Title       = $_helper->getConfig('homepage/general/cat3_title');
  16.  
  17. $_cat1Select      = $_helper->getConfig('homepage/general/cat1_select');
  18. $_cat2Select      = $_helper->getConfig('homepage/general/cat2_select');
  19. $_cat3Select      = $_helper->getConfig('homepage/general/cat3_select');
  20.  
  21. $_productLimit      = $_helper->getConfig('homepage/general/trending_limit');
  22. // $categoryId       = $_helper->getConfig('homepage/general/category');
  23.  
  24. /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
  25. $productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
  26.  
  27. $_cat1         = $objectManager
  28.                ->create('Magento\Catalog\Model\Category')->load($_cat1Select);
  29. $_cat2         = $objectManager
  30.                ->create('Magento\Catalog\Model\Category')->load($_cat2Select);
  31. $_cat3         = $objectManager
  32.                ->create('Magento\Catalog\Model\Category')->load($_cat3Select);
  33.  
  34. // $_TrendingConfig = $this->getLayout()->createBlock('Kemana\Homepage\Block\HomeTrendingProduct');
  35. $_trendingConfig = $block->getTrendingConfig();
  36. $_trendingLimit = $_trendingConfig->getTrendingLimit();
  37.  
  38. ?>
  39.  
  40. <div class="trending-product__header">
  41.    <h2 class="trending-header__title"> <?php echo $_trendingConfig->getTrendingTitle(); ?></h1>
  42.       <div class="trending-header__category">
  43.          <div class="trending-category__tab" id="catTabs">
  44.             <ul class="nav nav-tabs">
  45.                <?php if($_trendingConfig->getCat1Status() == 1): ?>
  46.                   <li class="active"><a  href="#trend1" data-toggle="tab"><?php echo $_trendingConfig->getCat1Title(); ?></a></li>
  47.                <?php endif; ?>
  48.  
  49.                <?php if($_trendingConfig->getCat2Status() == 1): ?>
  50.                   <li><a href="#trend2" data-toggle="tab"><?php echo $_trendingConfig->getCat2Title(); ?></a></li>
  51.                <?php endif; ?>
  52.  
  53.                <?php if($_trendingConfig->getCat3Status() == 1): ?>
  54.                   <li><a href="#trend3" data-toggle="tab"><?php echo $_trendingConfig->getCat3Title(); ?></a></li>
  55.                <?php endif; ?>
  56.             </ul>
  57.             <div class="tab-content ">
  58.                <?php if($_trendingConfig->getCat1Status() == 1):?>
  59.                   <div class="tab-pane active" id="trend1">
  60.                      <div class="trending-product__content owl-carousel owl-theme <?php echo $_trendingConfig->getCat1Value()?>" id="cat1">
  61.  
  62.                         <?php
  63.                         $_cat1Id = $_trendingConfig->getCat1Value();
  64.                         $_product1 = $block->getProductCollection($_cat1Id, $_trendingLimit);
  65.  
  66.                         foreach ($_product1 as $product1):
  67.                            $imageUrl = $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product1->getImage();
  68.                            $productTypeInstance = $objectManager->get('Magento\ConfigurableProduct\Model\Product\Type\Configurable');
  69.                            $productAttributeOptions = $productTypeInstance->getConfigurableAttributesAsArray($product1);
  70.                            $productAttribute = $block->getConfigurableProduct($product1);
  71.  
  72.                            ?>
  73.                            <div class="trending-item item">
  74.                               <a href="<?php echo $product1->getProductUrl();?>" class="trending-item__images">
  75.                                  <img src="<?php echo $imageUrl;?>" alt="<?php echo $product1->getName()?>"/>
  76.                               </a>
  77.  
  78.                               <div class="trending-item__content">
  79.                                  <div class="trending-content__summary">
  80.                                     <span class="trending-summary__color">
  81.                                        <?php foreach ($productAttribute as $key => $value) {
  82.                                           $tmp_option = $value['values'];
  83.                                           $_value = strtolower($value['label']);
  84.                                           if($_value == 'color'):
  85.                                              echo count($tmp_option) . ' Colours';
  86.                                           endif;
  87.                                        } ?>
  88.                                     </span>
  89.  
  90.                                     <span class="trending-summary__label">
  91.                                        <?php if($product1->getNew() != 0){
  92.                                           echo 'NEW';
  93.                                        } ?>
  94.                                     </span>
  95.                                  </div>
  96.  
  97.                                  <a href="<?php echo $product1->getProductUrl();?>" class="trending-content__title">
  98.                                     <span class="trending-title"><?php echo $product1->getName()?></span>
  99.                                  </a>
  100.  
  101.                                  <a href="<?php echo $product1->getProductUrl();?>" class="trending-content__category">
  102.                                     <span class="trending-category"> <?php echo $_cat1->getName();?></span>
  103.                                  </a>
  104.  
  105.                                  <div class="trending-content__prices">
  106.                                     <?php if($product1->getSale() == 0){?>
  107.                                        <span class="regular-prices"> <?php echo $priceHelper->currency($product1->getFinalPrice(), true, false);?></span>
  108.                                     <?php }else { ?>
  109.                                        <div class="sales-prices">
  110.                                           <span class="price"> MYR 140.00</span>
  111.                                           <span class="price-text"> (30% off) </span>
  112.                                        </div>
  113.                                     <?php } ?>
  114.                                  </div>
  115.                               </div>
  116.                            </div>
  117.                         <?php endforeach; ?>
  118.                      </div>
  119.                   </div>
  120.                <?php endif; ?>
  121.  
  122.                <?php if($_trendingConfig->getCat2Status() == 1):?>
  123.                   <div class="tab-pane" id="trend2">
  124.                      <div class="trending-product__content owl-carousel owl-theme <?php echo $_trendingConfig->getCat2Value()?>" id="cat2">
  125.                         <?php
  126.  
  127.                         $_cat2Id = $_trendingConfig->getCat1Value();
  128.                         $_product2 = $block->getProductCollection($_cat2Id, $_trendingLimit);
  129.                         foreach ($_product2 as $product2):
  130.                            $imageUrl2 = $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product2->getImage();
  131.  
  132.                            $product2TypeInstance = $objectManager->get('Magento\ConfigurableProduct\Model\Product\Type\Configurable');
  133.                            $product2AttributeOptions = $product2TypeInstance->getConfigurableAttributesAsArray($product2);
  134.  
  135.                            ?>
  136.                            <div class="trending-item item">
  137.                               <a href="<?php echo $product2->getProductUrl();?>" class="trending-item__images">
  138.                                  <img src="<?php echo $imageUrl2;?>" alt="<?php echo $product2->getName()?>"/>
  139.                               </a>
  140.  
  141.                               <div class="trending-item__content">
  142.                                  <div class="trending-content__summary">
  143.                                     <span class="trending-summary__color">
  144.                                        <?php foreach ($product2AttributeOptions as $key => $value) {
  145.                                           $tmp_option = $value['values'];
  146.                                           $_value = strtolower($value['label']);
  147.  
  148.                                           if($_value == 'color'):
  149.                                              echo count($tmp_option) . ' Colours';
  150.                                           endif;
  151.                                        } ?>
  152.                                     </span>
  153.  
  154.                                     <span class="trending-summary__label">
  155.                                        <?php if($product2->getNew() != 0){
  156.                                           echo 'NEW';
  157.                                        } ?>
  158.                                     </span>
  159.                                  </div>
  160.  
  161.                                  <a href="<?php echo $product2->getProductUrl();?>" class="trending-content__title">
  162.                                     <span class="trending-title"><?php echo $product2->getName()?></span>
  163.                                  </a>
  164.  
  165.                                  <a href="<?php echo $product2->getProductUrl();?>" class="trending-content__category">
  166.                                     <span class="trending-category"> <?php echo $_cat2->getName();?></span>
  167.                                  </a>
  168.  
  169.                                  <div class="trending-content__prices">
  170.                                     <?php if($product2->getSale() == 0){?>
  171.                                        <span class="regular-prices"> <?php echo $priceHelper->currency($product2->getFinalPrice(), true, false);?></span>
  172.                                     <?php }else { ?>
  173.                                        <div class="sales-prices">
  174.                                           <span class="price"> MYR 140.00</span>
  175.                                           <span class="price-text"> (30% off) </span>
  176.                                        </div>
  177.                                     <?php } ?>
  178.                                  </div>
  179.                               </div>
  180.                            </div>
  181.                         <?php endforeach; ?>
  182.                      </div>
  183.                   </div>
  184.                <?php endif; ?>
  185.  
  186.                <?php if($_cat3Enable == 1):?>
  187.                   <div class="tab-pane" id="trend3">
  188.                      <div class="trending-product__content owl-carousel owl-theme" id="cat3">
  189.                         <?php
  190.                         $_product3 = $productCollection->addAttributeToFilter('type_id', 'configurable')
  191.                         ->addAttributeToSelect('*')
  192.                         ->addCategoriesFilter(['eq' => $_cat3Select])
  193.                         ->setPageSize($_productLimit)
  194.                         ->setCurPage(1)->load();
  195.                         foreach ($_product3 as $product):
  196.                            $imageUrl = $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
  197.  
  198.                            $productTypeInstance = $objectManager->get('Magento\ConfigurableProduct\Model\Product\Type\Configurable');
  199.                            $productAttributeOptions = $productTypeInstance->getConfigurableAttributesAsArray($product);
  200.  
  201.                            ?>
  202.                            <div class="trending-item item">
  203.                               <a href="<?php echo $product->getProductUrl();?>" class="trending-item__images">
  204.                                  <img src="<?php echo $imageUrl;?>" alt="<?php echo $product->getName()?>"/>
  205.                               </a>
  206.  
  207.                               <div class="trending-item__content">
  208.                                  <div class="trending-content__summary">
  209.                                     <span class="trending-summary__color">
  210.                                        <?php foreach ($productAttributeOptions as $key => $value) {
  211.                                           $tmp_option = $value['values'];
  212.                                           $_value = strtolower($value['label']);
  213.  
  214.                                           if($_value == 'color'):
  215.                                              echo count($tmp_option) . ' Colours';
  216.                                           endif;
  217.                                        } ?>
  218.                                     </span>
  219.  
  220.                                     <span class="trending-summary__label">
  221.                                        <?php if($product->getNew() != 0){
  222.                                           echo 'NEW';
  223.                                        } ?>
  224.                                     </span>
  225.                                  </div>
  226.  
  227.                                  <a href="<?php echo $product->getProductUrl();?>" class="trending-content__title">
  228.                                     <span class="trending-title"><?php echo $product->getName()?></span>
  229.                                  </a>
  230.  
  231.                                  <a href="<?php echo $product->getProductUrl();?>" class="trending-content__category">
  232.                                     <span class="trending-category"> <?php echo $_cat3->getName();?></span>
  233.                                  </a>
  234.  
  235.                                  <div class="trending-content__prices">
  236.                                     <?php if($product->getSale() == 0){?>
  237.                                        <span class="regular-prices"> <?php echo $priceHelper->currency($product->getFinalPrice(), true, false);?></span>
  238.                                     <?php }else { ?>
  239.                                        <div class="sales-prices">
  240.                                           <span class="price"> MYR 140.00</span>
  241.                                           <span class="price-text"> (30% off) </span>
  242.                                        </div>
  243.                                     <?php } ?>
  244.                                  </div>
  245.                               </div>
  246.                            </div>
  247.                         <?php endforeach; ?>
  248.                      </div>
  249.                   </div>
  250.                <?php endif; ?>
  251.             </div>
  252.          </div>
  253.       </div>
  254.    </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement