Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Magento\Framework\App\Action\Action;
- $title = $block->getData('title') ? $block->getData('title') : '';
- $subtitle = $block->getData('subtitle') ? $block->getData('subtitle') : '';
- $category_id = $block->getData('category_id');
- $_helper = $this->helper('Magento\Catalog\Helper\Output');
- $size = $block->getData('products_count');
- $productCollection = $this->getProductCollection($category_id, $size);
- $imageBlock = $block->getLayout()->createBlock('Magento\Catalog\Block\Product\ListProduct');
- $showCart = true;
- $type = 'widget-new-grid';
- $viewMode = 'grid';
- $image = 'category_page_grid';
- $pos = $block->getPositioned();
- //$showDescription = true;
- $showDescription = $block->getData('show_description');
- $bestSeller = $block->getBestSellerData();
- //$products_id = array();
- //$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
- /*foreach ($bestSeller as $product) {
- $products_id[] = $block->getParentProductId($product->getProductId());
- }
- $products_id = array_unique($products_id);
- var_dump($products_id);*/
- $month_ago = strtotime('-1 month');
- $bestseller_data = array();
- //echo '<br><br>test time: <br>';
- foreach ($bestSeller as $product) {
- $data = $product->getData();
- $d = new DateTime($data['period']);
- if($d->format('U') > $month_ago){
- //var_dump($product->getData());
- $parent_id = $block->getParentProductId($data['product_id']);
- if(!array_key_exists($parent_id, $bestseller_data)){
- $bestseller_data[$parent_id] = (int)$data['qty_ordered'];
- }else{
- $bestseller_data[$parent_id] += (int)$data['qty_ordered'];
- }
- //echo '<br>';
- }
- }
- arsort($bestseller_data);
- echo 'bestseller_data: <br>';
- var_dump($bestseller_data);
- $test_col = $block->loadProductsByIdAndCat(array_keys($bestseller_data), 3);
- echo 'collection: <br>';
- foreach ($test_col as $_p) {
- var_dump($_p->getData());
- echo '<br>';
- }
- ?>
- <div class="soundshocking_widget_product_list">
- <div class="title"><span><?php echo $title; ?></span></div>
- <div class="subtitle"><?php echo $subtitle; ?></div>
- <div class="products-grid">
- <div class="products list items product-items">
- <ul class="product-items">
- <?php $iterator = 1; ?>
- <?php //foreach ($products_id as $product): ?>
- <?php //foreach ($bestseller_data as $key => $value): ?>
- <?php //$_product = $block->getLoadProduct($key) ?>
- <?php foreach ($test_col as $_product): ?>
- <?php $productImage = $imageBlock->getImage($_product, 'category_page_grid');
- if ($pos == null) {
- $position = ' style="left:' . $productImage->getWidth() . 'px;'
- . 'top:' . $productImage->getHeight() . 'px;"';
- }
- ?>
- <?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">' ?>
- <a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $productImage->toHtml() ?></a>
- <div class="product details product-item-details">
- <div class="pl-bestseller-count tooltip-pl">
- <div class="pl-heart"></div>
- <div class="pl-count"><?php /*echo $value;*/ echo $bestseller_data[$_product->getId()] ?></div>
- <span class="tooltiptext tooltip-right">test</span>
- </div>
- <strong class="product name product-item-name">
- <a class="product-item-link" href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>">
- <?php /* @escapeNotVerified */ echo $_product->getName(); ?>
- </a>
- </strong>
- <?php if ($showCart): ?>
- <?php if($showDescription == 1): ?>
- <div class="description">
- <?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
- </div>
- <?php endif ?>
- <?php //echo $this->getProductPricetoHtml($_product, $type); ?>
- <?php echo $block->getProductDetailsHtml($_product); ?>
- <div id="price_and_cart">
- <?php echo $this->getProductPricetoHtml($_product, $type); ?>
- <?php if ($_product->isSaleable()): ?>
- <?php $postParams = $block->getAddToCartPostParams($_product); ?>
- <form data-role="tocart-form" action="<?php /* @escapeNotVerified */ echo $postParams['action']; ?>" method="post">
- <input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams['data']['product']; ?>">
- <input type="hidden" name="<?php /* @escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
- <?php echo $block->getBlockHtml('formkey')?>
- <button type="submit"
- title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
- class="tocart_category_view">
- <?php /* @escapeNotVerified */ echo __('Add to Cart') ?>
- </button>
- </form>
- <?php else: ?>
- <?php if ($_product->getIsSalable()): ?>
- <div class="stock available"><span><?php /* @escapeNotVerified */ echo __('In stock') ?></span></div>
- <?php else: ?>
- <div class="stock unavailable" title="Out of Stock"><span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span></div>
- <?php endif; ?>
- <?php endif; ?>
- </div>
- <!--<div class="product-item-inner">
- <div class="product actions product-item-actions">
- <div class="actions-primary"<?php echo strpos($pos, $viewMode . '-primary') ? $position : ''; ?>>
- <?php if ($_product->isSaleable()): ?>
- <?php $postParams = $block->getAddToCartPostParams($_product); ?>
- <form data-role="tocart-form" action="<?php /* @escapeNotVerified */ echo $postParams['action']; ?>" method="post">
- <input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams['data']['product']; ?>">
- <input type="hidden" name="<?php /* @escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
- <?php echo $block->getBlockHtml('formkey')?>
- <button type="submit"
- title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
- class="action tocart primary">
- <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
- </button>
- </form>
- <?php else: ?>
- <?php if ($_product->getIsSalable()): ?>
- <div class="stock available"><span><?php /* @escapeNotVerified */ echo __('In stock') ?></span></div>
- <?php else: ?>
- <div class="stock unavailable"><span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span></div>
- <?php endif; ?>
- <?php endif; ?>
- </div>
- <div class="actions-secondary" data-role="add-to-links">
- <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
- <a href="#"
- data-post='<?php /* @escapeNotVerified */ echo $block->getAddToWishlistParams($_product); ?>'
- class="action towishlist" data-action="add-to-wishlist"
- title="<?php /* @escapeNotVerified */ echo __('Add to Wish List') ?>">
- <span><?php /* @escapeNotVerified */ echo __('Add to Wish List') ?></span>
- </a>
- <?php endif; ?>
- <?php if ($block->getAddToCompareUrl()) ?>
- <?php $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');?>
- <a href="#" class="action tocompare"
- data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($_product);?>'
- title="<?php /* @escapeNotVerified */ echo __('Add to Compare') ?>">
- <span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span>
- </a>
- <?php endif; ?>
- </div>
- </div>
- </div>-->
- </div>
- <?php echo($iterator == count($productCollection)+1) ? '</div></li>' : '' ?>
- <?php endforeach ?>
- </ul>
- </div>
- </div>
- </div>
- <?php if (!$block->isRedirectToCartEnabled()) : ?>
- <script type="text/x-magento-init">
- {
- "[data-role=tocart-form], .form.map.checkout": {
- "catalogAddToCart": {}
- }
- }
- </script>
- <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement