function hikashop_product_price_for_quantity_in_cart(&$product) { $currencyClass = hikashop_get('class.currency'); $quantity = @$product->cart_product_quantity; $plugin = JPluginHelper::getPlugin('system', 'custom_price'); if (version_compare(JVERSION, '2.5', '<')) { jimport('joomla.html.parameter'); $params = new JParameter($plugin->params); } else { $params = new JRegistry($plugin->params); } $taxes = $params->get('taxes', 0); $column = $params->get('field', 'amount'); if (!empty($product->{$column})) { if (empty($product->prices)) { $price = new stdClass(); $price->price_currency_id = hikashop_getCurrency(); $price->price_min_quantity = 1; $product->prices = array($price); } foreach ($product->prices as $k => $price) { if ($taxes && $product->product_type == 'variant' && empty($product->product_tax_id)) { $productClass = hikashop_get('class.product'); $main = $productClass->get($product->product_parent_id); $product->product_tax_id = $main->product_tax_id; } switch ($taxes) { case 2: $product->prices[$k]->price_value = $currencyClass->getUntaxedPrice($product->{$column}, hikashop_getZone(), $product->product_tax_id); $product->prices[$k]->taxes = $currencyClass->taxRates; $product->prices[$k]->price_value_with_tax = $product->{$column}; break; case 1: $product->prices[$k]->price_value = $product->{$column}; $product->prices[$k]->price_value_with_tax = $currencyClass->getTaxedPrice($product->{$column}, hikashop_getZone(), $product->product_tax_id); $product->prices[$k]->taxes = $currencyClass->taxRates; break; case 0: default: $product->prices[$k]->price_value = $product->{$column}; $product->prices[$k]->price_value_with_tax = $product->{$column}; break; } } } $currencyClass->quantityPrices($product->prices, $quantity, $product->cart_product_total_quantity); }
static function getCartSumm() { $config =& hikashop_config(); $main_currency = (int) $config->get('main_currency', 1); $zone_id = hikashop_getZone('shipping'); if ($config->get('tax_zone_type', 'shipping') == 'billing') { $tax_zone_id = hikashop_getZone('billing'); } else { $tax_zone_id = $zone_id; } $discount_before_tax = (int) $config->get('discount_before_tax', 0); $cart = hikashop_get('class.cart'); $cartInfo = $cart->loadCart(); $cart_id = $cartInfo->cart_id; if ($cart_id == 0) { return 0; } $products = $cart->get($cart_id); $total = null; $currencyClass = hikashop_get('class.currency'); $currency_id = hikashop_getCurrency(); $ids = array(); $mainIds = array(); foreach ($products as $product) { $ids[] = $product->product_id; } $currencyClass->getPrices($products, $ids, $currency_id, $main_currency, $tax_zone_id, $discount_before_tax); foreach ($products as $k => $row) { unset($products[$k]->cart_modified); unset($products[$k]->cart_coupon); $currencyClass->calculateProductPriceForQuantity($products[$k]); } $currencyClass->calculateTotal($products, $total, $currency_id); if (isset($total->prices) && isset($total->prices[0]) && isset($total->prices[0]->price_value) && !empty($total->prices[0]->price_value)) { $sum = $total->prices[0]->price_value; } else { $sum = 0; } return $sum; }
function &loadFullCart($additionalInfos = false, $keepEmptyCart = false, $skipChecks = false) { $app = JFactory::getApplication(); $database = JFactory::getDBO(); $config =& hikashop_config(); $currencyClass = hikashop_get('class.currency'); $productClass = hikashop_get('class.product'); $main_currency = (int) $config->get('main_currency', 1); $currency_id = hikashop_getCurrency(); if (!in_array($currency_id, $currencyClass->publishedCurrencies())) { $currency_id = $main_currency; } $zone_id = hikashop_getZone('shipping'); if ($config->get('tax_zone_type', 'shipping') == 'billing') { $tax_zone_id = hikashop_getZone('billing'); } else { $tax_zone_id = $zone_id; } $discount_before_tax = (int) $config->get('discount_before_tax', 0); $cart = new stdClass(); $cart->products = $this->get(@$this->cart->cart_id, $keepEmptyCart, isset($this->cart->cart_type) ? $this->cart->cart_type : ''); $cart->cart_id = (int) @$this->cart->cart_id; $cart->cart_type = @$this->cart->cart_type; $cart->cart_params = @$this->cart->cart_params; $cart->coupon = null; $cart->shipping = null; $cart->total = null; $cart->additional = array(); if (!empty($cart->products)) { $ids = array(); $mainIds = array(); foreach ($cart->products as $product) { $ids[] = $product->product_id; if ($product->product_parent_id == '0') { $mainIds[] = (int) $product->product_id; } else { $mainIds[] = (int) $product->product_parent_id; } } $query = 'SELECT a.*, b.* FROM ' . hikashop_table('product_category') . ' AS a LEFT JOIN ' . hikashop_table('category') . ' AS b ON a.category_id = b.category_id WHERE a.product_id IN(' . implode(',', $mainIds) . ') ORDER BY a.ordering ASC'; $database->setQuery($query); $categories = $database->loadObjectList(); $quantityDisplayType = hikashop_get('type.quantitydisplay'); foreach ($cart->products as $k => $row) { if ($row->product_parent_id != 0 && $row->cart_product_parent_id != '0') { $row->product_quantity_layout = $cart->products[$row->cart_product_parent_id]->product_quantity_layout; $row->product_min_per_order = $cart->products[$row->cart_product_parent_id]->product_min_per_order; $row->product_max_per_order = $cart->products[$row->cart_product_parent_id]->product_max_per_order; } if (empty($row->product_quantity_layout) || $row->product_quantity_layout == 'inherit') { $categoryQuantityLayout = ''; if (!empty($categories)) { foreach ($categories as $category) { if ($category->product_id == $row->product_id && !empty($category->category_quantity_layout) && $quantityDisplayType->check($category->category_quantity_layout, $app->getTemplate())) { $categoryQuantityLayout = $category->category_quantity_layout; break; } } } } if (!empty($row->product_quantity_layout) && $row->product_quantity_layout != 'inherit') { $qLayout = $row->product_quantity_layout; } elseif (!empty($categoryQuantityLayout) && $categoryQuantityLayout != 'inherit') { $qLayout = $categoryQuantityLayout; } else { $qLayout = $config->get('product_quantity_display', 'show_default'); } $cart->products[$k]->product_quantity_layout = $qLayout; } JArrayHelper::toInteger($ids); $query = 'SELECT * FROM ' . hikashop_table('file') . ' WHERE file_ref_id IN (' . implode(',', $ids) . ') AND file_type IN( \'product\',\'file\') ORDER BY file_ref_id ASC, file_ordering ASC'; $database->setQuery($query); $images = $database->loadObjectList(); if (!empty($images)) { foreach ($cart->products as $k => $row) { $productClass->addFiles($cart->products[$k], $images); } } foreach ($cart->products as $k => $row) { if ($row->product_type == 'variant') { foreach ($cart->products as $k2 => $row2) { if ($row->product_parent_id == $row2->product_id) { $cart->products[$k2]->variants[] =& $cart->products[$k]; break; } } } } $query = 'SELECT a.*,b.* FROM ' . hikashop_table('variant') . ' AS a LEFT JOIN ' . hikashop_table('characteristic') . ' AS b ON a.variant_characteristic_id=b.characteristic_id WHERE a.variant_product_id IN (' . implode(',', $ids) . ') ORDER BY a.ordering,b.characteristic_value'; $database->setQuery($query); $characteristics = $database->loadObjectList(); if (!empty($characteristics)) { foreach ($cart->products as $key => $product) { if ($product->product_type != 'variant') { $element =& $cart->products[$key]; $product_id = $product->product_id; $mainCharacteristics = array(); foreach ($characteristics as $characteristic) { if ($product_id == $characteristic->variant_product_id) { $mainCharacteristics[$product_id][$characteristic->characteristic_parent_id][$characteristic->characteristic_id] = $characteristic; } if (!empty($element->options)) { foreach ($element->options as $k => $optionElement) { if ($optionElement->product_id == $characteristic->variant_product_id) { $mainCharacteristics[$optionElement->product_id][$characteristic->characteristic_parent_id][$characteristic->characteristic_id] = $characteristic; } } } } JPluginHelper::importPlugin('hikashop'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onAfterProductCharacteristicsLoad', array(&$element, &$mainCharacteristics, &$characteristics)); if (!empty($element->variants)) { $this->addCharacteristics($element, $mainCharacteristics, $characteristics); } if (!empty($element->options)) { foreach ($element->options as $k => $optionElement) { if (!empty($optionElement->variants)) { $this->addCharacteristics($element->options[$k], $mainCharacteristics, $characteristics); } } } } } } $product_quantities = array(); foreach ($cart->products as $row) { if (empty($product_quantities[$row->product_id])) { $product_quantities[$row->product_id] = (int) @$row->cart_product_quantity; } else { $product_quantities[$row->product_id] += (int) @$row->cart_product_quantity; } if (empty($product_quantities[$row->product_parent_id])) { $product_quantities[$row->product_parent_id] = (int) @$row->cart_product_quantity; } else { $product_quantities[$row->product_parent_id] += (int) @$row->cart_product_quantity; } } foreach ($cart->products as $k => $row) { $cart->products[$k]->cart_product_total_quantity = $product_quantities[$row->product_id]; if ($row->product_parent_id) { $cart->products[$k]->cart_product_total_variants_quantity = $product_quantities[$row->product_parent_id]; } else { $cart->products[$k]->cart_product_total_variants_quantity = $cart->products[$k]->cart_product_total_quantity; } } $currencyClass->getPrices($cart->products, $ids, $currency_id, $main_currency, $tax_zone_id, $discount_before_tax); if ($additionalInfos) { $queryImage = 'SELECT * FROM ' . hikashop_table('file') . ' WHERE file_ref_id IN (' . implode(',', $ids) . ') AND file_type=\'product\' ORDER BY file_ref_id ASC, file_ordering ASC, file_id ASC'; $database->setQuery($queryImage); $images = $database->loadObjectList(); foreach ($cart->products as $k => $row) { if (!empty($images)) { foreach ($images as $image) { if ($row->product_id == $image->file_ref_id) { if (!isset($row->file_ref_id)) { foreach (get_object_vars($image) as $key => $name) { $cart->products[$k]->{$key} = $name; } } break; } } } if (!isset($cart->products[$k]->file_name)) { $cart->products[$k]->file_name = $row->product_name; } } } foreach ($cart->products as $k => $row) { if (!empty($row->variants)) { foreach ($row->variants as $k2 => $variant) { $productClass->checkVariant($cart->products[$k]->variants[$k2], $row); } } } $notUsable = array(); $cartData = $this->loadCart($cart->cart_id); if (!$skipChecks) { $cart->products = array_reverse($cart->products); foreach ($cart->products as $k => $product) { if (empty($product->product_id)) { continue; } if (!empty($product->cart_product_quantity)) { $oldQty = $product->cart_product_quantity; if (@$cartData->cart_type != 'wishlist') { $this->_checkQuantity($product, $product->cart_product_quantity, $cart->products, $product->cart_product_id); } if ($oldQty != $product->cart_product_quantity) { $notUsable[$product->cart_product_id] = 0; break; } if (!$config->get('display_add_to_cart_for_free_products', 0) && empty($product->prices)) { $notUsable[$product->cart_product_id] = 0; $app->enqueueMessage(JText::sprintf('PRODUCT_NOT_AVAILABLE', $product->product_name), 'notice'); continue; } if (empty($product->product_published)) { $notUsable[$product->cart_product_id] = 0; $app->enqueueMessage(JText::sprintf('PRODUCT_NOT_AVAILABLE', $product->product_name), 'notice'); continue; } if ($product->product_quantity != -1 && $product->product_quantity < $product->cart_product_quantity) { $notUsable[$product->cart_product_id] = 0; $app->enqueueMessage(JText::sprintf('NOT_ENOUGH_STOCK_FOR_PRODUCT', $product->product_name), 'notice'); continue; } if ($product->product_sale_start > time()) { $notUsable[$product->cart_product_id] = 0; $app->enqueueMessage(JText::sprintf('PRODUCT_NOT_YET_ON_SALE', $product->product_name), 'notice'); continue; } if (!empty($product->product_sale_end) && $product->product_sale_end < time()) { $notUsable[$product->cart_product_id] = 0; $app->enqueueMessage(JText::sprintf('PRODUCT_NOT_SOLD_ANYMORE', $product->product_name), 'notice'); continue; } } } $cart->products = array_reverse($cart->products); } if (!empty($notUsable)) { $this->update($notUsable, 1, 0, 'item'); return $this->loadFullCart($additionalInfos); } $cart->number_of_items = 0; $group = $config->get('group_options', 0); foreach ($cart->products as $k => $row) { unset($cart->products[$k]->cart_modified); unset($cart->products[$k]->cart_coupon); $currencyClass->calculateProductPriceForQuantity($cart->products[$k]); if (!$group || !$row->cart_product_option_parent_id) { $cart->number_of_items += $row->cart_product_quantity; } } $currencyClass->calculateTotal($cart->products, $cart->total, $currency_id); $cart->full_total =& $cart->total; JPluginHelper::importPlugin('hikashop'); JPluginHelper::importPlugin('hikashoppayment'); JPluginHelper::importPlugin('hikashopshipping'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onAfterCartProductsLoad', array(&$cart)); if (!empty($cart->additional)) { $currencyClass->addAdditionals($cart->additional, $cart->additional_total, $cart->full_total, $currency_id); $cart->full_total =& $cart->additional_total; } if (!empty($this->cart->cart_coupon) && $cart->cart_type != 'wishlist') { $discountClass = hikashop_get('class.discount'); $discountData = $discountClass->load($this->cart->cart_coupon); if (@$discountData->discount_auto_load) { $current_auto_coupon_key = $this->_generateHash($cart->products, $zone_id); $previous_auto_coupon_key = $app->getUserState(HIKASHOP_COMPONENT . '.auto_coupon_key'); if ($current_auto_coupon_key != $previous_auto_coupon_key) { $this->cart->cart_coupon = ''; } } } if (hikashop_level(1) && empty($this->cart->cart_coupon) && $cart->cart_type != 'wishlist') { $filters = array('discount_type=\'coupon\'', 'discount_published=1', 'discount_auto_load=1'); hikashop_addACLFilters($filters, 'discount_access'); $query = 'SELECT * FROM ' . hikashop_table('discount') . ' WHERE ' . implode(' AND ', $filters) . ' ORDER BY discount_minimum_order DESC, discount_minimum_products DESC'; $this->database->setQuery($query); $coupons = $this->database->loadObjectList(); if (!empty($coupons)) { $discountClass = hikashop_get('class.discount'); $zoneClass = hikashop_get('class.zone'); $zones = $zoneClass->getZoneParents($zone_id); foreach ($coupons as $coupon) { $result = $discountClass->check($coupon, $cart->total, $zones, $cart->products, false); if ($result) { $auto_coupon_key = $this->_generateHash($cart->products, $zone_id); $app->setUserState(HIKASHOP_COMPONENT . '.auto_coupon_key', $auto_coupon_key); $app->setUserState(HIKASHOP_COMPONENT . '.coupon_code', ''); $this->update($coupon->discount_code, 1, 0, 'coupon', true); if (empty($this->cart)) { $this->cart = new stdClass(); } $this->cart->cart_coupon = $coupon->discount_code; static $done = false; if ($done == false) { $done = true; return $this->loadFullCart($additionalInfos); } break; } } } } if (!empty($this->cart->cart_coupon) && $cart->cart_type != 'wishlist') { $zoneClass = hikashop_get('class.zone'); $zones = $zoneClass->getZoneParents($zone_id); $cart->coupon = $discountClass->loadAndCheck($this->cart->cart_coupon, $cart->full_total, $zones, $cart->products, true); if (empty($cart->coupon)) { if (!empty($this->cart)) { $this->cart->cart_coupon = ''; } } else { $cart->full_total =& $cart->coupon->total; } } if (hikashop_toFloat($cart->full_total->prices[0]->price_value_with_tax) <= 0) { $cart->full_total->prices[0]->price_value_with_tax = 0; $cart->full_total->prices[0]->price_value = 0; if (isset($cart->full_total->prices[0]->taxes)) { unset($cart->full_total->prices[0]->taxes); } } $shipping_id = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_id'); if (!empty($shipping_id)) { $cart->shipping = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_data'); if (!empty($cart->shipping)) { if (!is_array($cart->shipping)) { $cart->shipping = array($cart->shipping); } else { $shippings = array(); foreach ($cart->shipping as $method) { $group_key = $method->shipping_id; if (!empty($method->shipping_warehouse_id)) { $group_key .= '_'; if (is_array($method->shipping_warehouse_id)) { foreach ($method->shipping_warehouse_id as $key => $val) { $group_key .= $key . $val; } } else { $group_key .= $method->shipping_warehouse_id; } } $shippings[$group_key] = $method; } $cart->shipping = array_values($shippings); } $currencyClass = hikashop_get('class.currency'); $shipping =& $cart->shipping; $currencyClass->processShippings($shipping, $cart); $cart->full_total =& $currencyClass->addShipping($cart->shipping, $cart->full_total); } } $before_additional = !empty($cart->additional); $dispatcher->trigger('onAfterCartShippingLoad', array(&$cart)); if (!$before_additional && !empty($cart->additional)) { $currencyClass->addAdditionals($cart->additional, $cart->additional_total, $cart->full_total, $currency_id); $cart->full_total =& $cart->additional_total; } if (hikashop_toFloat($cart->full_total->prices[0]->price_value_with_tax) <= 0) { $cart->full_total->prices[0]->price_value_with_tax = 0; $cart->full_total->prices[0]->price_value = 0; if (isset($cart->full_total->prices[0]->taxes)) { unset($cart->full_total->prices[0]->taxes); } } $payment_id = $app->getUserState(HIKASHOP_COMPONENT . '.payment_id'); if (!empty($payment_id)) { $cart->payment = $app->getUserState(HIKASHOP_COMPONENT . '.payment_data'); if (!empty($cart->payment)) { $currencyClass = hikashop_get('class.currency'); $payment =& $cart->payment; $payments = array(&$payment); $currencyClass->processPayments($payments, $cart); $currencyClass->addPayment($cart->payment, $cart->full_total); $cart->full_total =& $cart->payment->total; } } if (hikashop_toFloat($cart->full_total->prices[0]->price_value_with_tax) <= 0) { $cart->full_total->prices[0]->price_value_with_tax = 0; $cart->full_total->prices[0]->price_value = 0; if (isset($cart->full_total->prices[0]->taxes)) { unset($cart->full_total->prices[0]->taxes); } } } if ($additionalInfos) { $app = JFactory::getApplication(); $shipping_address = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_address', 0); if (!empty($shipping_address)) { $this->loadAddress($cart, $shipping_address); } $billing_address = $app->getUserState(HIKASHOP_COMPONENT . '.billing_address', 0); if ($billing_address == $shipping_address) { $cart->billing_address =& $cart->shipping_address; } else { if (!empty($billing_address)) { $this->loadAddress($cart, $billing_address, 'parent', 'billing'); } } $this->calculateWeightAndVolume($cart); } if (!empty($cart->products) && isset($dispatcher)) { $dispatcher->trigger('onAfterFullCartLoad', array(&$cart)); } return $cart; }
function _loadResults($table_name, $switch_table, $ids, $columns = null) { $database = JFactory::getDBO(); $query = ''; JArrayHelper::toInteger($ids); if (!in_array($switch_table, array('characteristic'))) { foreach ($columns as $column) { hikashop_securefield($column); } } switch ($table_name) { case 'product': switch ($switch_table) { case 'price': $taxedPrice = false; $priceValue = false; foreach ($columns as $k => $column) { if ($column == 'price_value_with_tax') { unset($columns[$k]); $taxedPrice = true; } if ($column == 'price_value') { $priceValue = true; } } $addColumn = ''; if (!$priceValue && $taxedPrice) { if (count($columns) != 0) { $addColumn .= ', '; } $addColumn .= 'price_value'; } $query = 'SELECT ' . implode(',', $columns) . $addColumn . ', price_product_id, price_id'; $query .= ' FROM ' . hikashop_table('price'); $query .= ' WHERE price_product_id IN (' . implode(',', $ids) . ')'; $query .= ' ORDER BY price_id ASC'; if ($taxedPrice) { $productClass = hikashop_get('class.product'); $currencyHelper = hikashop_get('class.currency'); $productClass->getProducts($ids); $zone_id = hikashop_getZone(); $database->setQuery($query); $rows = $database->loadObjectList(); foreach ($rows as $k => $row) { if (isset($productClass->all_products[$row->price_product_id]) && $productClass->all_products[$row->price_product_id]->product_type == 'main') { $rows[$k]->price_value_with_tax = $currencyHelper->getTaxedPrice($row->price_value, $zone_id, $productClass->all_products[$row->price_product_id]->product_tax_id); } elseif (isset($productClass->all_products[$productClass->all_products[$row->price_product_id]->product_parent_id]->product_tax_id)) { $rows[$k]->price_value_with_tax = $currencyHelper->getTaxedPrice($row->price_value, $zone_id, $productClass->all_products[$productClass->all_products[$row->price_product_id]->product_parent_id]->product_tax_id); } else { $rows[$k]->price_value_with_tax = $rows[$k]->price_value; } if (!$priceValue) { unset($rows[$k]->price_value); } } $query = ''; return $rows; } break; case 'category': $query = 'SELECT c.' . implode(',c.', $columns) . ',pc.product_id,c.category_id'; $query .= ' FROM ' . hikashop_table('category') . ' AS c'; $query .= ' INNER JOIN ' . hikashop_table('product_category') . ' AS pc ON pc.category_id = c.category_id'; $query .= ' WHERE product_id IN (' . implode(',', $ids) . ')'; $query .= ' ORDER BY product_category_id'; break; case 'characteristic': $query = 'SELECT DISTINCT characteristic.characteristic_id,characteristic.characteristic_parent_id, characteristic.characteristic_value, variant.variant_product_id FROM ' . hikashop_table('characteristic') . ' AS characteristic '; $query .= ' LEFT JOIN ' . hikashop_table('variant') . ' AS variant ON characteristic.characteristic_id = variant.variant_characteristic_id'; $query .= ' WHERE variant_product_id IN (' . implode(',', $ids) . ')'; $query .= ' ORDER BY variant.ordering'; break; case 'related': $query = 'SELECT r.product_id ,p.product_id as \'related_id\',p.product_name, r.product_related_type'; $query .= ' FROM ' . hikashop_table('product_related') . ' AS r'; $query .= ' INNER JOIN ' . hikashop_table('product') . ' AS p ON r.product_related_id = p.product_id'; $query .= ' WHERE r.product_id IN (' . implode(',', $ids) . ')'; $query .= ' ORDER BY p.product_id ASC'; break; case 'files': $query = 'SELECT *'; $query .= ' FROM ' . hikashop_table('file'); $query .= ' WHERE file_ref_id IN (' . implode(',', $ids) . ') AND file_type = "file"'; $query .= ' ORDER BY file_ordering, file_ref_id ASC'; break; case 'images': $query = 'SELECT *'; $query .= ' FROM ' . hikashop_table('file'); $query .= ' WHERE file_ref_id IN (' . implode(',', $ids) . ') AND file_type = "product"'; $query .= ' ORDER BY file_ordering, file_ref_id ASC'; break; } break; case 'order': switch ($switch_table) { case 'order': $query = 'SELECT o.order_id,p.payment_name,p.payment_id,s.shipping_name,s.shipping_id'; $query .= ' FROM ' . hikashop_table('order') . ' as o'; $query .= ' LEFT JOIN ' . hikashop_table('shipping') . ' as s ON o.order_shipping_id = s.shipping_id'; $query .= ' LEFT JOIN ' . hikashop_table('payment') . ' as p ON o.order_payment_id = p.payment_id'; $query .= ' WHERE order_id IN (' . implode(',', $ids) . ')'; $query .= ' ORDER BY order_id ASC'; break; case 'order_product': $query = 'SELECT ' . implode(',', $columns) . ', order_product_id, order_id'; $query .= ' FROM ' . hikashop_table('order_product'); $query .= ' WHERE order_id IN (' . implode(',', $ids) . ')'; $query .= ' ORDER BY order_product_id ASC'; break; case 'address': foreach ($columns as $k => $column) { if (preg_match('#_state_#', $column)) { $columns[$k] = 'zone1.' . str_replace('_state', '', $column) . ' AS ' . $column; } elseif (preg_match('#_country_#', $column)) { $columns[$k] = 'zone2.' . str_replace('_country', '', $column) . ' AS ' . $column; } else { $columns[$k] = 'address.' . $column; } } $query = 'SELECT DISTINCT ' . implode(',', $columns) . ', address.address_id, order1.order_id'; $query .= ' FROM ' . hikashop_table('address') . ' AS address'; $query .= ' INNER JOIN ' . hikashop_table('order') . ' AS order1 ON address.address_id = order1.order_shipping_address_id OR address.address_id = order1.order_billing_address_id'; $query .= ' LEFT JOIN ' . hikashop_table('zone') . ' AS zone1 ON address.address_state = zone1.zone_namekey'; $query .= ' LEFT JOIN ' . hikashop_table('zone') . ' AS zone2 ON address.address_country = zone2.zone_namekey'; $query .= ' WHERE order1.order_id IN (' . implode(',', $ids) . ')'; $query .= ' ORDER BY address_id ASC'; break; case 'user': foreach ($columns as $k => $column) { $columns[$k] = 'user.' . $column; } $query = 'SELECT DISTINCT ' . implode(',', $columns) . ', user.user_id, user.user_cms_id'; $query .= ' FROM ' . hikashop_table('user') . ' AS user'; $query .= ' INNER JOIN ' . hikashop_table('order') . ' AS _order ON user.user_id = _order.order_user_id'; $query .= ' WHERE _order.order_id IN (' . implode(',', $ids) . ')'; $query .= ' ORDER BY user_id ASC'; break; case 'joomla_users': foreach ($columns as $k => $column) { $columns[$k] = 'user.' . $column; } $query = 'SELECT DISTINCT ' . implode(',', $columns) . ', user.id, hk_order.order_id'; $query .= ' FROM ' . hikashop_table('users', false) . ' AS user'; $query .= ' INNER JOIN ' . hikashop_table('user') . ' AS hk_user ON user.id = hk_user.user_cms_id'; $query .= ' INNER JOIN ' . hikashop_table('order') . ' AS hk_order ON hk_user.user_id = hk_order.order_user_id'; $query .= ' WHERE hk_order.order_id IN (' . implode(',', $ids) . ')'; $query .= ' ORDER BY id ASC'; break; } break; case 'user': switch ($switch_table) { case 'address': $query = 'SELECT ' . implode(',', $columns) . ', address_user_id, address_default, address_id'; $query .= ' FROM ' . hikashop_table('address'); $query .= ' WHERE address_user_id IN (' . implode(',', $ids) . ') AND address_published = 1'; $query .= ' ORDER BY address_default DESC, address_id DESC'; break; case 'joomla_users': foreach ($columns as $k => $column) { $columns[$k] = 'user.' . $column; } $query = 'SELECT DISTINCT ' . implode(',', $columns) . ', user.id as \'joomla_users_id\''; $query .= ' FROM ' . hikashop_table('users', false) . ' AS user'; $query .= ' INNER JOIN ' . hikashop_table('user') . ' AS hk_user ON user.id = hk_user.user_cms_id'; $query .= ' WHERE hk_user.user_id IN (' . implode(',', $ids) . ')'; $query .= ' ORDER BY id ASC'; break; case 'usergroups': $query = 'SELECT DISTINCT usergroups.title, hk_user.user_id, usergroups.id as \'usergroups_id\''; $query .= ' FROM ' . hikashop_table('usergroups', false) . ' AS usergroups'; $query .= ' INNER JOIN ' . hikashop_table('user_usergroup_map', false) . ' AS user_usergroup ON usergroups.id = user_usergroup.group_id'; $query .= ' INNER JOIN ' . hikashop_table('users', false) . ' AS user ON user.id = user_usergroup.user_id'; $query .= ' INNER JOIN ' . hikashop_table('user') . ' AS hk_user ON user.id = hk_user.user_cms_id'; $query .= ' WHERE hk_user.user_id IN (' . implode(',', $ids) . ')'; $query .= ' ORDER BY usergroups.id ASC'; break; } break; case 'address': switch ($switch_table) { case 'user': foreach ($columns as $k => $column) { $columns[$k] = 'user.' . $column; } $query = 'SELECT DISTINCT ' . implode(',', $columns) . ', user.user_id'; $query .= ' FROM ' . hikashop_table('user') . ' AS user'; $query .= ' INNER JOIN ' . hikashop_table('address') . ' AS address ON user.user_id = address.address_user_id'; $query .= ' WHERE address.address_id IN (' . implode(',', $ids) . ')'; $query .= ' ORDER BY user_id ASC'; break; case 'joomla_users': foreach ($columns as $k => $column) { $columns[$k] = 'user.' . $column; } $query = 'SELECT DISTINCT ' . implode(', ', $columns) . ', user.id as \'joomla_users_id\', hk_user.user_id'; $query .= ' FROM ' . hikashop_table('users', false) . ' AS user'; $query .= ' INNER JOIN ' . hikashop_table('user') . ' AS hk_user ON user.id = hk_user.user_cms_id'; $query .= ' INNER JOIN ' . hikashop_table('address') . ' AS address ON hk_user.user_id = address.address_user_id'; $query .= ' WHERE address.address_id IN (' . implode(',', $ids) . ')'; $query .= ' ORDER BY id ASC'; break; } break; } if (!empty($query)) { $database->setQuery($query); $rows = $database->loadObjectList(); return $rows; } }
function product_add($order_id = 0) { $config =& hikashop_config(); $currencyClass = hikashop_get('class.currency'); $classOrder = hikashop_get('class.order'); if ($order_id == 0) { $data = $this->_cleanOrder(); $product_ids = JRequest::getVar('cid', array(), '', 'array'); } else { $data = new stdClass(); $data->order_id = $order_id; $product_ids = JRequest::getVar('product_ids', array(), '', 'array'); } $quantities = JRequest::getVar('quantity', array(), '', 'array'); $rows = array(); if (!empty($product_ids)) { JArrayHelper::toInteger($product_ids); $database = JFactory::getDBO(); $query = 'SELECT * FROM ' . hikashop_table('product') . ' WHERE product_id IN (' . implode(',', $product_ids) . ')'; $database->setQuery($query); $rows = $database->loadObjectList(); } $user_id = 0; $main_currency = (int) $config->get('main_currency', 1); $discount_before_tax = (int) $config->get('discount_before_tax', 0); if (!empty($data->order_id)) { $orderData = $classOrder->get($data->order_id); $currency_id = $orderData->order_currency_id; $user_id = $orderData->order_user_id; } else { $currency_id = hikashop_getCurrency(); } $zone_id = hikashop_getZone(null); $currencyClass->getPrices($rows, $product_ids, $currency_id, $main_currency, $zone_id, $discount_before_tax, $user_id); $element = array(); if (!empty($rows)) { foreach ($rows as $k => $row) { $obj = new stdClass(); $obj->order_product_name = $row->product_name; $obj->order_product_code = $row->product_code; $obj->order_product_quantity = !empty($quantities[$row->product_id]) ? $quantities[$row->product_id] : 1; $currencyClass->pricesSelection($row->prices, $obj->order_product_quantity); $obj->product_id = $row->product_id; $obj->order_id = (int) $data->order_id; if (!empty($row->prices)) { foreach ($row->prices as $price) { $obj->order_product_price = $price->price_value; $obj->order_product_tax = $price->price_value_with_tax - $price->price_value; $obj->order_product_tax_info = $price->taxes; } } $element[$k] = $obj; } } $result = false; $cart_type = JRequest::getString('cart_type', 'cart'); $cart_id = JRequest::getString($cart_type . '_id', '0'); if (!empty($data->order_id)) { $data->product = $element; $classOrder = hikashop_get('class.order'); $classOrder->recalculateFullPrice($data); $result = $classOrder->save($data); } else { //cart type $classCart = hikashop_get('class.cart'); if ($cart_id == '0') { $cart = $classCart->initCart(); $cart_id = $classCart->save($cart); } $cart = new stdClass(); $cart->cart_id = $cart_id; $cart->cart_type = $cart_type; JRequest::setVar('cart_type', $cart_type); JRequest::setVar($cart_type . '_id', $cart_id); $result = true; foreach ($element as $data) { if (!$classCart->update($data->product_id, $data->order_product_quantity, 1, 'cart', false, true)) { $result = false; } } if ($result) { $this->_terminate($cart, 'showcart'); } else { $this->product_select(); } } if ($result && $order_id == 0) { $this->_terminate($data, 1); } else { return true; } }
function compare() { if (!hikashop_level(2)) { return; } $app = JFactory::getApplication(); $cids = JRequest::getVar('cid', array(), '', 'array'); $config =& hikashop_config(); $this->assignRef('config', $config); global $Itemid; $menus = $app->getMenu(); $menu = $menus->getActive(); if (empty($menu)) { if (!empty($Itemid)) { $menus->setActive($Itemid); $menu = $menus->getItem($Itemid); } } if (empty($cids)) { if (is_object($menu)) { jimport('joomla.html.parameter'); $category_params = new HikaParameter($menu->params); $cids = $category_params->get('product_id'); if (!is_array($cids)) { $cids = array($cids); } foreach ($cids as $k => $cid) { if ($k > 7) { unset($cids[$k]); } } } } if (empty($cids)) { return; } $c = array(); foreach ($cids as $cid) { if (strpos($cid, ',') !== false) { $c = array_merge($c, explode(',', $cid)); } else { $c[] = (int) $cid; } } $cids = $c; JArrayHelper::toInteger($cids); $empty = ''; $default_params = $config->get('default_params'); jimport('joomla.html.parameter'); $params = new HikaParameter($empty); foreach ($default_params as $k => $param) { $params->set($k, $param); } $main_currency = (int) $config->get('main_currency', 1); $params->set('main_currency', $main_currency); $discount_before_tax = (int) $config->get('discount_before_tax', 0); $params->set('discount_before_tax', $discount_before_tax); $params->set('show_compare', (int) $config->get('show_compare', 0)); $compare_limit = (int) $config->get('compare_limit', 5); $params->set('compare_limit', $compare_limit); $compare_inc_lastseen = (int) $config->get('compare_inc_lastseen', 0); $params->set('compare_inc_lastseen', $compare_inc_lastseen); $params->set('compare_show_name_separator', (int) $config->get('compare_show_name_separator', 1)); $params->set('catalogue', (int) $config->get('catalogue', 0)); $params->set('add_to_cart', (int) 1); $params->set('show_price_weight', (int) $config->get('show_price_weight', 0)); $params->set('characteristic_display', $config->get('characteristic_display', 'table')); $params->set('characteristic_display_text', $config->get('characteristic_display_text', 1)); $params->set('show_quantity_field', $config->get('show_quantity_field', 1)); $this->assignRef('params', $params); if (count($cids) > $compare_limit) { $cids = array_slice($cids, 0, $compare_limit); } $filters = array('a.product_id IN (' . implode(',', $cids) . ')'); hikashop_addACLFilters($filters, 'product_access', 'a'); $query = 'SELECT DISTINCT a.product_id, a.*,b.product_category_id, b.category_id, b.ordering FROM ' . hikashop_table('product') . ' AS a LEFT JOIN ' . hikashop_table('product_category') . ' AS b ON a.product_id = b.product_id WHERE ' . implode(' AND ', $filters) . ' ORDER BY b.ordering ASC, a.product_id ASC'; $database = JFactory::getDBO(); $database->setQuery($query); $elements = $database->loadObjectList(); if (empty($elements)) { return; } $this->modules = $config->get('product_show_modules', ''); $module = hikashop_get('helper.module'); $this->modules = $module->setModuleData($this->modules); $currencyClass = hikashop_get('class.currency'); $currency_id = hikashop_getCurrency(); $zone_id = hikashop_getZone(null); $cart = hikashop_get('helper.cart'); $this->assignRef('cart', $cart); $this->selected_variant_id = 0; $productClass = hikashop_get('class.product'); $this->assignRef('currencyHelper', $currencyClass); $fieldsClass = hikashop_get('class.field'); $this->assignRef('fieldsClass', $fieldsClass); $classbadge = hikashop_get('class.badge'); $this->assignRef('classbadge', $classbadge); $fields = array(0 => array()); $unset = array(); $done = array(); foreach ($elements as $k => $element) { $product_id = $element->product_id; if (isset($done[$product_id])) { $unset[] = $k; continue; } else { $done[$product_id] = $product_id; } if ($element->product_type == 'variant') { $filters = array('a.product_id=' . $element->product_parent_id); hikashop_addACLFilters($filters, 'product_access', 'a'); $query = 'SELECT a.*,b.* FROM ' . hikashop_table('product') . ' AS a LEFT JOIN ' . hikashop_table('product_category') . ' AS b ON a.product_id = b.product_id WHERE ' . implode(' AND ', $filters) . ' LIMIT 1'; $database->setQuery($query); $elements[$k] = $database->loadObject(); if (empty($elements[$k])) { return; } $k = array_search($product_id, $cids); if ($k !== false) { $cids[$k] = (int) $element->product_id; } } $productClass->addAlias($elements[$k]); if (!$elements[$k]->product_published) { return; } if ($compare_inc_lastseen) { $prod = new stdClass(); $prod->product_id = $product_id; $prod->product_hit = $element->product_hit + 1; $prod->product_last_seen_date = time(); $productClass->save($prod, true); } $f = $fieldsClass->getFields('frontcomp', $element, 'product', 'checkout&task=state'); $fields[$element->product_id] =& $f; foreach ($f as $i => $v) { $fields[0][$i] = $v; } } if (!empty($unset)) { foreach ($unset as $u) { unset($elements[$u]); } } $query = 'SELECT * FROM ' . hikashop_table('file') . ' WHERE file_ref_id IN (' . implode(',', $cids) . ') AND file_type IN (\'product\',\'file\') ORDER BY file_ref_id ASC, file_ordering ASC, file_id ASC'; $database->setQuery($query); $product_files = $database->loadObjectList(); if (!empty($product_files)) { foreach ($elements as $k => $element) { $productClass->addFiles($elements[$k], $product_files); } } $defaultParams = $config->get('default_params'); $detault_display_type = @$defaultParams['price_display_type']; $currencyClass->getListingPrices($elements, $zone_id, $currency_id, $detault_display_type); $this->assignRef('elements', $elements); $image = hikashop_get('helper.image'); $this->assignRef('image', $image); $this->assignRef('fields', $fields); $url = $this->init(); $cart->getJS($url); $this->assignRef('redirect_url', $url); }
function computePrice($order, &$payment, $price_all, $payment_price, $currency) { $currencyClass = hikashop_get('class.currency'); $zone_id = hikashop_getZone('shipping'); $payment->payment_currency_id = $currency; if (!empty($payment->payment_params->payment_algorithm) && $payment->payment_params->payment_algorithm == 'realcost') { if (!empty($payment->payment_params->payment_tax_id) && @$order->full_total->prices[0]->price_value != @$order->full_total->prices[0]->price_value_with_tax) { $payment_price_with_tax = $currencyClass->getTaxedPrice($payment_price, $zone_id, $payment->payment_params->payment_tax_id); $payment_percentage = (double) @$payment->payment_params->payment_percentage / 100; $payment_percentage_with_tax = $currencyClass->getTaxedPrice($payment_percentage, $zone_id, $payment->payment_params->payment_tax_id); } else { $payment_price_with_tax = $payment_price; $payment_percentage_with_tax = (double) @$payment->payment_params->payment_percentage / 100; } $payment_checkout = ($price_all + $payment_price_with_tax) / (1 - $payment_percentage_with_tax); $payment->payment_price_with_tax = $currencyClass->round($payment_checkout - $price_all, $currencyClass->getRounding($currency, true)); $payment->payment_price = $currencyClass->getUntaxedPrice($payment->payment_price_with_tax, $zone_id, $payment->payment_params->payment_tax_id); $payment->payment_tax = $payment->payment_price_with_tax - $payment->payment_price; return $payment->payment_price; } else { $payment->payment_price = $currencyClass->round($price_all * (double) @$payment->payment_params->payment_percentage / 100 + $payment_price, $currencyClass->getRounding($currency, true)); if (!empty($payment->payment_params->payment_tax_id) && isset($order->full_total->prices[0]->price_value_without_payment_with_tax)) { $payment->payment_price_with_tax = $currencyClass->getTaxedPrice($payment->payment_price, $zone_id, $payment->payment_params->payment_tax_id); $payment->payment_tax = $payment->payment_price_with_tax - $payment->payment_price; return $payment->payment_price_with_tax; } } return $payment->payment_price; }
function processPayments(&$usable_rates) { if (!empty($usable_rates)) { $this->convertPayments($usable_rates); $zone_id = hikashop_getZone(); foreach ($usable_rates as $k => $rate) { $round = $this->getRounding(@$rate->payment_currency_id, true); if (!empty($rate->payment_params->payment_tax_id) && bccomp($rate->payment_price, 0, 5)) { if (!empty($usable_rates[$k]->taxes_added)) { continue; } $usable_rates[$k]->taxes_added = true; $usable_rates[$k]->payment_price_with_tax = $this->getTaxedPrice($rate->payment_price, $zone_id, $rate->payment_params->payment_tax_id, $round); $usable_rates[$k]->taxes = $this->taxRates; if (isset($rate->payment_price_orig) && bccomp($rate->payment_price_orig, 0, 5)) { $usable_rates[$k]->payment_price_orig_with_tax = $this->getTaxedPrice($rate->payment_price_orig, $zone_id, $rate->payment_params->payment_tax_id, $round); $usable_rates[$k]->taxes_orig = $this->taxRates; } else { $usable_rates[$k]->payment_price_orig = 0.0; $usable_rates[$k]->payment_price_orig_with_tax = 0.0; } } else { if (!is_object($usable_rates[$k])) { $usable_rates[$k] = new stdClass(); } $usable_rates[$k]->payment_price_with_tax = @$rate->payment_price; $usable_rates[$k]->payment_price_orig_with_tax = @$usable_rates[$k]->payment_price_orig; } } } JPluginHelper::importPlugin('hikashop'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onAfterProcessPayments', array(&$usable_rates)); }
function addRate(&$rates, $service_types, $parcel, &$rate, $currency, $nb_package) { if (empty($nb_package)) { $nb_package = 1; } $app = JFactory::getApplication(); if ($parcel->country_code == 'AU') { $queryParams = array("from_postcode" => $parcel->from_postcode, "to_postcode" => $parcel->to_postcode, "length" => $parcel->Length, "width" => $parcel->Width, "height" => $parcel->Height, "weight" => $parcel->Weight); $urlPrefix = 'auspost.com.au'; $postageTypesURL = 'http://' . $urlPrefix . '/api/v3/postage/domestic/service.json?' . http_build_query($queryParams); $session = curl_init(); curl_setopt($session, CURLOPT_URL, $postageTypesURL); curl_setopt($session, CURLOPT_RETURNTRANSFER, 1); curl_setopt($session, CURLOPT_HTTPHEADER, array('AUTH-KEY: ' . $rate->shipping_params->api_key)); $rawBody = curl_exec($session); if (!$rawBody) { $app->enqueueMessage('Error: "' . curl_error($session) . '" - Code: ' . curl_errno($session)); return false; } $serviceTypesJSON = json_decode($rawBody); } else { $queryParams = array("country_code" => $parcel->country_code, "weight" => $parcel->Weight); $urlPrefix = 'auspost.com.au'; $postageTypesURL = 'http://' . $urlPrefix . '/api/postage/parcel/international/service.json?' . http_build_query($queryParams); $session = curl_init(); curl_setopt($session, CURLOPT_URL, $postageTypesURL); curl_setopt($session, CURLOPT_RETURNTRANSFER, 1); curl_setopt($session, CURLOPT_HTTPHEADER, array('AUTH-KEY: ' . $rate->shipping_params->api_key)); $rawBody = curl_exec($session); if (!$rawBody) { $app->enqueueMessage('Error: "' . curl_error($session) . '" - Code: ' . curl_errno($session)); return false; } $serviceTypesJSON = json_decode($rawBody); } if (isset($serviceTypesJSON->services->service) && !empty($serviceTypesJSON->services->service)) { $data = array(); foreach ($serviceTypesJSON->services->service as $key => $service) { if (in_array($service->code, $service_types) && isset($service->price)) { if (empty($rates[$service->code])) { $info = new stdClass(); $info = !HIKASHOP_PHP5 ? $rate : clone $rate; $shipping_name = JText::_($service->code . '_NAME'); if ($shipping_name != $service->code . '_NAME') { $info->shipping_name .= ' ' . $shipping_name; } else { $info->shipping_name .= ' ' . $service->name; } if (!empty($rate->shipping_description)) { $info->shipping_description = $rate->shipping_description . ' '; } else { $shipping_description = JText::_($service->code . '_DESCRIPTION'); if ($shipping_description != $service->code . '_DESCRIPTION') { $info->shipping_description .= $shipping_description; } } $info->shipping_id .= '-' . $this->shipping_types[$service->code]; $rates[$service->code] = $info; } else { $shipping_description = JText::_($service->code . '_DESCRIPTION'); if ($shipping_description == $service->code . '_DESCRIPTION') { $shipping_description = ''; } if (empty($shipping_description)) { $shipping_description = $rate->shipping_description; } if (!empty($shipping_description)) { $shipping_description .= '<br/>'; } if ($nb_package > 1 && (isset($rate->shipping_params->shipping_group) && $rate->shipping_params->shipping_group)) { $rates[$service->code]->shipping_description = $shipping_description . JText::sprintf('X_PACKAGES', $nb_package); } else { $rates[$service->code]->shipping_description = $shipping_description; } } if (@$rates[$service->code]->shipping_tax_id) { $currencyClass = hikashop_get('class.currency'); $service->price = $currencyClass->getUntaxedPrice($service->price, hikashop_getZone(), $rates[$service->code]->shipping_tax_id); } $rates[$service->code]->shipping_price += $service->price; $rates[$service->code]->shipping_currency_id = $currency; } } } else { if (isset($serviceTypesJSON->error->errorMessage) && !empty($serviceTypesJSON->error->errorMessage)) { $app->enqueueMessage($serviceTypesJSON->error->errorMessage); return false; } } }
function addRate(&$rates, $type, $parcel, &$rate, $currency, $nb_package) { if (empty($nb_package)) { $nb_package = 1; } $parcel->Service_Type = $type; $url = 'http://drc.edeliver.com.au/ratecalc.asp?'; foreach (get_object_vars($parcel) as $key => $val) { $url .= $key . '=' . $val . '&'; } $url = rtrim($url, '&'); $url = parse_url($url); if (!isset($url['query'])) { $url['query'] = ''; } if (!isset($url['port'])) { if (!empty($url['scheme']) && in_array($url['scheme'], array('https', 'ssl'))) { $url['port'] = 443; } else { $url['port'] = 80; } } if (!empty($url['scheme']) && in_array($url['scheme'], array('https', 'ssl'))) { $url['host_socket'] = 'ssl://' . $url['host']; } else { $url['host_socket'] = $url['host']; } $fp = fsockopen($url['host_socket'], $url['port'], $errno, $errstr, 30); if (!$fp) { $app = JFactory::getApplication(); $app->enqueueMessage('Cannot connect to australia post web service. You hosting company might be blocking outbond connections'); return false; } $uri = $url['path'] . ($url['query'] != '' ? '?' . $url['query'] : ''); $header = "GET {$uri} HTTP/1.0\r\n" . "User-Agent: PHP/" . phpversion() . "\r\n" . "Referer: " . hikashop_currentURL() . "\r\n" . "Server: " . $_SERVER['SERVER_SOFTWARE'] . "\r\n" . "Host: " . $url['host'] . ":" . $url['port'] . "\r\n" . "Accept: */" . "*\r\n\r\n"; fwrite($fp, $header); $response = ''; while (!feof($fp)) { $response .= fgets($fp, 1024); } fclose($fp); $pos = strpos($response, "\r\n\r\n"); $header = substr($response, 0, $pos); $body = substr($response, $pos + 2 * strlen("\r\n\r\n")); if (preg_match_all('#([a-z_]+)=([a-z_\\.0-9 ]+?)#Ui', $response, $matches)) { $data = array(); foreach ($matches[1] as $key => $val) { $data[$val] = $matches[2][$key]; } if (!empty($data['err_msg'])) { if ($data['err_msg'] == 'OK') { if (empty($rates[$type])) { $info = new stdClass(); $info = !HIKASHOP_PHP5 ? $rate : clone $rate; $info->shipping_name .= ' ' . JText::_($type); if (!empty($rate->shipping_description)) { $info->shipping_description = $rate->shipping_description . ' '; } else { $shipping_description = JText::_($type . '_DESCRIPTION'); if ($shipping_description == $type . '_DESCRIPTION') { $info->shipping_description .= $shipping_description; } $info->shipping_description = $shipping_description; } $types = array('SEA' => 1, 'AIR' => 2, 'EXPRESS' => 3, 'STANDARD' => 4); $info->shipping_id .= '-' . $types[$type]; $rates[$type] = $info; } else { $shipping_description = JText::_($type . '_DESCRIPTION'); if ($shipping_description == $type . '_DESCRIPTION') { $shipping_description = ''; } if (empty($shipping_description)) { $shipping_description = $rate->shipping_description; } if (!empty($shipping_description)) { $shipping_description .= '<br/>'; } if ($nb_package > 1 && (isset($rate->shipping_params->shipping_group) && $rate->shipping_params->shipping_group)) { $rates[$type]->shipping_description = $shipping_description . JText::sprintf('X_PACKAGES', $nb_package); } else { $rates[$type]->shipping_description = $shipping_description; } } if (@$rates[$type]->shipping_tax_id) { $currencyClass = hikashop_get('class.currency'); $data['charge'] = $currencyClass->getUntaxedPrice($data['charge'], hikashop_getZone(), $rates[$type]->shipping_tax_id); } $rates[$type]->shipping_price += $data['charge']; } elseif (!empty($data['err_msg'])) { if (preg_match('#Selected Destination not reached by .*#i', $data['err_msg'])) { return true; } $app = JFactory::getApplication(); $app->enqueueMessage('The request to the Australia Post server failed with the message: ' . $data['err_msg']); } else { $app = JFactory::getApplication(); $app->enqueueMessage('The request to the Australia Post server failed'); } } } }
function listing() { $this->setName(); $app = JFactory::getApplication(); $database = JFactory::getDBO(); $config =& hikashop_config(); $pageInfo = new stdClass(); $pageInfo->filter = new stdClass(); $pageInfo->filter->order = new stdClass(); $pageInfo->limit = new stdClass(); $pageInfo->search = $app->getUserStateFromRequest($this->paramBase . ".search", 'search', '', 'string'); $pageInfo->filter->order->value = $app->getUserStateFromRequest($this->paramBase . ".filter_order", 'filter_order', 'a.cart_modified', 'cmd'); $pageInfo->filter->order->dir = $app->getUserStateFromRequest($this->paramBase . ".filter_order_Dir", 'filter_order_Dir', 'desc', 'word'); $pageInfo->limit->value = $app->getUserStateFromRequest($this->paramBase . '.list_limit', 'limit', $app->getCfg('list_limit'), 'int'); $pageInfo->limit->start = $app->getUserStateFromRequest($this->paramBase . '.limitstart', 'limitstart', 0, 'int'); $popup = JRequest::getString('tmpl') === 'component'; $this->assignRef('popup', $popup); if (JRequest::getString('cart_type', 'cart') == 'cart') { $filters = array('a.cart_type=\'cart\''); } else { $filters = array('a.cart_type=\'wishlist\''); } $searchMap = array('a.cart_id', 'a.user_id', 'a.cart_name', 'a.cart_coupon', 'a.cart_type'); if (!empty($pageInfo->search)) { $searchVal = '\'%' . hikashop_getEscaped(JString::strtolower(trim($pageInfo->search)), true) . '%\''; $filters[] = implode(" LIKE {$searchVal} OR ", $searchMap) . " LIKE {$searchVal}"; } $groupBy = 'GROUP BY a.cart_id'; $order = ''; if (!empty($pageInfo->filter->order->value)) { $order = ' ORDER BY ' . $pageInfo->filter->order->value . ' ' . $pageInfo->filter->order->dir; } if (!empty($filters)) { $filters = ' WHERE ' . implode(' AND ', $filters); } else { $filters = ''; } $from = 'FROM ' . hikashop_table('cart') . ' AS a'; $cartProduct = 'JOIN ' . hikashop_table('cart_product') . ' AS b ON a.cart_id=b.cart_id'; $query = $from . ' ' . $cartProduct . ' ' . $filters . ' ' . $groupBy . ' ' . $order; $database->setQuery('SELECT a.*, b.* ' . $query, (int) $pageInfo->limit->start, (int) $pageInfo->limit->value); $rows = $database->loadObjectList(); if (!empty($pageInfo->search)) { $rows = hikashop_search($pageInfo->search, $rows, 'cart_id'); } $database->setQuery('SELECT COUNT(*) ' . $from . ' ' . $cartProduct . ' ' . $filters . ' ' . $groupBy); $pageInfo->elements = new stdClass(); $pageInfo->elements->total = $database->loadResult(); $pageInfo->elements->page = count($rows); $currencyClass = hikashop_get('class.currency'); $this->assignRef('currencyHelper', $currencyClass); $currencyClass = hikashop_get('class.currency'); $productClass = hikashop_get('class.product'); $main_currency = (int) $config->get('main_currency', 1); $currency_id = hikashop_getCurrency(); if ($config->get('tax_zone_type', 'shipping') == 'billing') { $zone_id = hikashop_getZone('billing'); } else { $zone_id = hikashop_getZone('shipping'); } $discount_before_tax = (int) $config->get('discount_before_tax', 0); $cartClass = hikashop_get('class.cart'); foreach ($rows as $k => $row) { if ($row->cart_id != null) { $cartClass->cart = new stdClass(); $cartClass->cart->cart_id = (int) $row->cart_id; $cartClass->cart->cart_type = JRequest::getString('cart_type', 'cart'); $rows[$k]->full_cart = $cartClass->loadFullCart(false, true, true); $rows[$k]->price = isset($rows[$k]->full_cart->full_total->prices[0]->price_value) ? $rows[$k]->full_cart->full_total->prices[0]->price_value : 0; $rows[$k]->quantity = isset($rows[$k]->full_cart->number_of_items) ? $rows[$k]->full_cart->number_of_items : 0; $rows[$k]->currency = isset($rows[$k]->full_cart->full_total->prices[0]->price_currency_id) ? $rows[$k]->full_cart->full_total->prices[0]->price_currency_id : $config->get('main_currency', 1); } } $cart = hikashop_get('helper.cart'); $this->assignRef('cart', $cart); $this->assignRef('carts', $rows); $pageInfo->elements->total = count($rows); $this->assignRef('pageInfo', $pageInfo); $this->getPagination(); $manageUser = hikashop_isAllowed($config->get('acl_user_manage', 'all')); $this->assignRef('manageUser', $manageUser); $pageInfo->manageUser = $manageUser; $manage = hikashop_isAllowed($config->get('acl_wishlist_manage', 'all')); $this->assignRef('manage', $manage); hikashop_setTitle(JText::_($this->nameListing), $this->icon, $this->ctrl); $this->toolbar = array(array('name' => 'addNew', 'display' => $manage), array('name' => 'editList', 'display' => $manage), array('name' => 'deleteList', 'display' => hikashop_isAllowed($config->get('acl_wishlist_delete', 'all'))), '|', array('name' => 'pophelp', 'target' => $this->ctrl . '-listing'), 'dashboard'); }
function generateXML() { $app = JFactory::getApplication(); $db = JFactory::getDBO(); $pluginsClass = hikashop_get('class.plugins'); $plugin = $pluginsClass->getByName('hikashop', 'google_products'); if (empty($plugin->params['condition'])) { $plugin->params['condition'] = "new"; } if (@$plugin->params['increase_perf']) { $memory = '128M'; $max_execution = '120'; if ($plugin->params['increase_perf'] == 2) { $memory = '512M'; $max_execution = '600'; } elseif ($plugin->params['increase_perf'] == 3) { $memory = '1024M'; $max_execution = '6000'; } elseif ($plugin->params['increase_perf'] == 10) { $memory = '4096M'; $max_execution = '0'; } ini_set('memory_limit', $memory); ini_set('max_execution_timeout', $max_execution); } $query = 'SELECT * FROM ' . hikashop_table('product') . ' WHERE product_access=\'all\' AND product_published=1 AND product_type=\'main\''; if (!empty($plugin->params['in_stock_only'])) { $query .= ' AND product_quantity!=0'; } $db->setQuery($query); $products = $db->loadObjectList(); if (empty($products)) { return true; } $ids = array(); foreach ($products as $key => $row) { $ids[] = $row->product_id; $products[$key]->alias = JFilterOutput::stringURLSafe($row->product_name); } $queryCategoryId = 'SELECT * FROM ' . hikashop_table('product_category') . ' WHERE product_id IN (' . implode(',', $ids) . ')'; $db->setQuery($queryCategoryId); $categoriesId = $db->loadObjectList(); foreach ($products as $k => $row) { foreach ($categoriesId as $catId) { if ($row->product_id == $catId->product_id) { $products[$k]->categories_id[] = $catId->category_id; } } } $usedCat = array(); $catList = ""; foreach ($products as $product) { if (!empty($product->categories_id)) { foreach ($product->categories_id as $catId) { if (!isset($usedCat[$catId])) { $usedCat[$catId] = $catId; $catList .= $catId . ','; } } } } $catList = substr($catList, 0, -1); $parentCatId = 'product'; $categoryClass = hikashop_get('class.category'); $categoryClass->getMainElement($parentCatId); $query = 'SELECT DISTINCT b.* FROM ' . hikashop_table('category') . ' AS a LEFT JOIN ' . hikashop_table('category') . ' AS b ON a.category_left >= b.category_left WHERE ' . 'b.category_right >= a.category_right AND a.category_id IN (' . $catList . ') AND a.category_published=1 AND a.category_type=\'product\' AND b.category_id!=' . $parentCatId . ' ' . 'ORDER BY b.category_left'; $db->setQuery($query); $categories = $db->loadObjectList(); $category_path = array(); $discard_products_without_valid_categories = array(); foreach ($products as $k => $product) { if (empty($product->categories_id)) { $discard_products_without_valid_categories[] = $k; } else { $path = array(); $at_least_a_category_valid = false; foreach ($categories as $category) { foreach ($product->categories_id as $catID) { if ($catID == $category->category_id) { $at_least_a_category_valid = true; if (!isset($category_path[$catID])) { $category_path[$catID] = $this->_getCategoryParent($category, $categories, $path, $parentCatId); } } } } if (!$at_least_a_category_valid) { $discard_products_without_valid_categories[] = $k; } } } if (!empty($discard_products_without_valid_categories)) { foreach ($discard_products_without_valid_categories as $k) { unset($products[$k]); } } foreach ($category_path as $id => $mainCat) { $path = ''; for ($i = count($mainCat); $i > 0; $i--) { $path .= $mainCat[$i - 1]->category_name . ' > '; } $category_path[$id]['path'] = substr($path, 0, -3); } $queryImage = 'SELECT * FROM ' . hikashop_table('file') . ' WHERE file_ref_id IN (' . implode(',', $ids) . ') AND file_type=\'product\' ORDER BY file_ordering ASC, file_id ASC'; $db->setQuery($queryImage); $images = $db->loadObjectList(); $products[$k]->images = array(); foreach ($products as $k => $row) { $i = 0; foreach ($images as $image) { if ($row->product_id == $image->file_ref_id) { $products[$k]->images[$i] = new stdClass(); foreach (get_object_vars($image) as $key => $name) { $products[$k]->images[$i]->{$key} = $name; } } $i++; } } $db->setQuery('SELECT * FROM ' . hikashop_table('variant') . ' WHERE variant_product_id IN (' . implode(',', $ids) . ')'); $variants = $db->loadObjectList(); if (!empty($variants)) { foreach ($products as $k => $product) { foreach ($variants as $variant) { if ($product->product_id == $variant->variant_product_id) { $products[$k]->has_options = true; break; } } } } $zone_id = hikashop_getZone(); $currencyClass = hikashop_get('class.currency'); $config =& hikashop_config(); $main_currency = (int) $config->get('main_currency', 1); if (empty($plugin->params['price_displayed'])) { $plugin->params['price_displayed'] = 'cheapest'; } if ($plugin->params['price_displayed'] == 'cheapest') { $currencyClass->getListingPrices($products, $zone_id, $main_currency, 'cheapest'); } if ($plugin->params['price_displayed'] == 'unit') { $currencyClass->getListingPrices($products, $zone_id, $main_currency, 'unit'); } if ($plugin->params['price_displayed'] == 'average') { $currencyClass->getListingPrices($products, $zone_id, $main_currency, 'range'); $tmpPrice = 0; $tmpTaxPrice = 0; foreach ($products as $product) { if (isset($product->prices[0]->price_value)) { if (count($product->prices) > 1) { for ($i = 0; $i < count($product->prices); $i++) { if ($product->prices[$i]->price_value > $tmpPrice) { $tmpPrice += $product->prices[$i]->price_value; $tmpTaxPrice += @$product->prices[$i]->price_value_with_tax; } } $product->prices[0]->price_value = $tmpPrice / count($product->prices); $product->prices[0]->price_value_with_tax = $tmpTaxPrice / count($product->prices); for ($i = 1; $i < count($product->prices); $i++) { unset($product->prices[$i]); } } } } } if ($plugin->params['price_displayed'] == 'expensive') { $currencyClass->getListingPrices($products, $zone_id, $main_currency, 'range'); $tmpPrice = 0; foreach ($products as $product) { if (isset($product->prices[0]->price_value)) { if (count($product->prices) > 1) { for ($i = 0; $i < count($product->prices); $i++) { if ($product->prices[$i]->price_value > $tmpPrice) { $tmpPrice = $product->prices[$i]->price_value; $key = $i; } } $product->prices[0] = $product->prices[$key]; for ($i = 1; $i < count($product->prices); $i++) { unset($product->prices[$i]); } } } } } if (!empty($plugin->params['use_brand'])) { $parentCatId = 'manufacturer'; $categoryClass->getMainElement($parentCatId); $query = 'SELECT DISTINCT * FROM ' . hikashop_table('category') . ' AS a WHERE a.category_published=1 AND a.category_type=\'manufacturer\' AND a.category_parent_id=' . $parentCatId; $db->setQuery($query); $brands = $db->loadObjectList('category_id'); } $config =& hikashop_config(); $uploadFolder = ltrim(JPath::clean(html_entity_decode($config->get('uploadfolder'))), DS); $uploadFolder = rtrim($uploadFolder, DS) . DS; $this->uploadFolder_url = str_replace(DS, '/', $uploadFolder); $this->uploadFolder = JPATH_ROOT . DS . $uploadFolder; $app = JFactory::getApplication(); $this->thumbnail = $config->get('thumbnail', 1); $this->thumbnail_x = $config->get('thumbnail_x', 100); $this->thumbnail_y = $config->get('thumbnail_y', 100); $this->main_thumbnail_x = $this->thumbnail_x; $this->main_thumbnail_y = $this->thumbnail_y; $this->main_uploadFolder_url = $this->uploadFolder_url; $this->main_uploadFolder = $this->uploadFolder; $conf = JFactory::getConfig(); if (!HIKASHOP_J30) { $siteName = $conf->getValue('config.sitename'); $siteDesc = $conf->getValue('config.MetaDesc'); } else { $siteName = $conf->get('sitename'); $siteDesc = $conf->get('MetaDesc'); } $siteAddress = JURI::base(); $siteAddress = str_replace('administrator/', '', $siteAddress); $xml = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" . '<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">' . "\n" . "\t" . '<channel>' . "\n" . "\t\t" . '<title><![CDATA[ ' . $siteName . ' ]]></title>' . "\n" . "\t\t" . '<description><![CDATA[ ' . $siteDesc . ' ]]></description>' . "\n" . "\t\t" . '<link><![CDATA[ ' . $siteAddress . ' ]]></link>' . "\n" . "\n"; $productClass = hikashop_get('class.product'); foreach ($products as $product) { if (isset($product->prices[0]->price_value)) { $price_name = 'price_value'; if (!empty($plugin->params['taxed_price'])) { $price_name = 'price_value_with_tax'; } if (empty($product->product_min_per_order)) { $price = round($product->prices[0]->{$price_name}, 2); } else { $price = round($product->prices[0]->{$price_name}, 2) * $product->product_min_per_order; } $currencies = array(); $currencyClass = hikashop_get('class.currency'); $ids[$product->prices[0]->price_currency_id] = $product->prices[0]->price_currency_id; $currencies = $currencyClass->getCurrencies($ids[$product->prices[0]->price_currency_id], $currencies); $currency = reset($currencies); $xml .= '<item>' . "\n"; $productClass->addAlias($product); if ($product->product_weight_unit == 'mg') { $product->product_weight = $product->product_weight * 1000; $product->product_weight_unit = 'g'; } $xml .= "\t" . '<g:id>' . $product->product_id . '</g:id>' . "\n"; $xml .= "\t" . '<title><![CDATA[ ' . $product->product_name . ' ]]></title>' . "\n"; $itemID = ''; if (!empty($plugin->params['item_id'])) { $itemID = '&Itemid=' . $plugin->params['item_id']; } if (!empty($product->product_canonical)) { $xml .= "\t" . '<g:link><![CDATA[ ' . str_replace('/administrator/', '/', hikashop_cleanURL($product->product_canonical)) . ' ]]></g:link>' . "\n"; } else { $xml .= "\t" . '<g:link><![CDATA[ ' . $siteAddress . 'index.php?option=com_hikashop&ctrl=product&task=show&cid=' . $product->product_id . '&name=' . $product->alias . $itemID . ' ]]></g:link>' . "\n"; } $xml .= "\t" . '<g:price>' . $price . ' ' . $currency->currency_code . '</g:price>' . "\n"; if (!empty($product->product_description)) { if (@$plugin->params['preview']) { $xml .= "\t" . '<g:description><![CDATA[ ' . strip_tags(preg_replace('#<hr *id="system-readmore" */>.*#is', '', $product->product_description)) . ' ]]></g:description>' . "\n"; } else { $xml .= "\t" . '<g:description><![CDATA[ ' . strip_tags($product->product_description) . ' ]]></g:description>' . "\n"; } } elseif (!empty($plugin->params['message'])) { $xml .= "\t" . '<g:description><![CDATA[ ' . $plugin->params['message'] . ' ]]></g:description>' . "\n"; } else { $xml .= "\t" . '<g:description>No description</g:description>' . "\n"; } $xml .= $this->_additionalParameter($product, $plugin, 'condition', 'condition'); $xml .= $this->_additionalParameter($product, $plugin, 'gender', 'gender'); $xml .= $this->_additionalParameter($product, $plugin, 'gtin', 'gtin'); $xml .= $this->_additionalParameter($product, $plugin, 'age_group', 'age_group'); $xml .= $this->_additionalParameter($product, $plugin, 'size', 'size'); $xml .= $this->_additionalParameter($product, $plugin, 'color', 'color'); $xml .= $this->_additionalParameter($product, $plugin, 'identifier_exists', 'identifier_exists'); $xml .= $this->_addShipping($product, $plugin); if (!empty($plugin->params['use_brand']) && !empty($brands[$product->product_manufacturer_id]->category_name)) { $xml .= "\t" . '<g:brand><![CDATA[ ' . $brands[$product->product_manufacturer_id]->category_name . ' ]]></g:brand>' . "\n"; } else { $xml .= $this->_additionalParameter($product, $plugin, 'brand', 'brand'); } $xml .= $this->_additionalParameter($product, $plugin, 'category', 'google_product_category'); if ($plugin->params['add_code']) { $xml .= "\t" . '<g:mpn><![CDATA[ ' . str_replace(array(' ', '-'), array('', ''), $product->product_code) . ' ]]></g:mpn>' . "\n"; } if (isset($product->images) && count($product->images)) { $i = 0; $name = "image_link"; foreach ($product->images as $image) { if ($i < 10) { $xml .= "\t" . '<g:' . $name . '>' . htmlspecialchars($siteAddress . $this->main_uploadFolder_url . $image->file_path) . '</g:' . $name . '>' . "\n"; $name = "additional_image_link"; $i++; } } } $type = ''; foreach ($product->categories_id as $catID) { foreach ($category_path as $id => $catPath) { if ($id == $catID) { if (strlen($type . '"' . $catPath['path'] . '",') > 750) { continue; } $type .= '"' . $catPath['path'] . '",'; } } } if (!empty($type)) { $type = substr($type, 0, -1); $xml .= "\t" . '<g:product_type><![CDATA[ ' . $type . ' ]]></g:product_type>' . "\n"; } if ($product->product_quantity != -1) { $xml .= "\t" . '<g:quantity>' . $product->product_quantity . '</g:quantity>' . "\n"; } if ($product->product_quantity == 0) { $xml .= "\t" . '<g:availability>out of stock</g:availability>' . "\n"; } else { $xml .= "\t" . '<g:availability>in stock</g:availability>' . "\n"; } $xml .= "\t" . '<g:shipping_weight>' . (double) hikashop_toFloat($product->product_weight) . ' ' . $product->product_weight_unit . '</g:shipping_weight>' . "\n"; $xml .= '</item>' . "\n"; } } $xml .= '</channel>' . "\n" . '</rss>' . "\n"; return $xml; }
function onAfterCartShippingLoad(&$cart) { $app = JFactory::getApplication(); $opt = $this->readGeneralOptions(); $no_virtual_coupon = (int) $app->getUserState(HIKASHOP_COMPONENT . '.userpoints_no_virtual_coupon', (int) (@$opt['checkout_step'] && @$opt['default_no_use'])); if (!empty($no_virtual_coupon)) { unset($cart->additional['userpoints']); unset($cart->additional['userpoints_points']); return; } $user = JFactory::getUser(); if (empty($user->id)) { return false; } if (isset($cart->additional['userpoints'])) { return; } $ret = $this->getCartUsedPoints($cart); if (empty($ret)) { return; } $pointsToLoose = $ret['points']; $coupon = $ret['value']; if (isset($cart->order_currency_id)) { $currency_id = $cart->order_currency_id; } else { $currency_id = hikashop_getCurrency(); } $zone_id = hikashop_getZone(); $tax_id = (int) @$this->payment_params->tax_id; $currencyClass = hikashop_get('class.currency'); $userpoints = new stdClass(); $userpoints->name = 'USERPOINTS_DISCOUNT'; $userpoints->value = ''; $userpoints->price_currency_id = $currency_id; $userpoints->price_value = -$coupon; $userpoints->price_value_with_tax = $currencyClass->getTaxedPrice($userpoints->price_value, $zone_id, $tax_id); $cart->additional['userpoints'] = $userpoints; $userpoints_points = new stdClass(); $userpoints_points->name = 'USERPOINTS_USE_POINTS'; $userpoints_points->value = $pointsToLoose . ' ' . JText::_('USERPOINTS_POINTS'); $userpoints_points->price_currency_id = 0; $userpoints_points->price_value = 0; $userpoints_points->price_value_with_tax = 0; $cart->additional['userpoints_points'] = $userpoints_points; }
public function edit_products($tpl = null) { $config = hikashop_config(); $this->assignRef('config', $config); $productClass = hikashop_get('class.product'); $fieldsClass = hikashop_get('class.field'); $this->assignRef('fieldsClass', $fieldsClass); $order_id = JRequest::getInt('order_id'); $order_product_id = JRequest::getInt('order_product_id', 0); $orderClass = hikashop_get('class.order'); $order = $orderClass->loadFullOrder($order_id); $originalProduct = new stdClass(); if (!empty($order_product_id)) { $orderProductClass = hikashop_get('class.order_product'); $orderProduct = $orderProductClass->get($order_product_id); if (empty($orderProduct) || $orderProduct->order_id != $order_id) { $orderProduct = new stdClass(); $orderProduct->order_id = $order_id; } if (!empty($orderProduct->product_id)) { $originalProduct = $productClass->get($orderProduct->product_id); } } else { $orderProduct = new stdClass(); $orderProduct->order_id = $order_id; $orderProduct->order_product_quantity = 1; $product_id = JRequest::getVar('cid', array(), '', 'array'); if (!empty($product_id)) { $database = JFactory::getDBO(); $query = 'SELECT product_parent_id FROM ' . hikashop_table('product') . ' WHERE product_id = ' . (int) $product_id[0]; $database->setQuery($query); $product_parent_id = $database->loadResult(); $isVariant = false; if ($product_parent_id != 0) { $product_id[1] = $product_parent_id; $isVariant = true; } if ($productClass->getProducts($product_id)) { $products = $productClass->products; $allproducts = $productClass->all_products; if (!$isVariant) { $product = $products[(int) $product_id[0]]; } else { $product = $allproducts[(int) $product_id[1]]->variants[(int) $product_id[0]]; } $product->options = array(); $originalProduct = $product; $orderProduct->product_id = $product->product_id; if ($isVariant && empty($product->product_name)) { $product->product_name = $allproducts[(int) $product_id[1]]->product_name; } $orderProduct->order_product_name = strip_tags($product->product_name); $orderProduct->order_product_code = $product->product_code; $currencyClass = hikashop_get('class.currency'); $main_currency = (int) $config->get('main_currency', 1); $discount_before_tax = (int) $config->get('discount_before_tax', 0); $currency_id = $order->order_currency_id; if ($config->get('tax_zone_type', 'shipping') == 'billing') { $orderClass->loadAddress($order->order_billing_address_id, $order, 'billing', 'object', 'backend'); if (!empty($order->billing_address->address_state->zone_id)) { $zone_id = $order->billing_address->address_state->zone_id; } elseif (!empty($order->billing_address->address_country->zone_id)) { $zone_id = $order->billing_address->address_country->zone_id; } else { $zone_id = hikashop_getZone('billing'); } } else { $orderClass->loadAddress($order->order_shipping_address_id, $order, 'shipping', 'object', 'backend'); if (!empty($order->shipping_address->address_state->zone_id)) { $zone_id = $order->shipping_address->address_state->zone_id; } elseif (!empty($order->shipping_address->address_country->zone_id)) { $zone_id = $order->shipping_address->address_country->zone_id; } else { $zone_id = hikashop_getZone('shipping'); } } $rows = array($product); if ($isVariant) { $rows[] = $allproducts[(int) $product_id[1]]; } $currencyClass->getPrices($rows, $product_id, $currency_id, $main_currency, $zone_id, $discount_before_tax, (int) $order->order_user_id); if (empty($rows[0]->prices) && !empty($rows[1]->prices)) { $rows[0]->prices = $rows[1]->prices; } $currencyClass->pricesSelection($rows[0]->prices, 0); if (!empty($rows[0]->prices)) { foreach ($rows[0]->prices as $price) { $orderProduct->order_product_price = $price->price_value; $orderProduct->order_product_tax = @$price->price_value_with_tax - @$price->price_value; $orderProduct->order_product_tax_info = @$price->taxes; } } } } } $this->assignRef('orderProduct', $orderProduct); $this->assignRef('originalProduct', $originalProduct); $ratesType = hikashop_get('type.rates'); $this->assignRef('ratesType', $ratesType); if (hikashop_level(2)) { $null = null; $this->fields['item'] = $this->fieldsClass->getFields('backend', $null, 'item', 'user&task=state'); } }
function _checkData(&$product, $main = false) { $this->currentProductVariants = array(); if (empty($product->product_created)) { $product->product_created = time(); } elseif (!is_numeric($product->product_created)) { $product->product_created = strtotime($product->product_created); } if (empty($product->product_modified)) { $product->product_modified = time(); } elseif (!is_numeric($product->product_modified)) { $product->product_modified = strtotime($product->product_modified); } if (empty($product->product_sale_start)) { if (!empty($this->template->product_sale_start)) { $product->product_sale_start = $this->template->product_sale_start; } } elseif (!is_numeric($product->product_sale_start)) { $product->product_sale_start = strtotime($product->product_sale_start); } if (empty($product->product_sale_end)) { if (!empty($this->template->product_sale_end)) { $product->product_sale_end = $this->template->product_sale_end; } } elseif (!is_numeric($product->product_sale_end)) { $product->product_sale_end = strtotime($product->product_sale_end); } if (!empty($product->product_weight)) { $product->product_weight = hikashop_toFloat($product->product_weight); } if (!empty($product->product_width)) { $product->product_width = hikashop_toFloat($product->product_width); } if (!empty($product->product_height)) { $product->product_height = hikashop_toFloat($product->product_height); } if (!empty($product->product_length)) { $product->product_length = hikashop_toFloat($product->product_length); } if (empty($product->product_type)) { if (empty($product->product_parent_id)) { $product->product_type = 'main'; } else { if (!empty($product->product_parent_id) && !empty($product->product_code) && $product->product_parent_id == $product->product_code) { $app = JFactory::getApplication(); $app->enqueueMessage('The product ' . $product->product_code . ' has the same value in the product_parent_id and product_code fields which is not possible ( a main product cannot be a variant at the same time ). This product has been considered as a main product by HikaShop and has been imported as such.'); $product->product_type = 'main'; $product->product_parent_id = 0; } else { $product->product_type = 'variant'; } } } else { if (!in_array($product->product_type, array('main', 'variant'))) { $product->product_type = 'main'; } } if ($product->product_type == 'main') { if (!empty($product->product_parent_id)) { $app = JFactory::getApplication(); $app->enqueueMessage('The product ' . @$product->product_code . ' should have an empty value instead of the value ' . $product->product_parent_id . ' in the field product_parent_id as it is a main product (not a variant) and thus doesn\'t have any parent.', 'error'); } } else { $product->product_tax_id = 0; } if (!isset($product->product_tax_id) || strlen($product->product_tax_id) < 1) { $product->product_tax_id = $this->tax_category; } else { if (!is_numeric($product->product_tax_id)) { $id = $this->_getCategory($product->product_tax_id, 0, !$this->createCategories, 'tax'); if (empty($id) && $this->createCategories) { $id = $this->_createCategory($product->product_tax_id, 0, 'tax'); } $product->product_tax_id = $id; } } if (!empty($product->product_manufacturer_id) && !is_numeric($product->product_manufacturer_id)) { $id = $this->_getCategory($product->product_manufacturer_id, 0, !$this->createCategories, 'manufacturer'); if (empty($id) && $this->createCategories) { $id = $this->_createCategory($product->product_manufacturer_id, 0, 'manufacturer'); } $product->product_manufacturer_id = $id; } if (!isset($product->product_quantity) || strlen($product->product_quantity) < 1) { if (!empty($this->template->product_quantity)) { $product->product_quantity = $this->template->product_quantity; } } if (isset($product->product_quantity) && !is_numeric($product->product_quantity)) { $product->product_quantity = -1; } foreach ($this->fields as $field) { if (empty($product->{$field}) && !empty($this->template->{$field})) { $product->{$field} = $this->template->{$field}; } } if (empty($product->product_dimension_unit)) { $product->product_dimension_unit = $this->volumeHelper->getSymbol(); } else { $product->product_dimension_unit = strtolower($product->product_dimension_unit); } if (empty($product->product_weight_unit)) { $product->product_weight_unit = $this->weightHelper->getSymbol(); } else { $product->product_weight_unit = strtolower($product->product_weight_unit); } if (!empty($product->product_published)) { $product->product_published = 1; } if (!isset($product->product_published)) { if (!empty($this->template)) { $product->product_published = $this->template->product_published; } } if (!empty($product->price_value_with_tax)) { $currencyHelper = hikashop_get('class.currency'); if (empty($product->product_tax_id)) { $product->product_tax_id = $currencyHelper->getTaxCategory(); } if ($product->product_tax_id) { if (strpos($product->price_value_with_tax, '|') === false) { $product->price_value = $currencyHelper->getUntaxedPrice(hikashop_toFloat($product->price_value_with_tax), hikashop_getZone(), $product->product_tax_id); } else { $price_value = explode('|', $product->price_value_with_tax); foreach ($price_value as $k => $price_value_one) { $price_value[$k] = $currencyHelper->getUntaxedPrice($price_value_one, hikashop_getZone(), $product->product_tax_id); } $product->price_value = implode('|', $price_value); } } } if (!empty($product->price_value)) { $product->prices = array(); if (strpos($product->price_value, '|') === false) { $price = new stdClass(); $price->price_value = hikashop_toFloat($product->price_value); if (!empty($this->price_fee)) { $price->price_value += $price->price_value * hikashop_toFloat($this->price_fee) / 100; } $price->price_min_quantity = (int) @$product->price_min_quantity; if ($price->price_min_quantity == 1) { $price->price_min_quantity = 0; } if (empty($product->price_access)) { $price->price_access = 'all'; } else { $price->price_access = $product->price_access; } if (!empty($product->price_currency_id)) { if (!is_numeric($product->price_currency_id)) { $product->price_currency_id = $this->_getCurrency($product->price_currency_id); } $price->price_currency_id = $product->price_currency_id; } else { $config =& hikashop_config(); $price->price_currency_id = $config->get('main_currency', 1); } $product->prices[] = $price; } else { $price_value = explode('|', $product->price_value); if (!empty($product->price_min_quantity)) { $price_min_quantity = explode('|', $product->price_min_quantity); } if (!empty($product->price_access)) { $price_access = explode('|', $product->price_access); } if (!empty($product->price_currency_id)) { $price_currency_id = explode('|', $product->price_currency_id); } foreach ($price_value as $k => $price_value_one) { $price = new stdClass(); $price->price_value = hikashop_toFloat($price_value_one); if (!empty($this->price_fee)) { $price->price_value += $price->price_value * hikashop_toFloat($this->price_fee) / 100; } $price->price_min_quantity = (int) @$price_min_quantity[$k]; if ($price->price_min_quantity == 1) { $price->price_min_quantity = 0; } if (empty($price_access[$k])) { $price->price_access = 'all'; } else { $price->price_access = $price_access[$k]; } if (!empty($price_currency_id[$k])) { if (!is_numeric($price_currency_id[$k])) { $price_currency_id[$k] = $this->_getCurrency($price_currency_id[$k]); } $price->price_currency_id = $price_currency_id[$k]; } else { $config =& hikashop_config(); $price->price_currency_id = $config->get('main_currency', 1); } $product->prices[] = $price; } } } if (!empty($product->files) && !is_array($product->files)) { $this->_separate($product->files); $unset = array(); foreach ($product->files as $k => $file) { $product->files[$k] = $file = trim($file); if (substr($file, 0, 7) == 'http://' || substr($file, 0, 8) == 'https://') { $parts = explode('/', $file); $name = array_pop($parts); $name = explode('?', $name); $name = array_shift($name); $name = urldecode($name); if (!file_exists($this->uploadFolder . $name)) { $data = @file_get_contents($file); if (empty($data) && !empty($this->default_file)) { $name = $this->default_file; } else { JFile::write($this->uploadFolder . $name, $data); } } else { $size = $this->getSizeFile($file); if ($size != filesize($this->uploadFolder . $name)) { $name = $size . '_' . $name; if (!file_exists($this->uploadFolder . $name)) { JFile::write($this->uploadFolder . $name, file_get_contents($file)); } } } if (file_exists($this->uploadFolder . $name) && (filesize($this->uploadFolder . $name) > 0 || filesize($this->uploadFolder . $name) === false)) { $product->files[$k] = $name; } else { $unset[] = $k; } } } if (!empty($unset)) { foreach ($unset as $k) { unset($product->files[$k]); } } $this->_filesToObject($product->files, 'files'); $this->_getFilesExtraData($product->files, $product, 'files'); } if (!empty($product->images) && !is_array($product->images)) { $this->_separate($product->images); $unset = array(); foreach ($product->images as $k => $image) { $product->images[$k] = $image = trim($image); if (substr($image, 0, 7) == 'http://' || substr($image, 0, 8) == 'https://') { $parts = explode('/', $image); $name = array_pop($parts); $name = explode('?', $name); $name = array_shift($name); $name = urldecode($name); if (!file_exists($this->uploadFolder . $name)) { $content = file_get_contents($image); JFile::write($this->uploadFolder . $name, $content); } else { $size = $this->getSizeFile($image); if ($size != filesize($this->uploadFolder . $name)) { $name = $size . '_' . $name; if (!file_exists($this->uploadFolder . $name)) { $content = file_get_contents($image); JFile::write($this->uploadFolder . $name, $content); } } } if (file_exists($this->uploadFolder . $name) && (filesize($this->uploadFolder . $name) > 0 || filesize($this->uploadFolder . $name) === false)) { $product->images[$k] = $name; } else { $unset[] = $k; } } } if (!empty($unset)) { foreach ($unset as $k) { unset($product->images[$k]); } } $this->_filesToObject($product->images, 'images'); $this->_getFilesExtraData($product->images, $product, 'images'); } if (empty($product->product_name)) { if (!empty($product->files)) { if (!is_array($product->files)) { $this->_separate($product->files); } if (is_object($product->files[0])) { $name = $product->files[0]->file_name; } else { $name = substr($product->files[0], 0, strrpos($product->files[0], '.')); } $product->product_name = $name; } elseif (!empty($product->images)) { if (!is_array($product->images)) { $this->_separate($product->images); } if (is_object($product->images[0])) { $name = $product->images[0]->file_name; } else { $name = substr($product->images[0], 0, strrpos($product->images[0], '.')); } $product->product_name = $name; } } if (!empty($product->related) && !is_array($product->related)) { $this->_separate($product->related); } if (!empty($product->options) && !is_array($product->options)) { $this->_separate($product->options); } if ($product->product_type == 'variant') { $product->categories = null; } else { if (!empty($product->categories)) { if (!is_array($product->categories)) { $this->_separate($product->categories); } $parent_id = 0; if ($this->createCategories && !empty($product->parent_category)) { $this->_separate($product->parent_category); $parent_id = array(); foreach ($product->parent_category as $k => $parent_category) { if (is_numeric($parent_category)) { $parent_id[$k] = $parent_category; } else { $parent_id[$k] = $this->_getCategory($parent_category, 0, false, 'product'); if (empty($parent_id[$k])) { $parent_id[$k] = $this->_createCategory($parent_category); } } } } if ($this->createCategories && !empty($product->categories_image)) { $unset = array(); $this->_separate($product->categories_image); foreach ($product->categories_image as $k => $image) { if (substr($image, 0, 7) == 'http://' || substr($image, 0, 8) == 'https://') { $parts = explode('/', $image); $name = array_pop($parts); if (!file_exists($this->uploadFolder . $name)) { JFile::write($this->uploadFolder . $name, file_get_contents($image)); } else { $size = $this->getSizeFile($image); if ($size != filesize($this->uploadFolder . $name)) { $name = $size . '_' . $name; if (!file_exists($this->uploadFolder . $name)) { JFile::write($this->uploadFolder . $name, file_get_contents($image)); } } } if (filesize($this->uploadFolder . $name)) { $product->categories_image[$k] = $name; } else { $unset[] = $k; } } } if (!empty($unset)) { foreach ($unset as $k) { unset($product->categories_image[$k]); } } } if ($this->createCategories && !empty($product->categories_namekey)) { $this->_separate($product->categories_namekey); } foreach ($product->categories as $k => $v) { if (!is_numeric($v) || !empty($product->categories_namekey)) { $pid = 0; if (is_array($parent_id)) { if (!empty($parent_id[$k])) { $pid = $parent_id[$k]; } elseif (!empty($parent_id[0])) { $pid = $parent_id[0]; } } $id = $this->_getCategory($v, 0, !$this->createCategories, 'product', $pid, @$product->categories_image[$k]); if (empty($id)) { if ($this->createCategories) { $id = $this->_createCategory($v, $pid, 'product', @$product->categories_image[$k], @$product->categories_namekey[$k]); } else { $app = JFactory::getApplication(); $app->enqueueMessage('The product ' . @$product->product_code . ' has the category name "' . $v . '" in your CSV but that category doesn\'t exist on your website and you turned off the automatic creation of categories for the import.', 'error'); } } $product->categories[$k] = (int) $id; } } } } if (!empty($product->categories_ordering)) { $this->_separate($product->categories_ordering); } if (empty($product->product_access)) { if (!empty($this->template)) { $product->product_access = @$this->template->product_access; } else { $product->product_access = 'all'; } } if (!isset($product->product_contact) && !empty($this->template)) { $product->product_contact = @$this->template->product_contact; } if (!isset($product->product_group_after_purchase) && !empty($this->template)) { $product->product_group_after_purchase = @$this->template->product_group_after_purchase; } if (hikashop_level(2) && !empty($product->product_access)) { if (!is_array($product->product_access)) { if (!in_array($product->product_access, array('none', 'all'))) { if (!is_array($product->product_access)) { $this->_separate($product->product_access); } } } if (is_array($product->product_access)) { $accesses = array(); foreach ($product->product_access as $access) { if (empty($access)) { continue; } if (!is_numeric($access)) { $access = $this->_getAccess($access); if (empty($access)) { continue; } } $accesses[] = $access; } $product->product_access = ',' . implode(',', $accesses) . ','; } } if (!empty($this->characteristicColumns)) { foreach ($this->characteristicColumns as $column) { if (isset($product->{$column}) && strlen($product->{$column}) > 0) { if ($product->product_type == 'main' && !empty($this->characteristicsConversionTable[$column])) { if (!isset($product->variant_links)) { $product->variant_links = array(); } $product->variant_links[] = $this->characteristicsConversionTable[$column]; } if (function_exists('mb_strtolower')) { $key = mb_strtolower(trim($product->{$column}, '" ')); } else { $key = strtolower(trim($product->{$column}, '" ')); } if (!empty($this->characteristicsConversionTable[$column . '_' . $key])) { $key = $column . '_' . $key; } if (!empty($this->characteristicsConversionTable[$key])) { if (!isset($product->variant_links)) { $product->variant_links = array(); } $product->variant_links[] = $this->characteristicsConversionTable[$key]; } } } } if (!empty($product->product_id) && empty($product->product_code)) { $query = 'SELECT `product_code` FROM ' . hikashop_table('product') . ' WHERE product_id=' . (int) $product->product_id; $this->db->setQuery($query); $product->product_code = $this->db->loadResult(); } else { if (empty($product->product_code) && !empty($product->product_name)) { $test = preg_replace('#[^a-z0-9_-]#i', '', $product->product_name); if (empty($test)) { static $last_pid = null; if ($last_pid === null) { $query = 'SELECT MAX(`product_id`) FROM ' . hikashop_table('product'); $this->db->setQuery($query); $last_pid = (int) $this->db->loadResult(); } $last_pid++; $product->product_code = 'product_' . $last_pid; } else { $product->product_code = preg_replace('#[^a-z0-9_-]#i', '_', $product->product_name); } } } if (empty($product->product_name) && !empty($this->template->product_name)) { $product->product_name = $this->template->product_name; } if (!empty($this->translateColumns)) { foreach ($this->translateColumns as $k => $v) { if (!empty($product->{$v})) { list($name, $lng) = explode('__tr__', $v); if ($lng == $this->locale) { $product->{$name} =& $product->{$v}; } else { if (isset($this->translateLanguages[$lng])) { if (!isset($product->translations)) { $product->translations = array(); } $obj = new stdClass(); $obj->language_id = $this->translateLanguages[$lng]; $obj->reference_table = 'hikashop_product'; $obj->reference_field = $name; $obj->value =& $product->{$v}; $obj->modified_by = 0; //TODO $obj->published = 1; $product->translations[] = $obj; } } } } } $unset = array(); foreach (get_object_vars($product) as $column => $value) { if (!empty($this->columnNamesConversionTable[$column]) && is_array($this->columnNamesConversionTable[$column])) { if (!empty($this->columnNamesConversionTable[$column]['append'])) { $new_column = $this->columnNamesConversionTable[$column]['append']; if (in_array($column, array('files', 'images'))) { if (is_array($value)) { $tmp = array(); foreach ($value as $v) { $tmp[] = '<a href="' . $this->uploadFolder_url . $v . '">' . $v . '</a>'; } $value = implode(',', $tmp); } else { $value = '<a href="' . $this->uploadFolder_url . $value . '">' . $value . '</a>'; } } $trans_string = 'HIKASHOP_FEED_' . strtoupper($column); $trans = JText::_($trans_string); if ($trans_string == $trans) { $trans = $column; } $product->{$new_column} .= '<div id="hikashop_product_' . $column . '">' . $trans . ':' . $value . '</div>'; $unset[] = $column; } if (!empty($this->columnNamesConversionTable[$column]['copy'])) { $new_column = $this->columnNamesConversionTable[$column]['copy']; $product->{$new_column} = $value; } } } if ($product->product_type == 'main' && $main && !isset($product->product_parent_id)) { if (!empty($this->template->variants)) { foreach ($this->template->variants as $variant) { $copy = !HIKASHOP_PHP5 ? $variant : clone $variant; unset($copy->product_id); $copy->product_parent_id = $product->product_code; $copy->product_code = $product->product_code . '_' . $copy->product_code; $this->currentProductVariants[] = $copy; } } } if (!empty($unset)) { foreach ($unset as $u) { unset($product->{$u}); } } }
function display($field, $value, $map, $inside, $options = '', $test = false, $allFields = null, $allValues = null) { if ($field->field_options['zone_type'] != 'country' || empty($field->field_options['pleaseselect'])) { $currentZoneId = hikashop_getZone() ? hikashop_getZone() : ''; if (!empty($currentZoneId) && JFactory::getApplication()->isSite()) { $zoneClass = hikashop_get('class.zone'); $currentZone = $zoneClass->getZoneParents($currentZoneId); foreach ($currentZone as $currentZoneInfos) { if (preg_match('/country/', $currentZoneInfos)) { $defaultCountry = $currentZoneInfos; } } } } if ($field->field_options['zone_type'] == 'country') { if (isset($defaultCountry)) { $field->field_default = $defaultCountry; } if (!empty($field->field_options['pleaseselect'])) { $PleaseSelect = new stdClass(); $PleaseSelect->value = JText::_('PLEASE_SELECT_SOMETHING'); $PleaseSelect->disabled = 0; $field->field_value = array_merge(array('' => $PleaseSelect), $field->field_value); $field->field_default = ''; } $stateNamekey = str_replace('country', 'state', $field->field_namekey); if (!empty($allFields)) { foreach ($allFields as &$f) { if ($f->field_type == 'zone' && !empty($f->field_options['zone_type']) && $f->field_options['zone_type'] == 'state') { $stateNamekey = $f->field_namekey; break; } } } $stateId = str_replace(array('[', ']', $field->field_namekey), array('_', '', $stateNamekey), $map); $form_name = str_replace(array('data[', '][' . $field->field_namekey . ']'), '', $map); $changeJs = 'window.hikashop.changeState(this,\'' . $stateId . '\',\'' . $field->field_url . 'field_type=' . $form_name . '&field_id=' . $stateId . '&field_namekey=' . $stateNamekey . '&namekey=\'+this.value);'; if (!empty($options) && stripos($options, 'onchange="') !== false) { $options = preg_replace('#onchange="#i', 'onchange="' . $changeJs, $options); } else { $options = ' onchange="' . $changeJs . '"'; } if ($allFields == null || $allValues == null) { $doc = JFactory::getDocument(); $lang = JFactory::getLanguage(); $locale = strtolower(substr($lang->get('tag'), 0, 2)); $js = 'window.hikashop.ready( function() { var el = document.getElementById(\'' . $this->prefix . $field->field_namekey . $this->suffix . '\'); window.hikashop.changeState(el,\'' . $stateId . '\',\'' . $field->field_url . 'lang=' . $locale . '&field_type=' . $form_name . '&field_id=' . $stateId . '&field_namekey=' . $stateNamekey . '&namekey=\'+el.value); });'; $doc->addScriptDeclaration($js); } } elseif ($field->field_options['zone_type'] == 'state') { $stateId = str_replace(array('[', ']'), array('_', ''), $map); $dropdown = ''; if ($allFields != null) { $country = null; if (isset($defaultCountry)) { $country = $defaultCountry; } foreach ($allFields as $f) { if ($f->field_type == 'zone' && !empty($f->field_options['zone_type']) && $f->field_options['zone_type'] == 'country') { $key = $f->field_namekey; if (!empty($allValues->{$key})) { $country = $allValues->{$key}; } else { $country = $f->field_default; } break; } } if (empty($country)) { $address_country_field = $this->parent->get(14); //14 = id of country field if (!empty($address_country_field) && $address_country_field->field_type == 'zone' && !empty($address_country_field->field_options['zone_type']) && $address_country_field->field_options['zone_type'] == 'country' && !empty($address_country_field->field_default)) { $country = $address_country_field->field_default; } } if (!empty($country)) { $countryType = hikashop_get('type.country'); $countryType->field = $field; $dropdown = $countryType->displayStateDropDown($country, $stateId, $map, '', $value, $field->field_options); } else { $dropdown = '<span class="state_no_country">' . JText::_('PLEASE_SELECT_COUNTRY_FIRST') . '</span>'; } } return '<span id="' . $stateId . '_container">' . $dropdown . '</span>' . '<input type="hidden" id="' . $stateId . '_default_value" name="' . $stateId . '_default_value" value="' . $value . '"/>'; } return parent::display($field, $value, $map, $inside, $options, $test, $allFields, $allValues); }
function showcarts() { $app = JFactory::getApplication(); $config = hikashop_config(); $menus = $app->getMenu(); $menu = $menus->getActive(); global $Itemid; if (empty($menu)) { if (!empty($Itemid)) { $menus->setActive($Itemid); $menu = $menus->getItem($Itemid); } } if (is_object($menu) && is_object($menu->params)) { $cart_type = $menu->params->get('cart_type'); } if (!empty($cart_type)) { JRequest::setVar('cart_type', $cart_type); } else { $cart_type = JRequest::getString('cart_type', 'cart'); if (!in_array($cart_type, array('cart', 'wishlist'))) { $cart_type = 'cart'; } } $this->assignRef('cart_type', $cart_type); $pageInfo = new stdClass(); $pageInfo->filter = new stdClass(); $pageInfo->filter->order = new stdClass(); $pageInfo->limit = new stdClass(); $pageInfo->filter->order->value = $app->getUserStateFromRequest($this->paramBase . ".filter_order", 'filter_order', 'a.cart_id', 'cmd'); $pageInfo->filter->order->dir = $app->getUserStateFromRequest($this->paramBase . ".filter_order_Dir", 'filter_order_Dir', 'desc', 'word'); $pageInfo->search = $app->getUserStateFromRequest($this->paramBase . ".search", 'search', '', 'string'); $pageInfo->search = JString::strtolower(trim($pageInfo->search)); $pageInfo->limit->start = $app->getUserStateFromRequest($this->paramBase . '.limitstart', 'limitstart', 0, 'int'); $oldValue = $app->getUserState($this->paramBase . '.list_limit'); if (empty($oldValue)) { $oldValue = $app->getCfg('list_limit'); } $pageInfo->limit->value = $app->getUserStateFromRequest($this->paramBase . '.list_limit', 'limit', $app->getCfg('list_limit'), 'int'); if ($oldValue != $pageInfo->limit->value) { $pageInfo->limit->start = 0; $app->setUserState($this->paramBase . '.limitstart', 0); } $database = JFactory::getDBO(); $searchMap = array('a.cart_id', 'a.cart_name', 'a.cart_type'); if (hikashop_loadUser() == null) { global $Itemid; $url = ''; if (!empty($Itemid)) { $url = '&Itemid=' . $Itemid; } if (!HIKASHOP_J16) { $url = 'index.php?option=com_user&view=login' . $url; } else { $url = 'index.php?option=com_users&view=login' . $url; } if ($config->get('enable_multicart', '0')) { $app->redirect(JRoute::_($url . '&return=' . urlencode(base64_encode(hikashop_currentUrl('', false))), false)); } else { $app->redirect(JRoute::_($url . '&return=' . base64_encode(hikashop_completeLink('cart&task=showcart&cart_type=' . $cart_type . '&Itemid=' . $Itemid, false, false, true)), false)); } return false; } $user = hikashop_loadUser(true); if (isset($user->user_cms_id)) { $user->id = $user->user_cms_id; } else { if (empty($user)) { $user = new stdClass(); } $user->id = 0; } $session = JFactory::getSession(); if ($session->getId()) { $user->session = $session->getId(); } else { $user->session = ''; } if (hikashop_loadUser() == null) { $filters = array('a.session_id=' . $database->Quote($user->session) . ' AND a.cart_type =' . $database->quote($cart_type)); } else { $filters = array('(a.user_id=' . (int) $user->id . ' OR a.session_id=' . $database->Quote($user->session) . ') AND a.cart_type =' . $database->quote($cart_type)); } $groupBy = 'GROUP BY a.cart_id'; $order = ''; if (!empty($pageInfo->filter->order->value)) { $order = 'ORDER BY a.cart_id ASC'; } if (!empty($pageInfo->search)) { $searchVal = '\'%' . hikashop_getEscaped(JString::strtolower(trim($pageInfo->search)), true) . '%\''; $filter = implode(" LIKE {$searchVal} OR ", $searchMap) . " LIKE {$searchVal}"; $filters[] = $filter; } $from = 'FROM ' . hikashop_table('cart') . ' AS a'; $cartProduct = 'LEFT JOIN ' . hikashop_table('cart_product') . ' AS b ON a.cart_id=b.cart_id'; $where = 'WHERE (' . implode(') AND (', $filters) . ') AND a.cart_type =' . $database->quote($cart_type); $query = $from . ' ' . $where . ' ' . $groupBy . ' ' . $order; //'.$cartProduct.' $database->setQuery('SELECT a.* ' . $query); $rows = $database->loadObjectList(); $database->setQuery('SELECT COUNT(*) ' . $from . ' ' . $where); $currencyClass = hikashop_get('class.currency'); $this->assignRef('currencyHelper', $currencyClass); $module = hikashop_get('helper.module'); $module->initialize($this); $currencyClass = hikashop_get('class.currency'); $class = hikashop_get('class.cart'); $productClass = hikashop_get('class.product'); $main_currency = (int) $config->get('main_currency', 1); $currency_id = hikashop_getCurrency(); if ($config->get('tax_zone_type', 'shipping') == 'billing') { $zone_id = hikashop_getZone('billing'); } else { $zone_id = hikashop_getZone('shipping'); } $discount_before_tax = (int) $config->get('discount_before_tax', 0); $cids = array(); foreach ($rows as $row) { if ($row->cart_id != null) { $cids[] = $row->cart_id; } } $filters = ''; $filters = array('a.cart_id IN(' . implode(",", $cids) . ')'); $order = ''; if (!empty($pageInfo->filter->order->value)) { $order = ' ORDER BY cart_id ASC'; } $product = ' LEFT JOIN ' . hikashop_table('product') . ' AS b ON a.product_id=b.product_id'; $query = 'FROM ' . hikashop_table('cart_product') . ' AS a ' . $product . ' WHERE (' . implode(') AND (', $filters) . ') ' . $order; $database->setQuery('SELECT a.*,b.* ' . $query); if (!empty($cids)) { $products = $database->loadObjectList(); $ids = array(); foreach ($products as $row) { $ids[] = $row->product_id; } $row_1 = 0; foreach ($products as $k => $row) { $currencyClass->getPrices($row, $ids, $currency_id, $main_currency, $zone_id, $discount_before_tax); if (!isset($row->prices[0]->price_value)) { if (isset($row_1->prices[0])) { $row->prices[0] = $row_1->prices[0]; } } $products[$k]->hide = 0; if ($row->product_type == 'variant') { $l = --$k; if (isset($products[$l])) { if (!isset($products[$l]) || !is_object($products[$l])) { $products[$l] = new stdClass(); } $products[$l]->hide = 1; } } $row_1 = $row; } $currentId = 0; $values = null; $price = 0; $price_with_tax = 0; $quantity = 0; $currency = hikashop_getCurrency(); foreach ($products as $product) { if (isset($product->cart_id) && isset($product->product_id)) { if ($product->cart_id != $currentId) { $price = 0; $price_with_tax = 0; $quantity = 0; $currentId = $product->cart_id; if (isset($product->prices[0]->price_currency_id)) { $currency = $product->prices[0]->price_currency_id; } } if (isset($product->prices[0])) { $price += $product->cart_product_quantity * $product->prices[0]->price_value; } if (isset($product->prices[0]->price_value_with_tax)) { $price_with_tax += $product->cart_product_quantity * $product->prices[0]->price_value_with_tax; } if (!isset($product->prices[0]->price_value)) { $variant = new stdClass(); $variant->product_parent_id = $product->product_parent_id; $variant->quantity = $product->cart_product_quantity; } if (isset($variant) && isset($product->prices[0]) && $product->product_id == $variant->product_parent_id) { $price += $variant->quantity * $product->prices[0]->price_value; $price_with_tax += $variant->quantity * $product->prices[0]->price_value_with_tax; } $quantity += $product->cart_product_quantity; if (!isset($values[$currentId])) { $values[$currentId] = new stdClass(); } $values[$currentId]->price = $price; $values[$currentId]->price_with_tax = isset($price_with_tax) ? $price_with_tax : $price; $values[$currentId]->quantity = $quantity; $values[$currentId]->currency = $currency; } } $totalCart = 0; $limit = 0; foreach ($rows as $k => $row) { if ($limit >= (int) $pageInfo->limit->start && $limit < (int) $pageInfo->limit->value && isset($values[$row->cart_id]) && $values[$row->cart_id] != null) { $rows[$k]->price = $values[$row->cart_id]->price; $rows[$k]->price_with_tax = $values[$row->cart_id]->price_with_tax; $rows[$k]->quantity = $values[$row->cart_id]->quantity; $rows[$k]->currency = $values[$row->cart_id]->currency; $totalCart++; } else { unset($rows[$k]); $limit--; } $limit++; } } $pageInfo->elements = new stdClass(); $pageInfo->elements->total = count($rows); if (!empty($pageInfo->search)) { $rows = hikashop_search($pageInfo->search, $rows, 'cart_id'); } $pageInfo->elements->page = count($rows); if (!$pageInfo->elements->page) { if (hikashop_loadUser() != null) { $app = JFactory::getApplication(); if ($cart_type == 'cart') { $app->enqueueMessage(JText::_('HIKA_NO_CARTS_FOUND')); } else { $app->enqueueMessage(JText::_('HIKA_NO_WISHLISTS_FOUND')); } } } jimport('joomla.html.pagination'); $pagination = hikashop_get('helper.pagination', $pageInfo->elements->total, $pageInfo->limit->start, $pageInfo->limit->value); $pagination->hikaSuffix = ''; $this->assignRef('pagination', $pagination); $this->assignRef('pageInfo', $pageInfo); $cart = hikashop_get('helper.cart'); $this->assignRef('cart', $cart); $this->assignRef('config', $config); $this->assignRef('carts', $rows); if ($cart_type == 'cart') { $title = JText::_('CARTS'); } else { $title = JText::_('WISHLISTS'); } hikashop_setPageTitle($title); }
function onProcessProductMassFiltercsvImport(&$elements, &$query, $filter, $num) { if (empty($filter['type']) || $filter['type'] == 'all') { return; } if (!isset($this->massaction)) { $this->massaction = hikashop_get('class.massaction'); } if (count($elements)) { foreach ($elements as $k => $element) { if ($element->{$filter}['type'] != $filter['value']) { unset($elements[$k]); } } } else { $data = $this->massaction->getFromFile($filter); if (empty($data->ids) || is_null($data->ids) || isset($data->error)) { $query->where[] = '1=2'; return false; } JArrayHelper::toInteger($data->ids); $db = JFactory::getDBO(); $productClass = hikashop_get('class.product'); $productClass->getProducts($data->ids); $pool = array(); foreach ($data->ids as $i => $id) { if (!isset($data->elements[$id]->product_id) || !isset($data->elements[$id]->product_code) || !isset($data->elements[$id]->product_parent_id)) { continue; } $pool[$data->elements[$id]->product_code] = array(); $pool[$data->elements[$id]->product_code]['id'] = $data->elements[$id]->product_id; $pool[$data->elements[$id]->product_code]['parent_id'] = $data->elements[$id]->product_parent_id; } $toGet = array(); foreach ($data->ids as $i => $id) { if (isset($data->elements[$id]->product_parent_id) && $data->elements[$id]->product_parent_id != '' && (int) $data->elements[$id]->product_parent_id == 0 && !in_array($data->elements[$id]->product_parent_id, $pool) && !in_array($data->elements[$id]->product_parent_id, $toGet)) { $toGet[] = $data->elements[$id]->product_parent_id; } } $db->setQuery('SELECT * FROM ' . hikashop_table('product') . ' WHERE product_code IN (\'' . implode('\',\'', $toGet) . '\')'); $gets = $db->loadObjectList(); foreach ($gets as $get) { $pool[$get->product_code]['id'] = $get->product_id; $pool[$get->product_code]['parent_id'] = $get->product_parent_id; } if (!is_array($data->ids)) { $data->ids = array($data->ids); } foreach ($data->ids as $i => $id) { if (!isset($data->elements[$id])) { continue; } $data->elements[$id]->product_id = (int) $data->elements[$id]->product_id; if (isset($data->elements[$id]->product_type) && $data->elements[$id]->product_type == 'variant' && (int) $data->elements[$id]->product_parent_id == 0) { if (array_key_exists($data->elements[$id]->product_parent_id, $pool)) { $data->elements[$id]->product_parent_id = $pool[$data->elements[$id]->product_parent_id]['id']; } else { continue; } } $oldElement = $productClass->all_products[$id]; if (!empty($data->elements[$id]->price_value_with_tax)) { $currencyHelper = hikashop_get('class.currency'); if (empty($data->elements[$id]->product_tax_id)) { if (!empty($oldElement->product_tax_id)) { $data->elements[$id]->product_tax_id = $oldElement->product_tax_id; } else { $data->elements[$id]->product_tax_id = $currencyHelper->getTaxCategory(); } } if ($data->elements[$id]->product_tax_id) { if (strpos($data->elements[$id]->price_value_with_tax, '|') === false) { $data->elements[$id]->price_value = $currencyHelper->getUntaxedPrice(hikashop_toFloat($data->elements[$id]->price_value_with_tax), hikashop_getZone(), $data->elements[$id]->product_tax_id); } else { $price_value = explode('|', $data->elements[$id]->price_value_with_tax); foreach ($price_value as $k => $price_value_one) { $price_value[$k] = $currencyHelper->getUntaxedPrice($price_value_one, hikashop_getZone(), $data->elements[$id]->product_tax_id); } $data->elements[$id]->price_value = implode('|', $price_value); } } unset($data->elements[$id]->price_value_with_tax); } if (!empty($data->elements[$id]->price_value)) { $data->elements[$id]->prices = array(); $price_values = explode('|', $data->elements[$id]->price_value); $price_currencies = explode('|', $data->elements[$id]->price_currency_id); $nbPrices = count($price_values) - 1; if (!isset($data->elements[$id]->price_min_quantity)) { $data->elements[$id]->price_min_quantity = '1'; if ($nbPrices) { $data->elements[$id]->price_min_quantity = $data->elements[$id]->price_min_quantity . str_repeat('|1', $nbPrices); } } if (!isset($data->elements[$id]->price_access)) { $data->elements[$id]->price_access = 'all'; if ($nbPrices) { $data->elements[$id]->price_access = $data->elements[$id]->price_access . str_repeat('|all', $nbPrices); } } $price_min_quantities = explode('|', $data->elements[$id]->price_min_quantity); $price_accesses = explode('|', $data->elements[$id]->price_access); foreach ($price_values as $k => $price_value) { $data->elements[$id]->prices[$k] = new stdClass(); $data->elements[$id]->prices[$k]->price_value = $price_value; } foreach ($price_currencies as $k => $price_currency) { if (!is_int($price_currency)) { $db->setQuery('SELECT currency_id FROM ' . hikashop_table('currency') . ' WHERE currency_code LIKE ' . $db->quote($price_currency)); $price_currency_id = $db->loadResult(); } $data->elements[$id]->prices[$k]->price_currency_id = $price_currency_id; } foreach ($price_min_quantities as $k => $price_min_quantity) { $data->elements[$id]->prices[$k]->price_min_quantity = $price_min_quantity; } foreach ($price_accesses as $k => $price_access) { $data->elements[$id]->prices[$k]->price_access = $price_access; } } unset($data->elements[$id]->price_value); unset($data->elements[$id]->price_currency_id); unset($data->elements[$id]->price_min_quantity); unset($data->elements[$id]->price_access); if (!empty($data->elements[$id]->files)) { $newFiles = explode(';', $data->elements[$id]->files); $data->elements[$id]->files = array(); foreach ($newFiles as $k => $newFile) { $same = 0; foreach ($oldElement->files as $oldFile) { if ($oldFile->file_path == $newFile) { $data->elements[$id]->files[] = $oldFile->file_id; $same = 1; } } if (!empty($newFile) && $same == 0) { $db->setQuery('SELECT file_id FROM ' . hikashop_table('file') . ' WHERE file_path LIKE ' . $db->quote($newFile)); $newFileId = $db->loadResult(); if (!empty($newFileId)) { $data->elements[$id]->files[] = $newFileId; } } } } if (!empty($data->elements[$id]->images)) { $newImages = explode(';', $data->elements[$id]->images); $data->elements[$id]->images = array(); foreach ($newImages as $k => $newImage) { $same = 0; foreach ($oldElement->images as $oldImage) { if (!empty($newImage) && $oldImage->file_path == $newImage) { $data->elements[$id]->images[] = $oldImage->file_id; $same = 1; } } if (!empty($newImage) && $same == 0) { $db->setQuery('SELECT file_id FROM ' . hikashop_table('file') . ' WHERE file_path LIKE ' . $db->quote($newImage)); $newImageId = $db->loadResult(); if (!empty($newImageId)) { $data->elements[$id]->images[] = $newImageId; } } } } if (!empty($data->elements[$id]->categories)) { $categories = explode(';', $data->elements[$id]->categories); $data->elements[$id]->categories = array(); foreach ($categories as $category) { $db->setQuery('SELECT category_id FROM ' . hikashop_table('category') . ' WHERE category_name LIKE ' . $db->quote($category)); $data->elements[$id]->categories[] = $db->loadResult(); } } if (!empty($data->elements[$id]->categories_ordering)) { $data->elements[$id]->categories_ordering = explode(';', $data->elements[$id]->categories_ordering); unset($oldElement->categories_ordering); } if (!empty($data->elements[$id]->related)) { $relateds = explode(';', $data->elements[$id]->related); $data->elements[$id]->related = array(); foreach ($relateds as $k => $related) { $db->setQuery('SELECT product_id FROM ' . hikashop_table('product') . ' WHERE product_code LIKE ' . $db->quote($related)); $data->elements[$id]->related[$k]->product_related_id = $db->loadResult(); $data->elements[$id]->related[$k]->product_id = $id; $data->elements[$id]->related[$k]->product_related_ordering = $k; $data->elements[$id]->related[$k]->product_related_type = 'related'; } } if (!empty($data->elements[$id]->options)) { $options = explode(';', $data->elements[$id]->options); $data->elements[$id]->options = array(); foreach ($options as $option) { $db->setQuery('SELECT product_id FROM ' . hikashop_table('product') . ' WHERE product_code LIKE ' . $db->quote($option)); $data->elements[$id]->options[$k]->product_related_id = $db->loadResult(); $data->elements[$id]->options[$k]->product_id = $id; $data->elements[$id]->options[$k]->product_related_ordering = $k; $data->elements[$id]->options[$k]->product_related_type = 'related'; } } unset($oldElement->images); unset($oldElement->files); unset($oldElement->related); unset($oldElement->options); foreach ($oldElement as $k => $old) { foreach ($data->elements[$id] as $l => $new) { if ($k == $l) { $oldElement->{$k} = $new; } } } $data->elements[$id] = $oldElement; if (isset($filter['save'])) { if (isset($data->elements[$id]->prices)) { $productClass->updatePrices($data->elements[$id], $id); } if ($data->elements[$id]->product_type != 'variant') { $productClass->updateCategories($data->elements[$id], $id); } if (!empty($data->elements[$id]->files)) { $productClass->updateFiles($data->elements[$id], $id, 'files'); } if (!empty($data->elements[$id]->images)) { $productClass->updateFiles($data->elements[$id], $id, 'images'); } if (!empty($data->elements[$id]->related)) { $productClass->updateRelated($data->elements[$id], $id, 'related'); } if (!empty($data->elements[$id]->options)) { $productClass->updateRelated($data->elements[$id], $id, 'options'); } unset($oldElement->categories); $db->setQuery('SHOW columns FROM ' . hikashop_table('product')); $cols = $db->loadObjectList(); $fields = array(); foreach ($cols as $col) { $fields[] = $col->Field; } foreach ($data->elements[$id] as $l => $content) { if (!in_array($l, $fields)) { unset($data->elements[$id]->{$l}); } } if (isset($data->elements[$id]->product_created) && (int) $data->elements[$id]->product_created == 0) { unset($data->elements[$id]->product_created); } $data->elements[$id]->product_modified = time(); $data->elements[$id]->product_width = str_replace($data->elements[$id]->product_dimension_unit, '', $data->elements[$id]->product_width); $data->elements[$id]->product_length = str_replace($data->elements[$id]->product_dimension_unit, '', $data->elements[$id]->product_length); $data->elements[$id]->product_height = str_replace($data->elements[$id]->product_dimension_unit, '', $data->elements[$id]->product_height); $elements = $data->elements; $productClass->save($elements[$id]); } } $elements = $data->elements; if ($filter['type'] == 'out') { JArrayHelper::toInteger($data->ids); $db->setQuery('SELECT product_id FROM ' . hikashop_table('product') . ' WHERE product_id NOT IN (' . implode(',', $data->ids) . ')'); $ids = $db->loadResultArray(); $productClass = hikashop_get('class.product'); $elements = array(); foreach ($ids as $id) { $elements[] = $productClass->get($id); } } } return 'onProcessProductMassFiltercsvImport called'; }
function onAfterRender() { $app = JFactory::getApplication(); if ($app->isAdmin()) { return true; } $layout = JRequest::getString('layout'); if ($layout == 'edit') { return true; } $body = JResponse::getBody(); $alternate_body = false; if (empty($body)) { $body = $app->getBody(); $alternate_body = true; } $search_space = substr($body, strpos($body, '<body')); if (!(preg_match_all('#\\{product\\}(.*)\\{\\/product\\}#Uis', $search_space, $matches) || preg_match_all('#\\{product (.*)\\}#Uis', $search_space, $matches))) { return; } if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } if (!(include_once rtrim(JPATH_ADMINISTRATOR, DS) . DS . 'components' . DS . 'com_hikashop' . DS . 'helpers' . DS . 'helper.php')) { return true; } $db = JFactory::getDBO(); $currencyClass = hikashop_get('class.currency'); $this->image = hikashop_get('helper.image'); $this->classbadge = hikashop_get('class.badge'); $para = array(); $nbtag = count($matches[1]); for ($i = 0; $i < $nbtag; $i++) { $para[$i] = explode('|', $matches[1][$i]); } $k = 0; $ids = array(); for ($i = 0; $i < $nbtag; $i++) { for ($u = 0; $u < count($para[$i]); $u++) { if (in_array($para[$i][$u], array('name', 'pricetax', 'pricedis', 'cart', 'quantityfield', 'description', 'link', 'border', 'badge', 'picture'))) { continue; } $ids[$k] = (int) $para[$i][$u]; $k++; } } $product_query = 'SELECT * FROM ' . hikashop_table('product') . ' WHERE product_id IN (' . implode(',', $ids) . ') AND product_access=\'all\' AND product_published=1 AND product_type=\'main\''; $db->setQuery($product_query); $products = $db->loadObjectList(); $db->setQuery('SELECT * FROM ' . hikashop_table('variant') . ' WHERE variant_product_id IN (' . implode(',', $ids) . ')'); $variants = $db->loadObjectList(); if (!empty($variants)) { foreach ($products as $k => $product) { foreach ($variants as $variant) { if ($product->product_id == $variant->variant_product_id) { $products[$k]->has_options = true; break; } } } } $db->setQuery('SELECT product_id FROM ' . hikashop_table('product_related') . ' WHERE product_related_type = ' . $db->quote('options') . ' AND product_id IN (' . implode(',', $ids) . ')'); $options = $db->loadObjectList(); if (!empty($options)) { foreach ($products as $k => $product) { foreach ($options as $option) { if ($product->product_id == $option->product_id) { $products[$k]->has_options = true; break; } } } } foreach ($products as $k => $product) { $this->classbadge->loadBadges($products[$k]); } $queryImage = 'SELECT * FROM ' . hikashop_table('file') . ' WHERE file_ref_id IN (' . implode(',', $ids) . ') AND file_type=\'product\' ORDER BY file_ordering ASC, file_id ASC'; $db->setQuery($queryImage); $images = $db->loadObjectList(); $productClass = hikashop_get('class.product'); foreach ($products as $k => $row) { $productClass->addAlias($products[$k]); foreach ($images as $j => $image) { if ($row->product_id != $image->file_ref_id) { continue; } foreach (get_object_vars($image) as $key => $name) { if (!isset($products[$k]->images)) { $products[$k]->images = array(); } if (!isset($products[$k]->images[$j])) { $products[$k]->images[$j] = new stdClass(); } $products[$k]->images[$j]->{$key} = $name; } } } $zone_id = hikashop_getZone(); $currencyClass = hikashop_get('class.currency'); $config = hikashop_config(); $defaultParams = $config->get('default_params'); $currencyClass->getListingPrices($products, $zone_id, hikashop_getCurrency(), $defaultParams['price_display_type']); $fields = array('name' => 'name', 'pricedis1' => 'pricedis', 'pricedis2' => array('pricedis', 2), 'pricedis3' => array('pricedis', 3), 'pricetax1' => 'pricetax', 'pricetax2' => array('pricetax', 2), 'price' => 'price', 'cart' => 'cart', 'quantityfield' => 'quantityfield', 'description' => 'description', 'picture' => 'picture', 'link' => 'link', 'border' => 'border', 'badge' => 'badge'); for ($i = 0; $i < $nbtag; $i++) { $nbprodtag = count($para[$i]); foreach ($fields as $k => $v) { if (is_string($v)) { $this->{$v} = 0; } if (in_array($k, $para[$i])) { if (is_array($v)) { $this->{$v[0]} = $v[1]; } else { $this->{$v} = 1; } $nbprodtag--; } } $this->menuid = 0; foreach ($para[$i] as $key => $value) { if (substr($value, 0, 6) == "menuid") { $explode = explode(':', $value); $this->menuid = $explode[1]; } } $id = array(); for ($j = 0; $j < $nbprodtag; $j++) { $id[$j] = $para[$i][$j]; } $name = 'hikashopproductinsert_view.php'; $path = JPATH_THEMES . DS . $app->getTemplate() . DS . 'system' . DS . $name; if (!file_exists($path)) { if (version_compare(JVERSION, '1.6', '<')) { $path = JPATH_PLUGINS . DS . 'system' . DS . $name; } else { $path = JPATH_PLUGINS . DS . 'system' . DS . 'hikashopproductinsert' . DS . $name; } if (!file_exists($path)) { return true; } } ob_start(); require $path; $product_view = ob_get_clean(); $pattern = '#\\{product\\}(.*)\\{\\/product\\}#Uis'; $replacement = ''; $body = JResponse::getBody(); $alternate_body = false; if (empty($body)) { $body = $app->getBody(); $alternate_body = true; } $search_space = substr($body, strpos($body, '<body')); $new_search_space = preg_replace($pattern, str_replace('$', '\\$', $product_view), $search_space, 1); $pattern = '#\\{product (.*)\\}#Uis'; $replacement = ''; $new_search_space = preg_replace($pattern, str_replace('$', '\\$', $product_view), $new_search_space, 1); $body = str_replace($search_space, $new_search_space, $body); if ($alternate_body) { $app->setBody($body); } else { JResponse::setBody($body); } } }
function getOrderZones(&$order) { $field = 'address_country'; $fieldClass = hikashop_get('class.field'); $fields = $fieldClass->getData('frontcomp', 'address'); if (isset($fields['address_state']) && $fields['address_state']->field_type == 'zone' && !empty($order->shipping_address) && !empty($order->shipping_address->address_state) && (!is_array($order->shipping_address->address_state) || count($order->shipping_address->address_state) > 1 || !empty($order->shipping_address->address_state[0]))) { $field = 'address_state'; } $type = 'shipping_address'; if (empty($order->shipping_address) && !empty($order->billing_address)) { $type = 'billing_address'; } if (empty($order->{$type}) || empty($order->{$type}->{$field})) { $zones = $this->getZoneParents(hikashop_getZone()); } else { $zones =& $order->{$type}->{$field}; if (!is_array($zones)) { $zones = array($zones); } } return $zones; }
static function store($config, $item) { $html = '<div class="nspHikashopBlock">'; // if (!(include_once rtrim(JPATH_ADMINISTRATOR, DS) . DS . 'components' . DS . 'com_hikashop' . DS . 'helpers' . DS . 'helper.php')) { return true; } $app = JFactory::getApplication(); $currencyHelper = hikashop_get('class.currency'); $taxed_price = $currencyHelper->getTaxedPrice($item['price'], hikashop_getZone(), $item['tax_id']); $mainCurr = $currencyHelper->mainCurrency(); $currCurrency = $app->getUserState(HIKASHOP_COMPONENT . '.currency_id', $mainCurr); $msrpCurrencied = $currencyHelper->convertUniquePrice($taxed_price, $mainCurr, $currCurrency); if ($msrpCurrencied == $taxed_price) { $html .= '<span>' . $currencyHelper->format($taxed_price, $mainCurr) . '</span>'; } else { $html .= '<span>' . $currencyHelper->format($msrpCurrencied, $currCurrency) . ' (' . $currencyHelper->format($taxed_price, $mainCurr) . ')' . '</span>'; } if ($config['hikashop_add_to_cart'] > 0) { if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } include_once rtrim(JPATH_ADMINISTRATOR, DS) . DS . 'components' . DS . 'com_hikashop' . DS . 'helpers' . DS . 'helper.php'; JHTML::_('behavior.framework'); $hs_config = hikashop_config(); $productClass = hikashop_get('class.product'); $_SESSION['hikashop_product'] = $productClass->get($item['id']); $params = new JRegistry(''); // enable quantity field if ($config['hikashop_add_to_cart'] == 2) { $params->set('show_quantity_field', 1); } else { $params->set('show_quantity_field', 0); } $params->set('price_with_tax', $hs_config->get('price_with_tax', 1)); $params->set('add_to_cart', 1); $js = ''; $html .= hikashop_getLayout('product', 'add_to_cart_listing', $params, $js); } $html .= '</div>'; return $html; }
function display($tpl = null) { global $mainframe; global $Itemid; $db = JFactory::getDBO(); $app = JFactory::getApplication(); $this->params = $app->getParams(); $doc = JFactory::getDocument(); $menus = $app->getMenu(); $menu = $menus->getActive(); $config =& hikashop_config(); if (empty($menu) && !empty($Itemid)) { $menus->setActive($Itemid); $menu = $menus->getItem($Itemid); } $myItem = empty($Itemid) ? '' : '&Itemid=' . $Itemid; if (is_object($menu)) { jimport('joomla.html.parameter'); $menuparams = new HikaParameter($menu->params); } $query = 'SELECT * FROM ' . hikashop_table('product') . ' WHERE product_access=\'all\' AND product_published=1 AND product_type=\'main\' '; if (!$config->get('show_out_of_stock', 1)) { $query .= ' AND product_quantity!=0 '; } $query .= ' ORDER BY ' . $config->get('hikarss_order', 'product_id') . ' DESC'; $query .= ' LIMIT ' . $config->get('hikarss_element', '10'); $db->setQuery($query); $products = $db->loadObjectList(); if (!empty($products)) { $ids = array(); $productClass = hikashop_get('class.product'); foreach ($products as $key => $row) { $ids[] = $row->product_id; $productClass->addAlias($products[$key]); } $queryCategoryId = 'SELECT * FROM ' . hikashop_table('product_category') . ' WHERE product_id IN (' . implode(',', $ids) . ')'; $db->setQuery($queryCategoryId); $categoriesId = $db->loadObjectList(); foreach ($products as $k => $row) { foreach ($categoriesId as $catId) { if ($row->product_id == $catId->product_id) { $products[$k]->categories_id[0] = $catId->category_id; } } } $queryImage = 'SELECT * FROM ' . hikashop_table('file') . ' WHERE file_ref_id IN (' . implode(',', $ids) . ') AND file_type=\'product\' ORDER BY file_ref_id ASC, file_ordering ASC, file_id ASC'; $db->setQuery($queryImage); $images = $db->loadObjectList(); foreach ($products as $k => $row) { foreach ($images as $image) { if ($row->product_id == $image->file_ref_id) { foreach (get_object_vars($image) as $key => $name) { if (empty($products[$k]->images)) { $products[$k]->images = array(); } if (empty($products[$k]->images[0])) { $products[$k]->images[0] = new stdClass(); } $products[$k]->images[0]->{$key} = $name; } break; } } } $db->setQuery('SELECT * FROM ' . hikashop_table('variant') . ' WHERE variant_product_id IN (' . implode(',', $ids) . ')'); $variants = $db->loadObjectList(); if (!empty($variants)) { foreach ($products as $k => $product) { foreach ($variants as $variant) { if ($product->product_id == $variant->variant_product_id) { $products[$k]->has_options = true; break; } } } } } else { return true; } $zone_id = hikashop_getZone(); $currencyClass = hikashop_get('class.currency'); $config =& hikashop_config(); $main_currency = (int) $config->get('main_currency', 1); $currencyClass->getListingPrices($products, $zone_id, $main_currency, 'cheapest'); $uploadFolder = ltrim(JPath::clean(html_entity_decode($config->get('uploadfolder'))), DS); $uploadFolder = rtrim($uploadFolder, DS) . DS; $this->uploadFolder_url = str_replace(DS, '/', $uploadFolder); $this->uploadFolder = JPATH_ROOT . DS . $uploadFolder; $app = JFactory::getApplication(); $this->thumbnail = $config->get('thumbnail', 1); $this->thumbnail_y = $config->get('product_image_y', $config->get('thumbnail_y')); $this->thumbnail_x = $config->get('product_image_x', $config->get('thumbnail_x')); $this->main_thumbnail_x = $this->thumbnail_x; $this->main_thumbnail_y = $this->thumbnail_y; $this->main_uploadFolder_url = $this->uploadFolder_url; $this->main_uploadFolder = $this->uploadFolder; $doc_description = $config->get('hikarss_description', ''); $doc_title = $config->get('hikarss_name', ''); if (!empty($doc_title)) { $doc->title = $doc_title; } if (!empty($doc_description)) { $doc->description = $doc_description; } $imageHelper = hikashop_get('helper.image'); foreach ($products as $product) { $title = $this->escape($product->product_name); $title = html_entity_decode($title); $pathway_sef_name = $config->get('pathway_sef_name', 'category_pathway'); $link = JURI::base() . 'index.php?option=com_hikashop&ctrl=product&task=show&cid=' . $product->product_id . '&name=' . $product->alias . '&Itemid=' . $Itemid . '&' . $pathway_sef_name . '=' . @$product->category_id; if (!empty($product->prices) && $product->prices[0]->price_value_with_tax != 0) { $desc = $product->product_description . JText::_('CART_PRODUCT_PRICE') . ' : ' . $currencyClass->format($product->prices[0]->price_value_with_tax, $product->prices[0]->price_currency_id); } else { $desc = $product->product_description . JText::_('FREE_PRICE'); } $desc = preg_replace('#<hr *id="system-readmore" */>#i', '', $desc); $image_options = array('default' => true); $img = $imageHelper->getThumbnail(@$product->images[0]->file_path, array('width' => $imageHelper->main_thumbnail_x, 'height' => $imageHelper->main_thumbnail_y), $image_options); if (substr($img->url, 0, 3) == '../') { $image = str_replace('../', HIKASHOP_LIVE, $img->url); } else { $image = substr(HIKASHOP_LIVE, 0, strpos(HIKASHOP_LIVE, '/', 9)) . $img->url; } $description = '<table><tr><td><img src="' . $image . '"/></td><td>' . $desc . '</td></tr></table>'; $item = new JFeedItem(); $item->title = $title; $item->link = $link; $item->description = $description; $item->date = $product->product_created; $item->category = @$product->category_id; $doc->addItem($item); } }
function _loadPrices(&$rows) { $currencyClass = hikashop_get('class.currency'); $zone_id = hikashop_getZone(); $ids = array(); foreach ($rows as $row) { $ids[] = (int) $row->product_id; } $query = 'SELECT * FROM ' . hikashop_table('price') . ' WHERE price_product_id IN (' . implode(',', $ids) . ')'; $database = JFactory::getDBO(); $database->setQuery($query); $prices = $database->loadObjectList(); if (!empty($prices)) { foreach ($rows as $k => $row) { foreach ($prices as $price) { if ($price->price_product_id == $row->product_id) { if (!isset($row->prices)) { $row->prices = array(); } $rows[$k]->prices[$price->price_min_quantity] = $price; $rows[$k]->prices[$price->price_min_quantity]->price_value_with_tax = $currencyClass->getTaxedPrice($price->price_value, $zone_id, $row->product_tax_id); } } } } }
function getPriceSelect($price_table = 'b', $product_table = 'b') { $case = ' case'; $currentCurrency = hikashop_getCurrency(); $unitType = $price_table . '.price_value'; $currencyType = hikashop_get('type.currency'); $currencyClass = hikashop_get('class.currency'); $dstCurrency = $currencyClass->get($currentCurrency); $currencyType->load(0); $currencies = $currencyType->currencies; $config =& hikashop_config(); $main_currency = $config->get('main_currency', 1); if ($config->get('price_with_tax')) { $categoryClass = hikashop_get('class.category'); $main = 'tax'; $categoryClass->getMainElement($main); $tax_categories = $categoryClass->getChildren($main); $taxes = array(); foreach ($tax_categories as $tax_category) { $taxes[$tax_category->category_id] = (double) $currencyClass->getTax(hikashop_getZone(), $tax_category->category_id); } $taxes[0] = 0; } foreach ($currencies as $currency) { $calculatedVal = $unitType; if ($main_currency != $currency->currency_id) { if (bccomp($currency->currency_percent_fee, 0, 2)) { $calculatedVal = '(' . $calculatedVal . '*' . floatval($currency->currency_percent_fee + 100) / 100.0 . ')'; } $calculatedVal = '(' . $calculatedVal . '/' . floatval($currency->currency_rate) . ')'; } if ($main_currency != $currentCurrency) { $calculatedVal = '(' . $calculatedVal . '*' . floatval($dstCurrency->currency_rate) . ')'; if (bccomp($dstCurrency->currency_percent_fee, 0, 2)) { $calculatedVal = '(' . $calculatedVal . '*' . floatval($dstCurrency->currency_percent_fee + 100) / 100.0 . ')'; } } else { $case .= ' when ' . $price_table . '.price_currency_id IS NULL then 0'; } if (!empty($taxes)) { $ids = array(); foreach ($taxes as $id => $tax) { if ($id != 0) { $ids[] = $id; $case .= ' when ' . $price_table . '.price_currency_id = \'' . $currency->currency_id . '\' and ' . $product_table . '.product_tax_id = \'' . $id . '\' then ' . $calculatedVal . '+' . $calculatedVal . '*' . $tax; } } $case .= ' when ' . $price_table . '.price_currency_id = \'' . $currency->currency_id . '\' and ' . $product_table . '.product_tax_id NOT IN (\'' . implode('\',\'', $ids) . '\') then ' . $calculatedVal; } else { $case .= ' when ' . $price_table . '.price_currency_id = \'' . $currency->currency_id . '\' then ' . $calculatedVal; } } $case .= ' end '; return $case; }
function quantityPrice(&$price, $quantity) { if ($quantity > 0) { $currencyHelper = hikashop_get('class.currency'); if (empty($price->unit_price)) { $price->unit_price = new stdClass(); } $price->unit_price->price_currency_id = $price->price_currency_id; $rounding = $currencyHelper->getRounding($price->price_currency_id); if (empty($this->product->product_tax_id)) { $class = hikashop_get('class.product'); $data = $class->get(@$this->product->product_id); if (empty($data->product_tax_id) && $data->product_type == "variant") { $data = $class->get(@$data->product_parent_id); } $this->product->product_tax_id = @$data->product_tax_id; } if (isset($price->price_orig_currency_id)) { $price->unit_price->price_orig_currency_id = $price->price_orig_currency_id; } if (isset($price->price_value_without_discount)) { $price->unit_price->price_value_without_discount = round($price->price_value_without_discount, $rounding); $price->price_value_without_discount = round($price->unit_price->price_value_without_discount * $quantity, $rounding); } if (isset($price->price_value)) { $price->unit_price->price_value = round($price->price_value, $rounding); $price->price_value = round($price->unit_price->price_value * $quantity, $rounding); } if (isset($price->price_orig_value)) { $price->unit_price->price_orig_value = round($price->price_orig_value, $rounding); $price->price_orig_value = round($price->unit_price->price_orig_value * $quantity, $rounding); } if (isset($price->price_orig_value_with_tax)) { $price->unit_price->price_orig_value_with_tax = round($price->price_orig_value_with_tax, $rounding); $price_quantity = $price->unit_price->price_orig_value * $quantity; $price->price_orig_value_with_tax = $currencyHelper->getTaxedPrice($price_quantity, hikashop_getZone(), $this->product->product_tax_id, $rounding); } if (isset($price->price_orig_value_without_discount)) { $price->unit_price->price_orig_value_without_discount = round($price->price_orig_value_without_discount, $rounding); $price->price_orig_value_without_discount = round($price->unit_price->price_orig_value_without_discount * $quantity, $rounding); } if (isset($price->price_value_without_discount_with_tax)) { $price->unit_price->price_value_without_discount_with_tax = round($price->price_value_without_discount_with_tax, $rounding); $price_quantity = $price->unit_price->price_value_without_discount * $quantity; $price->price_value_without_discount_with_tax = $currencyHelper->getTaxedPrice($price_quantity, hikashop_getZone(), $this->product->product_tax_id, $rounding); } if (isset($price->price_value_with_tax)) { $price->unit_price->price_value_with_tax = round($price->price_value_with_tax, $rounding); $price_quantity = $price->unit_price->price_value * $quantity; $price->price_value_with_tax = $currencyHelper->getTaxedPrice($price_quantity, hikashop_getZone(), $this->product->product_tax_id, $rounding); } if (isset($price->taxes)) { $price->unit_price->taxes = array(); foreach ($price->taxes as $k => $tax) { $price->unit_price->taxes[$k] = clone $tax; $price_quantity = $price->unit_price->price_value * $quantity; $price->taxes[$k]->tax_amount = $currencyHelper->getTaxedPrice($price_quantity, hikashop_getZone(), $this->product->product_tax_id, 7) - $price->unit_price->price_value * $quantity; } } if (isset($price->taxes_without_discount)) { $price->unit_price->taxes_without_discount = array(); foreach ($price->taxes_without_discount as $k => $tax) { $price->unit_price->taxes_without_discount[$k] = clone $tax; $price_quantity = $price->unit_price->price_value_without_discount * $quantity; $price->taxes_without_discount[$k]->tax_amount = $currencyHelper->getTaxedPrice($price_quantity, hikashop_getZone(), $this->product->product_tax_id, 7) - $price->unit_price->price_value_without_discount * $quantity; } } } }