本文整理汇总了PHP中JeproshopContext::getShopContext方法的典型用法代码示例。如果您正苦于以下问题:PHP JeproshopContext::getShopContext方法的具体用法?PHP JeproshopContext::getShopContext怎么用?PHP JeproshopContext::getShopContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JeproshopContext
的用法示例。
在下文中一共展示了JeproshopContext::getShopContext方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCustomerCartRules
/**
* @static
* @param $lang_id
* @param $customer_id
* @param bool $published
* @param bool $includeGeneric
* @param bool $inStock
* @param JeproshopCartModelCart|null $cart
* @return array
*/
public static function getCustomerCartRules($lang_id, $customer_id, $published = false, $includeGeneric = true, $inStock = false, JeproshopCartModelCart $cart = null)
{
if (!JeproshopCartRuleModelCartRule::isFeaturePublished()) {
return array();
}
$db = JFactory::getDBO();
$query = "SELECT * FROM " . $db->quoteName('#__jeproshop_cart_rule') . " AS cart_rule LEFT JOIN " . $db->quoteName('#__jeproshop_cart_rule_lang');
$query .= " AS cart_rule_lang ON (cart_rule." . $db->quoteName('cart_rule_id') . " = cart_rule_lang." . $db->quoteName('cart_rule_id') . " AND ";
$query .= "cart_rule_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") WHERE ( cart_rule." . $db->quoteName('customer_id') . " = ";
$query .= (int) $customer_id . " OR cart_rule.group_restriction = 1 " . ($includeGeneric ? "OR cart_rule." . $db->quoteName('customer_id') . " = 0" : "");
$query .= ") AND cart_rule.date_from < \"" . date('Y-m-d H:i:s') . "\" AND cart_rule.date_to > \"" . date('Y-m-d H:i:s') . "\"";
$query .= ($published ? " AND cart_rule" . $db->quoteName('published') . " = 1" : "") . ($inStock ? " AND cart_rule." . $db->quoteName('quantity') . " > 0" : "");
$db->setQuery($query);
$result = $db->loadObjectList();
// Remove cart rule that does not match the customer groups
$customerGroups = JeproshopCustomerModelCustomer::getGroupsStatic($customer_id);
foreach ($result as $key => $cart_rule) {
if ($cart_rule->group_restriction) {
$query = "SELECT " . $db->quoteName('group_id') . " FROM " . $db->quoteName('#__jeproshop_cart_rule_group') . " WHERE " . $db->quoteName('cart_rule_id') . " = " . (int) $cart_rule->cart_rule_id;
$db->setQuery($query);
$cartRuleGroups = $db->loadObjectList();
foreach ($cartRuleGroups as $cartRuleGroup) {
if (in_array($cartRuleGroup->group_id, $customerGroups)) {
continue 2;
}
}
unset($result[$key]);
}
}
foreach ($result as &$cart_rule) {
if ($cart_rule->quantity_per_user) {
$quantity_used = JeproshopOrderModelOrder::getCustomerDiscounts((int) $customer_id, (int) $cart_rule->cart_rule_id);
if (isset($cart) && isset($cart->cart_id)) {
$quantity_used += $cart->getDiscountsCustomer((int) $cart_rule->cart_rule_id);
}
$cart_rule->quantity_for_user = $cart_rule->quantity_per_user - $quantity_used;
} else {
$cart_rule->quantity_for_user = 0;
}
}
unset($cart_rule);
foreach ($result as $cart_rule) {
if ($cart_rule->shop_restriction) {
$query = "SELECT shop_id FROM " . $db->quoteName('#__jeproshop_cart_rule_shop') . " WHERE cart_rule_id = " . (int) $cart_rule->cart_rule_id;
$db->setQuery($query);
$cartRuleShops = $db->loadObjectList();
foreach ($cartRuleShops as $cartRuleShop) {
if (JeproshopShopModelShop::isFeatureActive() && $cartRuleShop->shop_id == JeproshopContext::getShopContext()->shop->shop_id) {
continue 2;
}
}
unset($result[$key]);
}
}
// RetroCompatibility with 1.4 discounts
foreach ($result as &$cart_rule) {
$cart_rule->value = 0;
$cart_rule->minimal = JeproshopTools::convertPriceFull($cart_rule->minimum_amount, new JeproshopCurrencyModelCurrency($cart_rule->minimum_amount_currency), JeproshopContext::getContext()->currency);
$cart_rule->cumulable = !$cart_rule->cart_rule_restriction;
$cart_rule->discount_type_id = false;
if ($cart_rule->free_shipping) {
$cart_rule->discount_type_id = Discount::FREE_SHIPPING;
} elseif ($cart_rule->reduction_percent > 0) {
$cart_rule->discount_type_id = Discount::PERCENT;
$cart_rule->value = $cart_rule->reduction_percent;
} elseif ($cart_rule->reduction_amount > 0) {
$cart_rule->discount_type_id = Discount::AMOUNT;
$cart_rule->value = $cart_rule->reduction_amount;
}
}
return $result;
}