Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
haitv282 committed Oct 13, 2020
1 parent e170130 commit f0a038e
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 112 deletions.
68 changes: 34 additions & 34 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
---
name: Bug report
about: Technical issue with the extension
labels: 'Issue'

---

<!---
Fields marked with (*) are required. Please don't remove the template.
-->

### Preconditions (*)
<!---
Provide the exact Magento version (example: 2.4.0) and any important information on the environment where bug is reproducible.
-->
1.
2.

### Steps to reproduce (*)
<!---
Important: Provide a set of clear steps to reproduce this bug. We can not provide support without clear instructions on how to reproduce.
-->
1.
2.

### Expected result (*)
<!--- Tell us what do you expect to happen. -->
1. [Screenshots, logs or description]
2.

### Actual result (*)
<!--- Tell us what happened instead. Include error messages and issues. -->
1. [Screenshots, logs or description]
2.
---
name: Bug report
about: Technical issue with the extension
labels: 'Issue'

---

<!---
Fields marked with (*) are required. Please don't remove the template.
-->

### Preconditions (*)
<!---
Provide the exact Magento version (example: 2.4.0) and any important information on the environment where bug is reproducible.
-->
1.
2.

### Steps to reproduce (*)
<!---
Important: Provide a set of clear steps to reproduce this bug. We can not provide support without clear instructions on how to reproduce.
-->
1.
2.

### Expected result (*)
<!--- Tell us what do you expect to happen. -->
1. [Screenshots, logs or description]
2.

### Actual result (*)
<!--- Tell us what happened instead. Include error messages and issues. -->
1. [Screenshots, logs or description]
2.
38 changes: 19 additions & 19 deletions .github/ISSUE_TEMPLATE/developer-experience-issue.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
name: Developer experience issue
about: Issues related to customization, extensibility, modularity
labels: 'Experience'

---

<!---
Fields marked with (*) are required. Please don't remove the template.
-->

### Summary (*)
<!--- Describe the issue you are experiencing. Include general information, error messages, environments, and so on. -->

### Examples (*)
<!--- Provide code examples or a patch with a test (recommended) to clearly indicate the problem. -->

### Proposed solution
<!--- Suggest your potential solutions for this issue. -->
---
name: Developer experience issue
about: Issues related to customization, extensibility, modularity
labels: 'Experience'

---

<!---
Fields marked with (*) are required. Please don't remove the template.
-->

### Summary (*)
<!--- Describe the issue you are experiencing. Include general information, error messages, environments, and so on. -->

### Examples (*)
<!--- Provide code examples or a patch with a test (recommended) to clearly indicate the problem. -->

### Proposed solution
<!--- Suggest your potential solutions for this issue. -->
44 changes: 22 additions & 22 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
---
name: Feature request
about: Request feature for development
labels: 'Feature Request'

---

<!---
Fields marked with (*) are required. Please don't remove the template.
-->

### Description (*)
<!--- Describe the feature you would like to add. -->

### Expected behavior (*)
<!--- What is the expected behavior of this feature? How is it going to work? -->

### Benefits
<!--- How do you think this feature would improve the extension? -->

### Additional information
<!--- What other information can you provide about the desired feature? -->
---
name: Feature request
about: Request feature for development
labels: 'Feature Request'

---

<!---
Fields marked with (*) are required. Please don't remove the template.
-->

### Description (*)
<!--- Describe the feature you would like to add. -->

### Expected behavior (*)
<!--- What is the expected behavior of this feature? How is it going to work? -->

### Benefits
<!--- How do you think this feature would improve the extension? -->

### Additional information
<!--- What other information can you provide about the desired feature? -->
6 changes: 3 additions & 3 deletions Block/AbstractSlider.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ private function getPriceCurrency()
$this->priceCurrency = ObjectManager::getInstance()
->get(PriceCurrencyInterface::class);
}

return $this->priceCurrency;
}

Expand Down Expand Up @@ -234,10 +235,10 @@ public function getProductPriceHtml(
if (!isset($arguments['zone'])) {
$arguments['zone'] = $renderZone;
}
$arguments['price_id'] = isset($arguments['price_id'])
$arguments['price_id'] = isset($arguments['price_id'])
? $arguments['price_id']
: 'old-price-' . $product->getId() . '-' . $priceType;
$arguments['include_container'] = isset($arguments['include_container'])
$arguments['include_container'] = isset($arguments['include_container'])
? $arguments['include_container']
: true;
$arguments['display_minimal_price'] = isset($arguments['display_minimal_price'])
Expand All @@ -261,7 +262,6 @@ public function getProductPriceHtml(
);
}


/**
* @return bool
*/
Expand Down
20 changes: 9 additions & 11 deletions Block/OnSaleProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class OnSaleProduct extends AbstractSlider

/**
* OnSaleProduct constructor.
*
* @param Context $context
* @param CollectionFactory $productCollectionFactory
* @param Visibility $catalogProductVisibility
Expand All @@ -60,8 +61,7 @@ public function __construct(
HttpContext $httpContext,
EncoderInterface $urlEncoder,
array $data = []
)
{
) {
$this->_dateTimeStore = $dateTime;
parent::__construct(
$context,
Expand All @@ -80,15 +80,15 @@ public function __construct(
*/
public function getProductCollection()
{
$date = strtotime($this->_dateTimeStore->gmtDate());
$collection = $this->_productCollectionFactory->create()->addAttributeToSelect('*');
$date = strtotime($this->_dateTimeStore->gmtDate());
$collection = $this->_productCollectionFactory->create()->addAttributeToSelect('*');
$productIds = [];

foreach ($collection as $product) {
if ($product->getTypeId() === 'configurable' && $product->getVisibility() != 1) {
$_children = $product->getTypeInstance()->getUsedProducts($product);
foreach ($_children as $child){
$specialPrice = (float)$child->getSpecialPrice();
foreach ($_children as $child) {
$specialPrice = (float) $child->getSpecialPrice();
if ($specialPrice) {
if ($specialPrice < ((float) $child->getPrice())) {
$fromDate = strtotime($child->getSpecialFromDate());
Expand All @@ -97,17 +97,16 @@ public function getProductCollection()
if ($toDate > $date) {
$productIds[] = $product->getId();
}
}else {
} else {
if ($fromDate < $date) {
$productIds[] = $product->getId();
}
}
}
}
}

} elseif ($product->getTypeId() === 'simple' && $product->getVisibility() != 1) {
$specialPriceSp = (float)$product->getData('special_price');
$specialPriceSp = (float) $product->getData('special_price');
if ($specialPriceSp) {
if ($specialPriceSp < ((float) $product->getPrice())) {
$fromDateSp = strtotime($product->getSpecialFromDate());
Expand All @@ -116,7 +115,7 @@ public function getProductCollection()
if ($toDateSp > $date) {
$productIds[] = $product->getId();
}
}else {
} else {
if ($fromDateSp < $date) {
$productIds[] = $product->getId();
}
Expand All @@ -133,7 +132,6 @@ public function getProductCollection()
->addAttributeToSelect('*')
->addStoreFilter($this->getStoreId())->setPageSize($this->getProductsCount());


return $collectionClone;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"mageplaza/module-core": "^1.4.5"
},
"type": "magento2-module",
"version": "2.0.7",
"version": "2.0.8",
"license": "proprietary",
"authors": [
{
Expand Down
22 changes: 11 additions & 11 deletions view/frontend/templates/productslider.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $type = 'widget-product-grid';
$title = $block->getTitle();
$blockId = $block->getSliderId() . uniqid('-', false);
$items = $block->getProductCollection();
if ($items && $items->getSize()) : ?>
if ($items && $items->getSize()): ?>
<div class="mp-product-slider-block block widget block-products-list <?= /** @noEscape */ $mode ?>">
<h2 class="mp-product-slider-title"><?= $block->escapeHtml($title) ?></h2>
<p class="mp-ps-info"><?= $block->escapeHtml($block->getDescription()) ?></p>
Expand All @@ -38,7 +38,7 @@ if ($items && $items->getSize()) : ?>
<ol class="product-items widget-viewed-grid">
<?php $iterator = 1; ?>
<div id="mp-list-items-<?= /** @noEscape */ $blockId ?>" class="owl-carousel owl-theme">
<?php foreach ($items as $_item) : ?>
<?php foreach ($items as $_item): ?>
<?= ($iterator++ == 1) ? '<li class="product-item product-slider"">' : '</li><li class="product-item product-slider"">' ?>
<div class="slider-product-item-info">
<a href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>"
Expand All @@ -53,20 +53,20 @@ if ($items && $items->getSize()) : ?>
</a>
</strong>

<?php if ($block->canShowReview()) : ?>
<?php if ($block->canShowReview()): ?>
<?= $block->getReviewsSummaryHtml($_item, 'short', true) ?>
<?php endif; ?>

<?= /** @noEscape */ $block->getProductDetailsHtml($_item) ?>

<?php if ($block->canShowPrice()) : ?>
<?php if ($block->canShowPrice()): ?>
<?= /** @noEscape */ $block->getProductPriceHtml($_item, $type) ?>
<?php endif; ?>

<div class="product actions slider-product-item-actions product-item-actions">
<?php if ($block->canShowAddToCart()) : ?>
<?php if ($block->canShowAddToCart()): ?>
<div class="actions-primary">
<?php if ($_item->isSaleable()) : ?>
<?php if ($_item->isSaleable()): ?>
<?php $postParams = $block->getAddToCartPostParams($_item); ?>
<form data-role="tocart-form" data-product-sku="<?= $block->escapeHtml($_item->getSku()) ?>" action="<?= /* @NoEscape */ $postParams['action'] ?>" method="post">
<input type="hidden" name="product" value="<?= /* @escapeNotVerified */ $postParams['data']['product'] ?>">
Expand All @@ -78,25 +78,25 @@ if ($items && $items->getSize()) : ?>
<span><?= /** @noEscape */ __('Add to Cart') ?></span>
</button>
</form>
<?php else : ?>
<?php if ($_item->getIsSalable()) : ?>
<?php else: ?>
<?php if ($_item->getIsSalable()): ?>
<div class="stock available"><span><?= $block->escapeHtml(__('In stock')) ?></span></div>
<?php else : ?>
<?php else: ?>
<div class="stock unavailable"><span><?= $block->escapeHtml(__('Out of stock')) ?></span></div>
<?php endif; ?>
<?php endif; ?>
</div>
<div class="secondary-addto-links actions-secondary"
data-role="add-to-links">
<?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()) : ?>
<?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
<a href="#"
data-post='<?= /** @noEscape */ $block->getAddToWishlistParams($_item); ?>'
class="action towishlist" data-action="add-to-wishlist"
title="<?= /** @noEscape */ __('Add to Wish List') ?>">
<span><?= /** @noEscape */ __('Add to Wish List') ?></span>
</a>
<?php endif; ?>
<?php if ($block->getAddToCompareUrl()) : ?>
<?php if ($block->getAddToCompareUrl()): ?>
<?php $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare'); ?>
<a href="#" class="action tocompare"
data-post='<?= /** @noEscape */ $compareHelper->getPostDataParams($_item); ?>'
Expand Down
Loading

0 comments on commit f0a038e

Please sign in to comment.