update multi_tenancy and current shop

This commit is contained in:
Thein Lin Kyaw
2020-01-13 16:35:57 +06:30
parent 66c375cc38
commit 3088aa3016
4 changed files with 13 additions and 21 deletions

View File

@@ -4,16 +4,18 @@ module MultiTenancy
included do
set_current_tenant_through_filter if respond_to? :set_current_tenant_through_filter
before_action :find_shop_by_subdomain_or_frist if respond_to? :before_action
helper_method :current_shop if respond_to? :helper_method
end
private
def find_shop_by_subdomain_or_frist
if request.subdomain.present?
shop_code = request.subdomain.partition('-').last
@shop = Shop.find_by(shop_code: shop_code)
else
@shop = Shop.first
if request.subdomains.last
set_current_tenant(Shop.find_by(shop_code: request.subdomains.last.partition('-').last))
end
set_current_tenant(@shop)
current_shop
end
def current_shop
@shop ||= Shop.current_shop
end
end