Skip to content
Merged
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
3 changes: 3 additions & 0 deletions app/Constants/Hooks/CustomHookNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ class CustomHookNames
public const ECOMMERCE_PAYMENT_PROVIDERS = 'kirki_ecommerce_payment_providers';
public const USER_EMAIL_VERIFIED = 'kecom_user_email_verified';
public const CONFIG_DATA = 'kecom_config_data';
public const ACCOUNT_ROUTE_CONFIG = 'kecom_account_route_config';
public const ACCOUNT_MENU_ITEMS = 'kecom_account_menu_items';
public const SITE_PAGES = 'kecom_site_pages';
}
18 changes: 13 additions & 5 deletions app/Resources/Site/Shop/ShopProductResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function to_array(): array

$has_variants = (bool) $this->has_variants;
$variant_id = intval($variant->id);
$out_of_stock = $this->resolve_stock_status($variant_id);
$out_of_stock = ! $this->resolve_has_stock($variants);
$pricing = $this->resolve_pricing($variant, $variants, $has_variants);
$is_wishlisted = app(WishlistService::class)->is_wishlisted($variant_id);

Expand Down Expand Up @@ -138,15 +138,23 @@ private function resolve_variant_price_range($variants, $display_currency = null
}

/**
* Check whether the given variant is out of stock.
* Check any variant is in stock.
*
* @param int $variant_id
* @param Collection $variants variants.
*
* @return bool
*/
private function resolve_stock_status(int $variant_id): bool
private function resolve_has_stock(Collection $variants): bool
{
return ! app()->make(InventoryService::class)->has_stock($variant_id, 1);
$has_stock = false;
$inventory_service = app()->make(InventoryService::class);
foreach ($variants as $variant) {
if ($inventory_service->has_stock($variant->id, 1)) {
$has_stock = true;
break;
}
}
return $has_stock;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions app/Supports/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Kirki\Ecommerce\App\Supports;

use Kirki\Ecommerce\App\Constants\Hooks\CustomHookNames;
use Kirki\Ecommerce\App\Constants\Order\FulfillmentStatus;
use Kirki\Ecommerce\App\Constants\Order\PaymentStatus;
use Kirki\Ecommerce\App\Constants\PageKeys;
Expand Down Expand Up @@ -73,7 +74,7 @@ public static function get_site_pages()
$pages['advance.pages.' . $key] = $name;
}

$pages = apply_filters('kirki_ecommerce_site_pages', $pages);
$pages = apply_filters(CustomHookNames::SITE_PAGES, $pages);

return $pages;
}
Expand Down Expand Up @@ -167,7 +168,7 @@ public static function get_account_route_config()
],
];

$route_config = apply_filters('kirki_ecommerce_account_route_config', $route_config);
$route_config = apply_filters(CustomHookNames::ACCOUNT_ROUTE_CONFIG, $route_config);

return $route_config;
}
Expand All @@ -190,7 +191,7 @@ public static function get_account_menu_items()
}
}

$menu_items = apply_filters('kirki_ecommerce_account_menu_items', $menu_items);
$menu_items = apply_filters(CustomHookNames::ACCOUNT_MENU_ITEMS, $menu_items);

return $menu_items;
}
Expand Down
Loading