Skip to content

Commit

Permalink
Made Catalog Rules made compatible with new product types and updated…
Browse files Browse the repository at this point in the history
… issue templates
  • Loading branch information
prashant-webkul committed Oct 23, 2019
1 parent 02f0d00 commit 23237f9
Show file tree
Hide file tree
Showing 18 changed files with 262 additions and 197 deletions.
22 changes: 12 additions & 10 deletions .github/ISSUE_TEMPLATE/1_Bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,31 @@ about: 'Report a general library issue.'
# Bug report

### Title
**Just a quick sentence to brief your trouble with Bagisto or something associated with it.**

Please be calm, short and emaphasize on points.
**Just a quick sentence to brief your trouble with Bagisto or something associated with it.**
**Please be calm, short and emaphasize on points.**

### Issue Description
**Description helps the developers to understand the bug. It describes the problem encountered or some after effect of some kind.**
**Description helps the developers to understand the bug. It describes the problem encountered or some after effect of some kind.**

### Preconditions
**Please provide as detailed information about your environment as possible.**
**Please provide as detailed information about your environment as possible.**

1. framework Version.
2. Commit id.

### Steps to reproduce
**It is important to provide a set of clear steps to reproduce this bug.If relevant please include code samples.**
**It is important to provide a set of clear steps to reproduce this bug.If relevant please include code samples.**

1. step1
2. step2

### Expected result
**Tell us what should happen.**
* [Screenshots, logs or description]
**Tell us what should happen.**

* [Screenshots, logs or description]

### Actual result
**Tell us what happens instead.**
* [Tell us what happens instead]

> **Tell us what happens instead.**
* [points....]
11 changes: 8 additions & 3 deletions .github/ISSUE_TEMPLATE/2_Feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ name: "💡 Feature Request"
about: 'For ideas or feature requests, please make a pull request, or open an issue'
---

This repository is only for reporting bugs or issues. If you need support, please use the forums:
This repository is only for reporting bugs or issues. If you need support, please use
other channels:

- https://forums.bagisto.com/
1. Write an email - mailto:[email protected]

2. Create support ticket on https://bagisto.uvdesk.com

3. Visit forums to get support from our community (https://forums.bagisto.com)

Alternatively, you may use Facebook (https://www.facebook.com/groups/bagisto/).

We promise that more channels are coming soon!!!
We promise that more channels are coming soon!!!
6 changes: 1 addition & 5 deletions .github/ISSUE_TEMPLATE/3_Support_question.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ about: 'This repository is only for reporting bugs or problems. If you need help

This repository is only for reporting bugs or issues. If you need support, please use:

1. Write an email - mailto:[email protected]

2. Create support ticket on https://bagisto.uvdesk.com

3. Visit forums to get support from our community (https://forums.bagisto.com)
1. Create support ticket on https://bagisto.uvdesk.com

Thanks!
14 changes: 6 additions & 8 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
**BUGS:**

Please describe the issue that you solved if its not filed. Otherwise please mention issue #id and use comma
if your PR is having multiple fixes.
>Please describe the issue that you solved if its not filed.
**Core development ideas or discussion:**
>Otherwise please mention issue #id and use comma if your PR
>solves multiple issues.
Describe the feature in very short lines word usage limit is 200. Otherwise use **issue #id** if the issue was
filed as **feature** request.
**For things other than bugs:**

**Which branch you should target?**

You should fork the Bagisto repository and push your local changes to your own **development** branch. And after you are done then generate from your **development** branch to Bagisto's **master** branch. Use branches other than **master** if you are fixing any backward compatible issue.
> Describe that thing in very short line, word limit is 200.
> Otherwise use **issue #id** if the issue was filed as **feature** request.
16 changes: 9 additions & 7 deletions packages/Webkul/Admin/src/Config/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,15 @@
'route' => 'admin.cart-rule.index',
'sort' => 1,
'icon-class' => ''
], [
'key' => 'promotions.catalog-rule',
'name' => 'admin::app.promotion.catalog-rule',
'route' => 'admin.catalog-rule.index',
'sort' => 1,
'icon-class' => '',
], [
],
// , [
// 'key' => 'promotions.catalog-rule',
// 'name' => 'admin::app.promotion.catalog-rule',
// 'route' => 'admin.catalog-rule.index',
// 'sort' => 1,
// 'icon-class' => '',
// ],
[
'key' => 'cms',
'name' => 'admin::app.layouts.cms',
'route' => 'admin.cms.index',
Expand Down
2 changes: 1 addition & 1 deletion packages/Webkul/Checkout/src/Models/CartItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function child()
}

/**
* Get the children items.
* Get the item childrens.
*/
public function children()
{
Expand Down
38 changes: 0 additions & 38 deletions packages/Webkul/Discount/src/Actions/Action.php

This file was deleted.

112 changes: 112 additions & 0 deletions packages/Webkul/Discount/src/Actions/Cart/Action.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace Webkul\Discount\Actions\Cart;

abstract class Action
{
/**
* To hold the current rule
*/
protected $rule;

abstract public function calculate($rule);

/**
* Empty collection instance for keeping final list of items
*/
protected $matchedItems;

public function __construct()
{
/**
* Making $matchedItems property empty collection instance.
*/
$this->matchedItems = collect();
}

/**
* To find the eligble items for the current rule,
*
* @param CartRule $rule
*
* @return Collection $matchedItems
*/
public function getEligibleItems($rule)
{
$cart = \Cart::getCart();

$items = $cart->items()->get();

$productIDs = $rule->product_ids;

$productIDs = explode(',', $productIDs);

$matchCriteria = $rule->uses_attribute_conditions ? $rule->product_ids : '*';

if ($matchCriteria == '*') {
$this->matchedItems = $items;

return $this->matchedItems;
} else {
$matchingIDs = explode(',', $matchCriteria);

foreach ($items as $item) {
foreach ($matchingIDs as $matchingID) {
$childrens = collect();
$childrens = $item->children;

foreach ($childrens as $children) {
if ($children->product_id == $matchingID) {
$this->pushItem($children);
}
}

if ($item->product_id == $matchingID) {
$this->pushItem($item);
}
}
}

return $this->matchedItems;
}
}

/**
* To check the items applicability
*/
public function checkApplicability()
{
$rule = $this->rule;

$eligibleItems = $this->getEligibleItems($rule);

$apply = function () use($rule, $eligibleItems) {
if ($rule->action_type == 'percent_of_product') {
return true;
} else {
if ($rule->action_type == 'whole_cart_to_percent' && $rule->uses_attribute_condition) {
$matchIDs = explode(',', $rule->product_ids);

foreach ($matchIDs as $matchID) {
foreach ($eligibleItems as $item) {
if (($item->child ? $item->child->product_id : $item->product_id) == $matchID) {
return true;
}
}
}

return false;
} else {
return true;
}
}
};

return $apply();
}


private function pushItem($item) {
$this->matchedItems->push($item);
}
}
63 changes: 25 additions & 38 deletions packages/Webkul/Discount/src/Actions/Cart/FixedAmount.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,36 @@

namespace Webkul\Discount\Actions\Cart;

use Webkul\Discount\Actions\Action;
use Webkul\Discount\Actions\Cart\Action;

class FixedAmount extends Action
{
public function calculate($rule)
{
/**
* Setting the rule getting applied
*/
$this->rule = $rule;

$impact = collect();

$totalDiscount = 0;

$eligibleItems = $this->getEligibleItems($rule);
$applicability = $this->checkApplicability();

$apply = function () use ($rule, $eligibleItems) {
if ($rule->action_type == 'fixed_amount') {
return true;
} else {
if ($rule->action_type == 'whole_cart_to_fixed' && $rule->uses_attribute_condition) {
$matchIDs = explode(',', $rule->product_ids);
if ($applicability) {
// if ($rule->action_type == 'whole_cart_to_fixed') {
// $eligibleItems = \Cart::getCart()->items;
// }

foreach ($matchIDs as $matchID) {
foreach ($eligibleItems as $item) {
if (($item->child ? $item->child->product_id : $item->product_id) == $matchID) {
return true;
}
}
}
$eligibleItems = \Cart::getCart()->items;

return false;
} else {
return true;
}
}
};
foreach ($eligibleItems as $item) {
$report = array();

if ($apply()) {
if ($rule->action_type == 'whole_cart_to_fixed')
{
$eligibleItems = \Cart::getCart()->items;
}
$report['item_id'] = $item->id;
$report['child_items'] = collect();

foreach ($eligibleItems as $item) {
$itemPrice = $item->base_price;

$itemQuantity = $item->quantity;
Expand All @@ -51,10 +40,6 @@ public function calculate($rule)

$discQuantity = $itemQuantity <= $discQuantity ? $itemQuantity : $discQuantity;

$report = array();

$report['item_id'] = $item->id;

if ($item->product->getTypeInstance()->isComposite()) {
$isQtyZero = true;

Expand All @@ -65,24 +50,26 @@ public function calculate($rule)
}

if ($isQtyZero) {
// case for configurable products
$report['product_id'] = $item->children->first()->product_id;

$report['child_items'] = collect();
} else {
// composites other than configurable
$report['product_id'] = $item->product_id;

$report['child_items'] = collect();

foreach ($item->children as $children) {
$children->discount = $rule->disc_amount;
$childBaseTotal = $children->base_total;

$itemDiscount = $childBaseTotal / (\Cart::getCart()->base_sub_total / 100);

$children->discount = ($itemDiscount / 100) * $rule->disc_amount;

$children->discount = $children->base_total > $children->discount ? $children->discount : $children->base_total;

$report['child_items']->push($children);
}
}
} else {
$report['product_id'] = $item->product_id;

$report['child_items'] = collect();
}

$discount = round($rule->disc_amount, 4) * $discQuantity;
Expand Down
Loading

0 comments on commit 23237f9

Please sign in to comment.