Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.66 KB | None | 0 0
  1. <?php
  2. use Magento\Framework\App\Action\Action;
  3.  
  4. $title = $block->getData('title') ? $block->getData('title') : '';
  5. $subtitle = $block->getData('subtitle') ? $block->getData('subtitle') : '';
  6. $category_id = $block->getData('category_id');
  7. $_helper = $this->helper('Magento\Catalog\Helper\Output');
  8. $size = $block->getData('products_count');
  9. $productCollection = $this->getProductCollection($category_id, $size);
  10. $imageBlock =  $block->getLayout()->createBlock('Magento\Catalog\Block\Product\ListProduct');
  11. $showCart = true;
  12. $type = 'widget-new-grid';
  13. $viewMode = 'grid';
  14. $image = 'category_page_grid';
  15. $pos = $block->getPositioned();
  16. //$showDescription = true;
  17. $showDescription = $block->getData('show_description');
  18.  
  19. $bestSeller =  $block->getBestSellerData();
  20. //$products_id = array();
  21. //$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
  22.  
  23. /*foreach ($bestSeller as $product) {
  24.     $products_id[] = $block->getParentProductId($product->getProductId());
  25. }
  26.  
  27. $products_id = array_unique($products_id);
  28. var_dump($products_id);*/
  29.  
  30. $month_ago = strtotime('-1 month');
  31. $bestseller_data = array();
  32.  
  33. //echo '<br><br>test time: <br>';
  34. foreach ($bestSeller as $product) {
  35.     $data = $product->getData();
  36.     $d = new DateTime($data['period']);
  37.     if($d->format('U') > $month_ago){
  38.         //var_dump($product->getData());
  39.         $parent_id = $block->getParentProductId($data['product_id']);
  40.         if(!array_key_exists($parent_id, $bestseller_data)){
  41.             $bestseller_data[$parent_id] = (int)$data['qty_ordered'];
  42.         }else{
  43.             $bestseller_data[$parent_id] += (int)$data['qty_ordered'];
  44.         }
  45.         //echo '<br>';
  46.     }
  47. }
  48.  
  49. arsort($bestseller_data);
  50. echo 'bestseller_data: <br>';
  51. var_dump($bestseller_data);
  52.  
  53. $test_col = $block->loadProductsByIdAndCat(array_keys($bestseller_data), 3);
  54.  
  55. echo 'collection: <br>';
  56. foreach ($test_col as $_p) {
  57.     var_dump($_p->getData());
  58.     echo '<br>';
  59. }
  60.  
  61. ?>
  62.  
  63. <div class="soundshocking_widget_product_list">
  64.     <div class="title"><span><?php echo $title; ?></span></div>
  65.     <div class="subtitle"><?php echo $subtitle; ?></div>
  66.     <div class="products-grid">
  67.         <div class="products list items product-items">
  68.             <ul class="product-items">
  69.                 <?php $iterator = 1; ?>
  70.                 <?php //foreach ($products_id as $product): ?>
  71.                 <?php //foreach ($bestseller_data as $key => $value): ?>
  72.                 <?php //$_product = $block->getLoadProduct($key) ?>
  73.                 <?php foreach ($test_col as $_product): ?>
  74.                 <?php $productImage = $imageBlock->getImage($_product, 'category_page_grid');
  75.                     if ($pos == null) {                                                        
  76.                         $position = ' style="left:' . $productImage->getWidth() . 'px;'
  77.                             . 'top:' . $productImage->getHeight() . 'px;"';
  78.                     }
  79.                     ?>
  80.                 <?php /* @escapeNotVerified */ echo($iterator++ == 1) ? '<li class="product-item"><div class="product-item-info">' : '</div></li><li class="product-item"><div class="product-item-info">' ?>
  81.                 <a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $productImage->toHtml()  ?></a>
  82.                 <div class="product details product-item-details">
  83.                     <div class="pl-bestseller-count tooltip-pl">
  84.                         <div class="pl-heart"></div>
  85.                         <div class="pl-count"><?php /*echo $value;*/ echo $bestseller_data[$_product->getId()] ?></div>
  86.                         <span class="tooltiptext tooltip-right">test</span>
  87.                     </div>
  88.                     <strong class="product name product-item-name">
  89.                         <a class="product-item-link"  href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>">
  90.                             <?php /* @escapeNotVerified */ echo $_product->getName(); ?>
  91.                         </a>
  92.                     </strong>
  93.                     <?php if ($showCart): ?>
  94.                         <?php if($showDescription == 1): ?>
  95.                             <div class="description">
  96.                                 <?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
  97.                             </div>
  98.                         <?php endif ?>
  99.                     <?php //echo $this->getProductPricetoHtml($_product, $type); ?>
  100.                     <?php echo $block->getProductDetailsHtml($_product); ?>
  101.  
  102.                     <div id="price_and_cart">
  103.                         <?php echo $this->getProductPricetoHtml($_product, $type); ?>
  104.  
  105.                         <?php if ($_product->isSaleable()): ?>
  106.                             <?php $postParams = $block->getAddToCartPostParams($_product); ?>
  107.                             <form data-role="tocart-form" action="<?php /* @escapeNotVerified */ echo $postParams['action']; ?>" method="post">
  108.                                 <input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams['data']['product']; ?>">
  109.                                 <input type="hidden" name="<?php /* @escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
  110.                                 <?php echo $block->getBlockHtml('formkey')?>
  111.                                 <button type="submit"
  112.                                         title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
  113.                                         class="tocart_category_view">
  114.                                     <?php /* @escapeNotVerified */ echo __('Add to Cart') ?>
  115.                                 </button>
  116.                             </form>
  117.                         <?php else: ?>
  118.                             <?php if ($_product->getIsSalable()): ?>
  119.                                 <div class="stock available"><span><?php /* @escapeNotVerified */ echo __('In stock') ?></span></div>
  120.                             <?php else: ?>
  121.                                 <div class="stock unavailable" title="Out of Stock"><span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span></div>
  122.                             <?php endif; ?>
  123.                         <?php endif; ?>
  124.                     </div>
  125.  
  126.  
  127.                     <!--<div class="product-item-inner">
  128.                         <div class="product actions product-item-actions">
  129.                             <div class="actions-primary"<?php echo strpos($pos, $viewMode . '-primary') ? $position : ''; ?>>
  130.                                 <?php if ($_product->isSaleable()): ?>
  131.                                 <?php $postParams = $block->getAddToCartPostParams($_product); ?>
  132.                                 <form data-role="tocart-form" action="<?php /* @escapeNotVerified */ echo $postParams['action']; ?>" method="post">
  133.                                     <input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams['data']['product']; ?>">
  134.                                     <input type="hidden" name="<?php /* @escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
  135.                                     <?php echo $block->getBlockHtml('formkey')?>
  136.                                     <button type="submit"
  137.                                         title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
  138.                                         class="action tocart primary">
  139.                                     <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
  140.                                     </button>
  141.                                 </form>
  142.                                 <?php else: ?>
  143.                                 <?php if ($_product->getIsSalable()): ?>
  144.                                 <div class="stock available"><span><?php /* @escapeNotVerified */ echo __('In stock') ?></span></div>
  145.                                 <?php else: ?>
  146.                                 <div class="stock unavailable"><span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span></div>
  147.                                 <?php endif; ?>
  148.                                 <?php endif; ?>
  149.                             </div>
  150.    
  151.                             <div class="actions-secondary" data-role="add-to-links">
  152.                                 <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
  153.                                     <a href="#"
  154.                                        data-post='<?php /* @escapeNotVerified */ echo $block->getAddToWishlistParams($_product); ?>'
  155.                                        class="action towishlist" data-action="add-to-wishlist"
  156.                                        title="<?php /* @escapeNotVerified */ echo __('Add to Wish List') ?>">
  157.                                         <span><?php /* @escapeNotVerified */ echo __('Add to Wish List') ?></span>
  158.                                     </a>
  159.                                 <?php endif; ?>
  160.                                 <?php if ($block->getAddToCompareUrl()) ?>
  161.                                     <?php $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');?>
  162.                                     <a href="#" class="action tocompare"
  163.                                        data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($_product);?>'
  164.                                        title="<?php /* @escapeNotVerified */ echo __('Add to Compare') ?>">
  165.                                         <span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span>
  166.                                     </a>
  167.                                 <?php endif; ?>
  168.                             </div>
  169.                         </div>
  170.                     </div>-->
  171.                 </div>
  172.                 <?php echo($iterator == count($productCollection)+1) ? '</div></li>' : '' ?>
  173.                 <?php endforeach ?>
  174.             </ul>
  175.         </div>
  176.     </div>
  177. </div>
  178.  
  179. <?php if (!$block->isRedirectToCartEnabled()) : ?>
  180. <script type="text/x-magento-init">
  181.     {
  182.         "[data-role=tocart-form], .form.map.checkout": {
  183.             "catalogAddToCart": {}
  184.         }
  185.     }
  186. </script>
  187. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement