Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1cc scoupon bug #429

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions includes/api/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,27 @@ function addMagicCheckoutSettingFields(&$defaultFormFields)
'label' => __('Allow customers to create store Account'),
'default' => 'No',
),
'enable_dual_checkout_oncart' => array(
'title' => __('Activate Dual checkout on cart'),
'type' => 'checkbox',
'description' => "Activate Dual checkout on cart page",
'label' => __('Activate Dual checkout on cart'),
'default' => 'yes',
),
'enable_dual_checkout_onpdp' => array(
'title' => __('Activate Dual checkout on Buynow'),
'type' => 'checkbox',
'description' => "Activate Dual checkout on Product description Page",
'label' => __('Activate Dual checkout on Buynow'),
'default' => 'yes',
),
'enable_dual_checkout_minicart' => array(
'title' => __('Activate Dual checkout on minicart'),
'type' => 'checkbox',
'description' => 'Activate Dual checkout on minicart',
'label' => __('Activate Dual checkout on minicart'),
'default' => 'yes',
),
);

$defaultFormFields = array_merge($defaultFormFields, $magicCheckoutConfigFields);
Expand Down
147 changes: 134 additions & 13 deletions includes/api/coupon-get.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ function getCouponList($request)
);

//check woo-discount-rule plugin disabling the coupons
if (is_plugin_active('woo-discount-rules/woo-discount-rules.php')) {
$discountOptions = get_option('woo-discount-config-v2', []);
if (!empty($discountOptions)) {
$isCouponEnabled = $discountOptions['disable_coupon_when_rule_applied'];
if ($isCouponEnabled == 'disable_coupon') {
$args = array();
}
}
}
// if (is_plugin_active('woo-discount-rules/woo-discount-rules.php')) {
// $discountOptions = get_option('woo-discount-config-v2', []);
// if (!empty($discountOptions)) {
// $isCouponEnabled = $discountOptions['disable_coupon_when_rule_applied'];
// if ($isCouponEnabled == 'disable_coupon') {
// $args = array();
// }
// }
// }

$coupons = new WP_Query($args);

Expand Down Expand Up @@ -229,14 +229,27 @@ function getCouponList($request)
// Cleanup cart.
WC()->cart->empty_cart();
create1ccCart($orderId);
$smartCoupon = new Wt_Smart_Coupon_Public(" ", " ");

// if(class_exists('Wt_Smart_Coupon_Restriction_Public')){
// $items = WC()->cart->get_cart();
// $quantityMatchingProduct = get_quantity_of_product($coupon, $items,[], []);
// $subtotalMatchingProduct = get_sub_total_of_products($coupon, $items, [], []);

// }else{
// $smartCoupon = new Wt_Smart_Coupon_Public(" ", " ");
// $quantityMatchingProduct = $smartCoupon->get_quantity_of_matching_product($coupon);
// $subtotalMatchingProduct = $smartCoupon->get_sub_total_of_matching_products($coupon);

// }

$items = WC()->cart->get_cart();

// Quantity of matching Products
$minMatchingProductQty = get_post_meta($coupon->get_id(), '_wt_min_matching_product_qty', true);
$maxMatchingProductQty = get_post_meta($coupon->get_id(), '_wt_max_matching_product_qty', true);

if ($minMatchingProductQty > 0 || $maxMatchingProductQty > 0) {
$quantityMatchingProduct = $smartCoupon->get_quantity_of_matching_product($coupon);
$quantityMatchingProduct = get_quantity_of_product($coupon, $items,[], []);
if ($minMatchingProductQty > 0 && $quantityMatchingProduct < $minMatchingProductQty) {
continue;
}
Expand All @@ -245,12 +258,12 @@ function getCouponList($request)
}
}

// Subtotal of matching products
//Subtotal of matching products
$minMatchingProductSubtotal = get_post_meta($coupon->get_id(), '_wt_min_matching_product_subtotal', true);
$maxMatchingProductSubtotal = get_post_meta($coupon->get_id(), '_wt_max_matching_product_subtotal', true);

if ($minMatchingProductSubtotal !== 0 || $maxMatchingProductSubtotal !== 0) {
$subtotalMatchingProduct = $smartCoupon->get_sub_total_of_matching_products($coupon);
$subtotalMatchingProduct = get_sub_total_of_products($coupon, $items, [], []);
if ($minMatchingProductSubtotal > 0 && $subtotalMatchingProduct < $minMatchingProductSubtotal) {
continue;
}
Expand Down Expand Up @@ -305,3 +318,111 @@ function transformAmountForRzp($amount)
{
return wc_format_decimal($amount, 2) * 100;
}

function get_quantity_of_product($coupon, $items, $couponProducts, $couponCategories, $couponExcludeProducts = array(), $couponExcludeCategories = array())
{
global $woocommerce;
$qty = 0;

$isProductRestrictionEnabled=count($couponProducts)>0;
$isCategoryRestrictionEnabled=count($couponCategories)>0;

foreach($items as $item)
{
if(isset($item['free_product']) && "wt_give_away_product"===$item['free_product'])
{
continue;
}

$itemQuantity=0; //always reset to zero on loop start

if($isProductRestrictionEnabled)
{
if(in_array($item['product_id'], $couponProducts) || in_array($item['variation_id'], $couponProducts))
{
$itemQuantity = $item['quantity'];
}
}

if(0===$itemQuantity && $isCategoryRestrictionEnabled) /* not already in coupon products and category restriction enabled */
{
$productCats = wc_get_product_cat_ids($item['product_id']);

if(count(array_intersect($couponCategories, $productCats))>0)
{
if(0 === count(array_intersect($couponExcludeCategories, $productCats)))
{
$itemQuantity = $item['quantity'];
}
}
}


if(!$isProductRestrictionEnabled && !$isCategoryRestrictionEnabled)
{
$productCats = wc_get_product_cat_ids($item['product_id']);

if(!empty($couponExcludeCategories) || !empty($couponExcludeProducts))
{

if(in_array($item['product_id'], $couponExcludeProducts) || in_array($item['variation_id'], $couponExcludeProducts))
{
continue;

}elseif(0 < count(array_intersect($couponExcludeCategories, $productCats)))
{
continue;
}else
{
//not included in excluded product/category
$itemQuantity = $item['quantity'];
}

}else
{
$itemQuantity = $item['quantity'];
}

}

$qty += $itemQuantity;
}

return $qty;
}

function get_sub_total_of_products($coupon,$items, $couponProducts, $couponCategories)
{
global $woocommerce;
$total = 0;

$isProductRestrictionEnabled=count($couponProducts)>0;
$isCategoryRestrictionEnabled=count($couponCategories)>0;

if($isProductRestrictionEnabled || $isCategoryRestrictionEnabled) // check with matching products by include condition.
{
foreach($items as $item)
{
if(isset($item['free_product']) && "wt_give_away_product" === $item['free_product'])
{
continue;
}

$productCats = wc_get_product_cat_ids($item['product_id']);

if(($isProductRestrictionEnabled && in_array($item['product_id'], $couponProducts)) || ($isCategoryRestrictionEnabled && count(array_intersect($couponCategories,$productCats)) > 0))
{
$total += (float) $item['data']->get_price() * (int) $item['quantity'];
}
}

}else
{
foreach( $items as $item )
{
$total += (float) $item['data']->get_price() * (int) $item['quantity'];
}
}

return $total;
}
13 changes: 13 additions & 0 deletions includes/stylehandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
function styleHandler($theme){

$theme = strtolower(str_replace(' ', '', $theme));
$defaultStyle = plugin_dir_url(__DIR__) . 'public/css/1cc-product-checkout.css';
$cssFilePath = plugin_dir_path( __DIR__ ). '/public/css/'. $theme .'.css';
$css = plugin_dir_url(__DIR__) . 'public/css/'. $theme .'.css';

return is_file($cssFilePath)?
$css
:$defaultStyle;
}
?>
25 changes: 25 additions & 0 deletions includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,31 @@ function isMandatoryAccCreationEnabled()
&& 'yes' == get_option('woocommerce_razorpay_settings')['1cc_account_creation']
);
}

function isDualMiniCartCheckoutEnabled()
{
return (
empty(get_option('woocommerce_razorpay_settings')['enable_dual_checkout_minicart']) === false
&& 'yes' == get_option('woocommerce_razorpay_settings')['enable_dual_checkout_minicart']
);
}

function isDualPdpCheckoutEnabled()
{
return (
empty(get_option('woocommerce_razorpay_settings')['enable_dual_checkout_onpdp']) === false
&& 'yes' == get_option('woocommerce_razorpay_settings')['enable_dual_checkout_onpdp']
);
}

function isDualCartCheckoutEnabled()
{
return (
empty(get_option('woocommerce_razorpay_settings')['enable_dual_checkout_oncart']) === false
&& 'yes' == get_option('woocommerce_razorpay_settings')['enable_dual_checkout_oncart']
);
}

function validateInput($route, $param)
{
$failure_reason = null;
Expand Down
Empty file modified public/css/1cc-product-checkout.css
100644 → 100755
Empty file.
92 changes: 92 additions & 0 deletions public/css/astra.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#btn-1cc {
display: block !important;
width: 100%;
}
#btn-1cc-mini-cart {
display: block !important;
width: 100%;
}
#btn-1cc-pdp {
position: relative;
top: 10px;
display: block !important;
width: 220px;
border-radius: 2px;
overflow: hidden;
}
#rzp-spinner-backdrop {
position: fixed;
top: 0;
left: 0;
z-index: 9999;
width: 100%;
height: 100%;
background: rgba(0, 0, 0);
visibility: hidden;
opacity: 0;
}
#rzp-spinner-backdrop.show {
visibility: visible;
opacity: 0.4;
}
#rzp-spinner {
visibility: hidden;
opacity: 0;
/* positioning and centering */
position: fixed;
left: 0;
top: 0;
bottom: 0;
right: 0;
margin: auto;
z-index: 10000;
display: flex !important;
align-items: center;
justify-content: center;
}
#rzp-spinner.show {
visibility: visible;
opacity: 1;
}
@keyframes rotate {
0% {
transform: rotate(0);
}
100% {
transform: rotate(360deg);
}
}
#loading-indicator {
border-radius: 50%;
width: 80px;
height: 80px;
border: 4px solid;
border-color: rgb(59, 124, 245) transparent rgb(59, 124, 245) rgb(59, 124, 245) !important;
animation: 1s linear 0s infinite normal none running rotate;
margin-top: 2px;
box-sizing: content-box;
}
#icon {
position: absolute;
}
#rzp-logo{
width: auto;
height: 80px !important;
}
@media (max-device-height: 768px), (max-device-width: 768px) {
#loading-indicator {
width: 45px;
height: 45px;
}
#rzp-logo {
height: 45px !important;
}
}

.single_add_to_cart_button.button{
z-index: 2 !important;
}

.quantity{
z-index: 2 !important;
}
Loading