list.phtml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. use Magento\Framework\App\Action\Action;
  7. // @codingStandardsIgnoreFile
  8. ?>
  9. <?php
  10. /**
  11. * Product list template
  12. *
  13. * @var $block \Magento\Catalog\Block\Product\ListProduct
  14. */
  15. ?>
  16. <h1>Daily Deal Collection</h1>
  17. <?php
  18. $dailydealproductCollection = $block->getDailydealEnableProduct();
  19. $_helper = $this->helper('Magento\Catalog\Helper\Output');
  20. // Daily deal Helper
  21. $dailydealhelper=$this->helper('Smartwave\Dailydeals\Helper\Data');
  22. ?>
  23. <?php if (!$dailydealproductCollection->count()): ?>
  24. <div class="message info empty"><div><?php /* @escapeNotVerified */ echo __('We can\'t find products matching the selection.') ?></div></div>
  25. <?php else: ?>
  26. <?php //echo $block->getToolbarHtml() ?>
  27. <?php //echo $block->getAdditionalHtml() ?>
  28. <?php
  29. if ($block->getMode() == 'grid') {
  30. $viewMode = 'grid';
  31. $image = 'category_page_grid';
  32. $showDescription = false;
  33. $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
  34. } else {
  35. $viewMode = 'list';
  36. $image = 'category_page_list';
  37. $showDescription = true;
  38. $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::FULL_VIEW;
  39. }
  40. /**
  41. * Position for actions regarding image size changing in vde if needed
  42. */
  43. $pos = $block->getPositioned();
  44. ?>
  45. <div class="products wrapper <?php /* @escapeNotVerified */ echo $viewMode; ?> products-<?php /* @escapeNotVerified */ echo $viewMode; ?>">
  46. <?php $iterator = 1; ?>
  47. <ol class="products list items product-items" id="dailydealproduct">
  48. <!-- Loop for Fetch the product Sku from dailydeal collection -->
  49. <?php foreach($dailydealproductCollection as $dealproduct) : ?>
  50. <?php /** @var $_product \Magento\Catalog\Model\Product */ ?>
  51. <?php if($block->recentlyDailydeal($dealproduct->getSwProductSku())) : ?>
  52. <?php foreach ($block->getDailyDealProduct($dealproduct->getSwProductSku()) as $_product): ?>
  53. <?php /* @escapeNotVerified */ echo($iterator++ == 1) ? '<li class="item product product-item ">' : '</li><li class="item product product-item">' ?>
  54. <div class="product-item-info" data-container="product-grid">
  55. <?php
  56. $productImage = $block->getImage($_product, $image);
  57. if ($pos != null) {
  58. $position = ' style="left:' . $productImage->getWidth() . 'px;'
  59. . 'top:' . $productImage->getHeight() . 'px;"';
  60. }
  61. ?>
  62. <?php // Product Image ?>
  63. <a href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl().'?dailydealproduct=true' ?>" class="product photo product-item-photo" tabindex="-1">
  64. <?php echo $productImage->toHtml(); ?>
  65. </a>
  66. <div class="product details product-item-details">
  67. <?php
  68. $_productNameStripped = $block->stripTags($_product->getName(), null, true);
  69. ?>
  70. <strong class="product name product-item-name">
  71. <a class="product-item-link"
  72. href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl().'?dailydealproduct=true' ?>" >
  73. <?php /* @escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>
  74. </a>
  75. </strong>
  76. <?php echo $block->getReviewsSummaryHtml($_product, $templateType); ?>
  77. <?php echo "<div id='dailydeal' style='margin-top:5px; margin-bottom:5px;'>".$block->getProductPrice($_product)."</div>"; ?>
  78. <?php /* @escapeNotVerified */ ?>
  79. <?php echo $block->getProductDetailsHtml($_product); ?>
  80. <?php if($_product->getPrice() == 0) : ?>
  81. <?php if($_product->getTypeId() != "bundle" && $_product->getTypeId() != "grouped") : ?>
  82. <?php $_children = $_product->getTypeInstance()->getUsedProducts($_product);
  83. foreach ($_children as $child){
  84. $price=$child->getPrice();}
  85. ?>
  86. <?php endif; ?>
  87. <?php else: ?>
  88. <?php $price=$_product->getPrice(); ?>
  89. <?php endif;?>
  90. <?php if($_product->getTypeId() == "bundle" || $_product->getTypeId() == "grouped" ) : ?>
  91. <?php if($dealproduct->getSwDiscountType() ==1) :?>
  92. <div style="margin-top:20px; "><?php echo "<strong>Save: ".$dailydealhelper->getcurrencySymbol()."".number_format($dealproduct->getSwDiscountAmount(),2)."</strong>"; ?></div>
  93. <?php elseif($dealproduct->getSwDiscountType() ==2) : ?>
  94. <div style="margin-top:20px;"><strong>OFF:<?php echo number_format($dealproduct->getSwDiscountAmount(),2); ?>%</strong></div>
  95. <?php endif; ?>
  96. <?php else: ?>
  97. <!-- Show Save and Off value for non bundle Product -->
  98. <?php if($dealproduct->getSwDiscountType() ==1) :?>
  99. <?php $off=(($price-$dealproduct->getSwProductPrice())* 100)/ $price ; ?>
  100. <div style="float:right; margin-top:-20px;"><strong>OFF:<?php echo number_format($off,2); ?>%</strong></div>
  101. <div style="float:left; margin-top:-20px;"><strong>Save:<?php echo "" .$dailydealhelper->getcurrencySymbol()."".number_format($dealproduct->getSwDiscountAmount(),2); ?></strong></div>
  102. <?php elseif($dealproduct->getSwDiscountType() ==2) : ?>
  103. <div style="float:right; margin-top:-20px;"><?php echo "<strong>OFF: ".number_format($dealproduct->getSwDiscountAmount(),2)."%</strong>"; ?></div>
  104. <div style="float:left; margin-top:-20px; "><?php echo "<strong>Save: ".$dailydealhelper->getcurrencySymbol()."".number_format($price-$dealproduct->getSwProductPrice(),2)."</strong>"; ?></div>
  105. <?php endif; ?>
  106. <?php endif; ?>
  107. <input type="text" style="display: none" id="todate_<?php echo $iterator; ?>" value="<?php echo $dealproduct->getSwDateTo(); ?>" >
  108. <input type="text" style="display: none" id="fromdate_<?php echo $iterator; ?>" value="<?php echo $dealproduct->getSwDateFrom(); ?>">
  109. <input type="text" style="display: none" id="currentdate_<?php echo $iterator; ?>" value="<?php echo $dailydealhelper->getcurrentDate(); ?>" >
  110. <div class="sw-dailydeal">
  111. <div id="CDT">
  112. <p id="expired_<?php echo $iterator; ?>"></p>
  113. <div class="countdowncontainer_<?php echo $iterator; ?>" style="display:none;">
  114. <span class="dailydeal-label">
  115. <?php echo __('Ends In:'); ?>
  116. </span>
  117. <span class="number-wrapper">
  118. <div class="line"></div>
  119. <span class="number day"><p id="countdown_days_<?php echo $iterator; ?>">00</p></span>
  120. <div class="caption"><?php echo __('Day(s), '); ?></div>
  121. </span>
  122. <span class="number-wrapper">
  123. <div class="line"></div>
  124. <span class="number hour"><p id="countdown_hours_<?php echo $iterator; ?>">00</p></span>
  125. <div class="caption">:</div>
  126. </span>
  127. <span class="number-wrapper">
  128. <div class="line"></div>
  129. <span class="number min"><p id="countdown_minutes_<?php echo $iterator; ?>">00</p></span>
  130. <div class="caption">:</div>
  131. </span>
  132. <span class="number-wrapper">
  133. <div class="line"></div>
  134. <span class="number sec"><p id="countdown_seconds_<?php echo $iterator; ?>">00</p></span>
  135. <div class="caption"></div>
  136. </span>
  137. </div>
  138. </div>
  139. </div>
  140. <div class="product-item-inner">
  141. <div class="product actions product-item-actions"<?php echo strpos($pos, $viewMode . '-actions') ? $position : ''; ?>>
  142. <div class="actions-primary"<?php echo strpos($pos, $viewMode . '-primary') ? $position : ''; ?>>
  143. <?php if ($_product->isSaleable()): ?>
  144. <?php $postParams = $block->getAddToCartPostParams($_product); ?>
  145. <form data-role="tocart-form" action="<?php /* @escapeNotVerified */ echo $postParams['action']; ?>" method="post">
  146. <input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams['data']['product']; ?>">
  147. <input type="hidden" name="<?php /* @escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
  148. <?php echo $block->getBlockHtml('formkey')?>
  149. <button type="submit"
  150. title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
  151. class="action tocart primary">
  152. <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
  153. </button>
  154. </form>
  155. <?php else: ?>
  156. <?php if ($_product->getIsSalable()): ?>
  157. <div class="stock available"><span><?php /* @escapeNotVerified */ echo __('In stock') ?></span></div>
  158. <?php else: ?>
  159. <div class="stock unavailable"><span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span></div>
  160. <?php endif; ?>
  161. <?php endif; ?>
  162. </div>
  163. <div data-role="add-to-links" class="actions-secondary"<?php echo strpos($pos, $viewMode . '-secondary') ? $position : ''; ?>>
  164. <?php if ($addToBlock = $block->getChildBlock('addto')): ?>
  165. <?php echo $addToBlock->setProduct($_product)->getChildHtml(); ?>
  166. <?php endif; ?>
  167. </div>
  168. </div>
  169. <?php if ($showDescription):?>
  170. <div class="product description product-item-description">
  171. <?php /* @escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
  172. <a href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>" title="<?php /* @escapeNotVerified */ echo $_productNameStripped ?>"
  173. class="action more"><?php /* @escapeNotVerified */ echo __('Learn More') ?></a>
  174. </div>
  175. <?php endif; ?>
  176. </div>
  177. </div>
  178. </div>
  179. <?php echo($iterator == count($dailydealproductCollection)+1) ? '</li>' : '' ?>
  180. <?php endforeach; ?>
  181. <?php endif; ?>
  182. <?php endforeach; ?>
  183. </ol>
  184. </div>
  185. <?php echo $block->getToolbarHtml() ?>
  186. <?php if (!$block->isRedirectToCartEnabled()) : ?>
  187. <script type="text/x-magento-init">
  188. {
  189. "[data-role=tocart-form], .form.map.checkout": {
  190. "catalogAddToCart": {}
  191. }
  192. }
  193. </script>
  194. <?php endif; ?>
  195. <?php endif; ?>
  196. <script>
  197. // Timer for LEFT time for Dailydeal product
  198. var _second = 1000;
  199. var _minute = _second * 60;
  200. var _hour = _minute * 60;
  201. var _day = _hour * 24;
  202. var timer;
  203. <?php if(!isset($iterator))
  204. {
  205. $iterator=0;
  206. }
  207. ?>
  208. function showRemaining(currentdate)
  209. {
  210. var count;
  211. for (count = 2; count <= <?php echo $iterator; ?>; count++)
  212. {
  213. // get Value of dailydeal product
  214. var cid='countdown_'+count;
  215. var daysid='countdown_days_'+count;
  216. var hoursid='countdown_hours_'+count;
  217. var minutesid='countdown_minutes_'+count;
  218. var secondsid='countdown_seconds_'+count;
  219. var startdateid='fromdate_'+count;
  220. var id='todate_'+count;
  221. var enddate = new Date(jQuery('#'+id).val());
  222. var dealstartdate=new Date(jQuery('#'+startdateid).val());
  223. // Get Current Date from magentodatetime
  224. var currentdate=new Date(currentdate);
  225. //Get Difference between Two dates
  226. var distance = enddate - currentdate;
  227. if (distance < 0)
  228. {
  229. // clearInterval(timer);
  230. jQuery('#expired_'+count).html("<div class='offermessage'>EXPIRED!</div>");
  231. }
  232. else if(dealstartdate > currentdate)
  233. {
  234. jQuery('.countdowncontainer_'+count).hide();
  235. var msg="<div class='offermessage'> Coming Soon..<br>Deal Start at:<br>"+jQuery('#'+startdateid).val()+"<div>";
  236. jQuery('#expired_'+count).html(msg);
  237. }
  238. else
  239. {
  240. var days = Math.floor(distance / _day);
  241. var hours = Math.floor((distance % _day) / _hour);
  242. var minutes = Math.floor((distance % _hour) / _minute);
  243. var seconds = Math.floor((distance % _minute) / _second);
  244. // var difference='<strong>'+days + 'Days '+ hours + ':'+minutes + ':'+seconds + ' LEFT</strong>';
  245. jQuery('.countdowncontainer_'+count).show();
  246. jQuery('#'+daysid).html(days);
  247. jQuery('#'+hoursid).html(hours);
  248. jQuery('#'+minutesid).html(minutes);
  249. jQuery('#'+secondsid).html(seconds);
  250. // jQuery('#'+cid).html(timer);
  251. }
  252. }
  253. }
  254. //Set date as magentodatetime
  255. var date = new Date('<?php echo $dailydealhelper->getcurrentDate() ?>');
  256. var day = date.getDate();
  257. var month = date.getMonth();
  258. var year = date.getFullYear();
  259. var hours = date.getHours();
  260. var minutes = "0" + date.getMinutes();
  261. var seconds = "0" + date.getSeconds();
  262. var fulldate = year+'-'+(month+1)+'-'+day+' '+hours + ':' + minutes.substr(minutes.length-2) + ':' + seconds.substr(seconds.length-2);
  263. // Set Interval
  264. timer = setInterval(function()
  265. {
  266. date.setSeconds(date.getSeconds() + 1);
  267. var month=date.getMonth();
  268. var currentdatetime=date.getFullYear()+"-"+(month+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
  269. showRemaining(currentdatetime);
  270. }, 1000);
  271. </script>
  272. <style type="text/css">
  273. .page-layout-1column .toolbar-products {
  274. position: relative;
  275. display:none;
  276. }
  277. </style>