From 72db492507f5fb53005a7388de81ef720a2d372a Mon Sep 17 00:00:00 2001 From: Chris Brown Date: Wed, 3 Apr 2024 08:47:53 -0400 Subject: [PATCH] Product class Centralizes all basic product-related querying and overriding. (Not including attributes or pricing.) Closes #6367 The easiest override/notifier hook is now `NOTIFY_GET_PRODUCT_OBJECT_DETAILS` --- includes/classes/Product.php | 303 ++++++++++++++++++ includes/classes/shopping_cart.php | 14 +- includes/functions/functions_products.php | 128 +++----- includes/modules/also_purchased_products.php | 68 ++-- includes/modules/featured_products.php | 126 ++++---- includes/modules/new_products.php | 4 +- .../document_general_info/header_php.php | 6 +- .../main_template_vars.php | 16 +- .../document_product_info/header_php.php | 6 +- .../main_template_vars.php | 16 +- .../product_free_shipping_info/header_php.php | 6 +- .../main_template_vars.php | 16 +- .../modules/pages/product_info/header_php.php | 6 +- .../pages/product_info/main_template_vars.php | 20 +- .../pages/product_music_info/header_php.php | 6 +- .../product_music_info/main_template_vars.php | 16 +- includes/modules/product_listing.php | 9 +- .../responsive_classic/product_listing.php | 9 +- includes/modules/sideboxes/best_sellers.php | 2 + includes/modules/specials_index.php | 99 +++--- includes/modules/upcoming_products.php | 75 +++-- includes/psr4Autoload.php | 1 + .../sideboxes/tpl_reviews_random.php | 14 +- .../sideboxes/tpl_featured.php | 21 +- .../sideboxes/tpl_reviews_random.php | 14 +- .../sideboxes/tpl_specials.php | 21 +- .../sideboxes/tpl_whats_new.php | 22 +- 27 files changed, 687 insertions(+), 357 deletions(-) create mode 100644 includes/classes/Product.php diff --git a/includes/classes/Product.php b/includes/classes/Product.php new file mode 100644 index 0000000000..4a6bbca403 --- /dev/null +++ b/includes/classes/Product.php @@ -0,0 +1,303 @@ +get('property') or ->getData() */ + public array $fields; + + /** @deprecated use !exists() */ + public bool $EOF = true; + + public function __construct(protected ?int $product_id = null) + { + $this->initLanguages(); + + if ($this->product_id !== null) { + $this->data = $this->loadProductDetails($this->product_id); + + // set some backward compatibility properties + $this->fields = $this->data; + $this->EOF = false; + } + } + + public function forLanguage(?int $language_id): self + { + $this->data = $this->getDataForLanguage($language_id); + $this->fields = $this->data; + + return $this; + } + + public function withDefaultLanguage(): self + { + $this->data = $this->getDataForLanguage(); + $this->fields = $this->data; + + return $this; + } + + public function getData(): ?array + { + return $this->data; + } + + public function get(string $name) + { + return $this->data[$name] ?? $this->data['lang'][$this->languages[(int)$_SESSION['languages_id']]] ?? null; + } + + public function getDataForLanguage(?int $language_id = null): ?array + { + if (empty($language_id)) { + $language_id = (int)$_SESSION['languages_id']; + } + $data = $this->data; + + // strip all languages except specified one, and merge into parent array instead of sub-array + foreach($data['lang'][$this->languages[$language_id]] as $key => $value) { + $data[$key] = $value; + } + unset($data['lang']); + + return $data; + } + + public function getId(): ?int + { + return $this->product_id; + } + + public function exists(): bool + { + return !empty($this->product_id); + } + public function isValid(): bool + { + return !empty($this->data); + } + + public function isLinked(): bool + { + return ($this->data['linked_categories_count'] ?? 0) > 0; + } + + public function isVirtual(): bool + { + return ($this->data['products_virtual'] ?? 0) === '1'; + } + + public function isAlwaysFreeShipping(): bool + { + return ($this->data['product_is_always_free_shipping'] ?? '') === '1'; + } + + public function isGiftVoucher(): bool + { + return str_starts_with($this->data['products_model'] ?? '', 'GIFT'); + } + + public function allowsAddToCart(): bool + { + if (empty($this->data)) { + return false; + } + + $allow_add_to_cart = ($this->data['allow_add_to_cart'] ?? 'N') !== 'N'; + + if ($allow_add_to_cart && $this->isGiftVoucher()) { + // if GV feature disabled, can't allow GV's to be added to cart + if (!defined('MODULE_ORDER_TOTAL_GV_STATUS') || MODULE_ORDER_TOTAL_GV_STATUS !== 'true') { + $allow_add_to_cart = false; + } + } + + $this->notify('NOTIFY_GET_PRODUCT_ALLOW_ADD_TO_CART', $this->product_id, $allow_add_to_cart, $this->data); + + // test for boolean and for 'Y', since observer might try to return 'Y' + return in_array($allow_add_to_cart, [true, 'Y'], true); + } + + public function getProductQuantity(): int|float + { + $quantity = $this->data['products_quantity'] ?? '0'; + $this->notify('NOTIFY_GET_PRODUCT_QUANTITY', $this->product_id, $quantity); + return zen_str_to_numeric((string)$quantity); + } + + public function getTypeHandler(): string + { + return ($this->data['type_handler'] ?? 'product'); + } + + public function getInfoPage(): string + { + return $this->getTypeHandler() . '_info'; + } + + public function hasPriceQuantityDiscounts(): bool + { + if (empty($this->data)) { + return false; + } + + global $db; + $sql = "SELECT products_id FROM " . TABLE_PRODUCTS_DISCOUNT_QUANTITY . " WHERE products_id=" . (int)$this->product_id; + $results = $db->Execute($sql, 1); + return !$results->EOF; + } + + public function hasPriceSpecials() + { + if (empty($this->data)) { + return false; + } + + global $db; + $sql = "SELECT products_id FROM " . TABLE_SPECIALS . " WHERE products_id=" . (int)$this->product_id; + $results = $db->Execute($sql, 1); + return !$results->EOF; + } + + public function priceIsByAttribute(): bool + { + return ($this->data['products_priced_by_attribute'] ?? '0') === '1'; + } + + public function priceIsFree(): bool + { + return ($this->data['product_is_free'] ?? '0') === '1'; + } + + public function priceIsCall(): bool + { + return ($this->data['product_is_call'] ?? '0') === '1'; + } + + public function __get(string $name) + { + return $this->get($name); + } + + protected function loadProductDetails(int $product_id, ?int $language_id = null): array + { + global $db; + + $sql = "SELECT p.*, pt.allow_add_to_cart, pt.type_handler, m.manufacturers_name, m.manufacturers_image + FROM " . TABLE_PRODUCTS . " p + LEFT JOIN " . TABLE_PRODUCT_TYPES . " pt ON (p.products_type = pt.type_id) + LEFT JOIN " . TABLE_MANUFACTURERS . " m USING (manufacturers_id) + WHERE p.products_id = " . (int)$product_id; + $product = $db->Execute($sql, 1, true, 900); + + if ($product->EOF) { + return []; + } + + $data = $product->fields; + $data['id'] = $data['products_id']; + $data['product_id'] = $data['products_id']; + $data['info_page'] = $data['type_handler'] . '_info'; + //$data['parent_category_id'] = $data['master_categories_id']; + + /** + * Add $data['lang'][code] = [products_name, products_description, etc] for each language + */ + $sql = "SELECT pd.* + FROM " . TABLE_PRODUCTS_DESCRIPTION . " pd + WHERE pd.products_id = " . (int)$product_id . " + ORDER BY language_id"; + $pd = $db->Execute($sql, null, true, 900); + foreach ($pd as $result) { + unset($result['products_id']); + $data['lang'][$this->languages[$result['language_id']]] = $result; + } + + // count linked categories + $sql = "SELECT categories_id FROM " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc WHERE products_id=" . (int)$product_id; + $results = $db->Execute($sql, null, true, 900); + $data['linked_categories_count'] = $results->RecordCount(); + $data['linked_categories'] = []; + foreach($results as $result) { + $data['linked_categories'][] = $result['categories_id']; + } + + // get cPath + $categories = []; + zen_get_parent_categories($categories, $data['master_categories_id']); + $categories = array_reverse($categories); + $categories[] = $data['master_categories_id']; + $data['cPath'] = implode('_', $categories); + + + //Allow an observer to modify details + $this->notify('NOTIFY_GET_PRODUCT_OBJECT_DETAILS', $product_id, $data); + + return $data; + } + + protected function initLanguages(): void + { + global $lng; + + if ($lng === null) { + $lng = new language(); + } + + $this->languages = $lng->get_language_list(); // [1 => 'en', 2 => 'fr'] + } +} + + +/* This class essentially deprecates the following functions (note Notifier hook differences): +zen_get_product_details (er, well, it's now a helper to access this class) +zen_get_products_category_id +zen_products_id_valid +zen_get_products_name +zen_get_products_model +zen_get_products_status +zen_get_product_is_linked +zen_get_products_stock (*) +zen_get_products_manufacturers_name +zen_get_products_manufacturers_image +zen_get_products_manufacturers_id +zen_get_products_url +zen_get_products_description +zen_get_info_page +zen_get_products_type +zen_get_products_image (er, well, must call zen_image yourself) +zen_get_products_virtual +zen_get_products_allow_add_to_cart +zen_get_product_is_always_free_shipping +zen_products_lookup +zen_get_parent_category_id +zen_has_product_discounts +zen_has_product_specials +zen_get_product_path +zen_get_products_price_is_free +zen_get_products_price_is_call +zen_get_products_price_is_priced_by_attributes +zen_get_products_quantity_order_min +zen_get_products_quantity_order_units +zen_get_products_quantity_order_max +zen_get_products_qty_box_status +zen_get_products_quantity_mixed + +*/ diff --git a/includes/classes/shopping_cart.php b/includes/classes/shopping_cart.php index da2a8909d7..33f09e508b 100644 --- a/includes/classes/shopping_cart.php +++ b/includes/classes/shopping_cart.php @@ -677,7 +677,7 @@ public function calculate() $qty = $data['qty']; $prid = zen_get_prid($uprid); - $product = zen_get_product_details($prid); + $product = (new Product($prid))->withDefaultLanguage(); if ($product->EOF) { $this->removeUprid($uprid); continue; @@ -1231,7 +1231,7 @@ public function get_products(bool $check_for_valid_cart = false) $products_array = []; foreach ($this->contents as $uprid => $data) { $prid = zen_get_prid($uprid); - $products = zen_get_product_details($prid); + $products = (new Product($prid))->withDefaultLanguage(); if ($products->EOF) { $this->removeUprid($uprid); continue; @@ -1489,7 +1489,7 @@ public function get_content_type($gv_only = false) } else { foreach ($this->contents as $uprid => $data) { $prid = (int)$uprid; - $free_ship_check = zen_get_product_details($prid); + $free_ship_check = (new Product($prid))->withDefaultLanguage(); $free_ship_check = $free_ship_check->fields; if (str_starts_with($free_ship_check['products_model'], 'GIFT')) { @@ -1594,7 +1594,7 @@ public function in_cart_mixed($uprid_to_check) } // check if mixed is on - $product = zen_get_product_details((int)$uprid_to_check); + $product = (new Product((int)$uprid_to_check))->withDefaultLanguage(); // if mixed attributes is off return qty for current attribute selection if ($product->fields['products_quantity_mixed'] === '0') { @@ -1630,7 +1630,7 @@ public function in_cart_mixed_discount_quantity($uprid_to_check) } // check if mixed is on - $product = zen_get_product_details((int)$uprid_to_check); + $product = (new Product((int)$uprid_to_check))->withDefaultLanguage(); // if mixed attributes is off return qty for current attribute selection if ($product->fields['products_mixed_discount_quantity'] === '0') { @@ -1671,7 +1671,7 @@ public function in_cart_check($check_what, $check_value = '1') $in_cart_check_qty = 0; foreach ($this->contents as $uprid => $data) { // check if field it true - $product_check = zen_get_product_details(zen_get_prid($uprid)); + $product_check = (new Product(zen_get_prid($uprid)))->withDefaultLanguage(); if (array_key_exists($check_what, $product_check->fields) && (string)$product_check->fields[$check_what] === (string)$check_value) { $in_cart_check_qty += $data['qty']; } @@ -2651,7 +2651,7 @@ public function in_cart_product_mixed_changed($product_id, $chk = false) } // check if mixed is on - $product = zen_get_product_details((int)$pr_id); + $product = (new Product((int)$pr_id))->withDefaultLanguage(); // if mixed attributes is off identify that this product is the last of its kind (which is also the first of its kind). if (empty($product->fields['products_quantity_mixed'])) { diff --git a/includes/functions/functions_products.php b/includes/functions/functions_products.php index 72a370b65b..054db65db5 100644 --- a/includes/functions/functions_products.php +++ b/includes/functions/functions_products.php @@ -13,30 +13,16 @@ * * @param int $product_id * @param int $language_id (optional) - * @return queryFactoryResult + * @return Product */ -function zen_get_product_details($product_id, $language_id = null) +function zen_get_product_details($product_id, $language_id = null): Product { - global $db, $zco_notifier; - - if ($language_id === null) { - $language_id = $_SESSION['languages_id'] ?? 1; - } - - $sql = "SELECT p.*, pd.*, pt.allow_add_to_cart, pt.type_handler - FROM " . TABLE_PRODUCTS . " p - LEFT JOIN " . TABLE_PRODUCT_TYPES . " pt ON (p.products_type = pt.type_id) - LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON (p.products_id = pd.products_id AND pd.language_id = " . (int)$language_id . ") - WHERE p.products_id = " . (int)$product_id; - $product = $db->Execute($sql, 1, true, 900); - //Allow an observer to modify details - $zco_notifier->notify('NOTIFY_GET_PRODUCT_DETAILS', $product_id, $product); - return $product; + return (new Product($product_id))->forLanguage((int)$language_id); } /** * @param int $product_id - * @param null $product_info + * @param Product $product_info */ function zen_product_set_header_response($product_id, $product_info = null) { @@ -44,11 +30,11 @@ function zen_product_set_header_response($product_id, $product_info = null) // make sure we got a dbResponse if ($product_info === null || !isset($product_info->EOF)) { - $product_info = zen_get_product_details($product_id); + $product_info = new Product($product_id); } // make sure it's for the current product if (!isset($product_info->fields['products_id'], $product_info->fields['products_status']) || (int)$product_info->fields['products_id'] !== (int)$product_id) { - $product_info = zen_get_product_details($product_id); + $product_info = new Product($product_id); } $response_code = 200; @@ -205,11 +191,7 @@ function zen_get_new_date_range($time_limit = false) */ function zen_get_products_category_id($product_id) { - $result = zen_get_product_details($product_id); - if ($result->EOF) { - return ''; - } - return $result->fields['master_categories_id']; + return (new Product($product_id))->get('master_categories_id') ?? ''; } /** @@ -426,8 +408,7 @@ function zen_get_prid(string|int $uprid): int */ function zen_products_id_valid($product_id) { - $product = zen_get_product_details($product_id); - return !$product->EOF; + return (new Product($product_id))->isValid(); } /** @@ -438,8 +419,9 @@ function zen_products_id_valid($product_id) */ function zen_get_products_name($product_id, $language_id = null) { - $product = zen_get_product_details($product_id, $language_id); - return ($product->EOF) ? '' : $product->fields['products_name']; + $product = new Product($product_id); + $data = $product->getDataForLanguage($language_id); + return ($product->EOF) ? '' : $data['products_name']; } /** @@ -448,8 +430,7 @@ function zen_get_products_name($product_id, $language_id = null) */ function zen_get_products_model($product_id) { - $product = zen_get_product_details($product_id); - return ($product->EOF) ? '' : $product->fields['products_model']; + return (new Product($product_id))->get('products_model') ?? ''; } /** @@ -458,8 +439,7 @@ function zen_get_products_model($product_id) */ function zen_get_products_status($product_id) { - $product = zen_get_product_details($product_id); - return ($product->EOF) ? '' : $product->fields['products_status']; + return (new Product($product_id))->get('products_status') ?? ''; } /** @@ -470,19 +450,10 @@ function zen_get_products_status($product_id) */ function zen_get_product_is_linked($product_id, $show_count = 'false') { - global $db; - - $sql = "SELECT * FROM " . TABLE_PRODUCTS_TO_CATEGORIES . (!empty($product_id) ? " where products_id=" . (int)$product_id : ""); - $check_linked = $db->Execute($sql); - if ($check_linked->RecordCount() > 1) { - if ($show_count === 'true') { - return $check_linked->RecordCount(); - } else { - return 'true'; - } - } else { - return 'false'; + if ($show_count === true || $show_count === 'true') { + return (new Product($product_id))->get('linked_categories_count'); } + return (new Product($product_id))->isLinked() ? 'true' : 'false'; } /** @@ -507,8 +478,7 @@ function zen_get_products_stock($products_id) return $products_quantity; } $products_id = zen_get_prid($products_id); - $product = zen_get_product_details($products_id); - return ($product->EOF) ? '0' : $product->fields['products_quantity']; + return (new Product($products_id))->get('products_quantity') ?? '0'; } /** @@ -584,7 +554,7 @@ function zen_get_products_manufacturers_image($product_id) */ function zen_get_products_manufacturers_id($product_id) { - $product = zen_get_product_details($product_id); + $product = new Product($product_id); return ($product->EOF) ? 0 : (int)$product->fields['manufacturers_id']; } @@ -595,8 +565,9 @@ function zen_get_products_manufacturers_id($product_id) */ function zen_get_products_url($product_id, $language_id) { - $product = zen_get_product_details($product_id, $language_id); - return ($product->EOF) ? '' : (string)$product->fields['products_url']; + $product = new Product($product_id); + $data = $product->getDataForLanguage($language_id); + return ($product->EOF) ? '' : (string)$data['products_url']; } /** @@ -609,11 +580,12 @@ function zen_get_products_description($product_id, $language_id = null) { global $zco_notifier; - $product = zen_get_product_details($product_id, $language_id); + $product = new Product($product_id); + $data = $product->getDataForLanguage($language_id); //Allow an observer to modify the description - $zco_notifier->notify('NOTIFY_GET_PRODUCTS_DESCRIPTION', $product_id, $product); - return ($product->EOF) ? '' : $product->fields['products_description']; + $zco_notifier->notify('NOTIFY_GET_PRODUCTS_DESCRIPTION', $product_id, $data); + return ($product->EOF) ? '' : $data['products_description']; } /** @@ -623,8 +595,7 @@ function zen_get_products_description($product_id, $language_id = null) */ function zen_get_info_page($product_id) { - $result = zen_get_product_details($product_id); - return ($result->EOF) ? 'product_info' : ($result->fields['type_handler'] . '_info'); + return (new Product($product_id))->getInfoPage(); } /** @@ -634,7 +605,7 @@ function zen_get_info_page($product_id) */ function zen_get_products_type($product_id) { - $result = zen_get_product_details($product_id); + $result = new Product($product_id); // ----- // NOTE: Empty string return is used by the admin/product.php to identify a product @@ -652,15 +623,15 @@ function zen_get_products_type($product_id) */ function zen_get_products_image($product_id, $width = SMALL_IMAGE_WIDTH, $height = SMALL_IMAGE_HEIGHT) { - $result = zen_get_product_details($product_id); - if ($result->EOF) { + $product = new Product($product_id); + if ($product->EOF) { return ''; } if (IS_ADMIN_FLAG === true) { - return $result->fields['products_image']; + return $product->fields['products_image']; } - return zen_image(DIR_WS_IMAGES . $result->fields['products_image'], zen_get_products_name($product_id), $width, $height); + return zen_image(DIR_WS_IMAGES . $product->fields['products_image'], zen_get_products_name($product_id), $width, $height); } /** @@ -670,8 +641,7 @@ function zen_get_products_image($product_id, $width = SMALL_IMAGE_WIDTH, $height */ function zen_get_products_virtual($product_id) { - $result = zen_get_product_details($product_id); - return (!$result->EOF && $result->fields['products_virtual'] === '1'); + return (new Product($product_id))->isVirtual(); } /** @@ -681,24 +651,7 @@ function zen_get_products_virtual($product_id) */ function zen_get_products_allow_add_to_cart($product_id) { - global $zco_notifier; - - $product_query_results = zen_get_product_details($product_id); - - // If product found, and product_type's allow_add_to_cart is not 'N', allow - $allow_add_to_cart = !$product_query_results->EOF && $product_query_results->fields['allow_add_to_cart'] !== 'N'; - - // If product is encoded as GV but GV feature is turned off, disallow add-to-cart - if ($allow_add_to_cart === true && strpos($product_query_results->fields['products_model'], 'GIFT') === 0) { - if (!defined('MODULE_ORDER_TOTAL_GV_STATUS') || MODULE_ORDER_TOTAL_GV_STATUS !== 'true') { - $allow_add_to_cart = false; - } - } - - $zco_notifier->notify('NOTIFY_GET_PRODUCT_ALLOW_ADD_TO_CART', $product_id, $allow_add_to_cart, $product_query_results); - - // test for boolean and for 'Y', since observer might try to return 'Y' - return in_array($allow_add_to_cart, [true, 'Y'], true) ? 'Y' : 'N'; + return (new Product($product_id))->allowsAddToCart() ? 'Y' : 'N'; } /** @@ -734,8 +687,7 @@ function zen_get_show_product_switch($lookup, $field, $prefix = 'SHOW_', $suffix */ function zen_get_show_product_switch_name($lookup, $field, $prefix = 'SHOW_', $suffix = '_INFO', $field_prefix = '_', $field_suffix = '') { - $product = zen_get_product_details((int)$lookup); - $type_handler = ($product->EOF) ? 'product' : $product->fields['type_handler']; + $type_handler = (new Product((int)$lookup))->getTypeHandler(); return strtoupper($prefix . $type_handler . $suffix . $field_prefix . $field . $field_suffix); } @@ -746,8 +698,7 @@ function zen_get_show_product_switch_name($lookup, $field, $prefix = 'SHOW_', $s */ function zen_get_product_is_always_free_shipping($product_id): bool { - $look_up = zen_get_product_details($product_id); - return (!$look_up->EOF && $look_up->fields['product_is_always_free_shipping'] === '1'); + return (new Product($product_id))->isAlwaysFreeShipping(); } /** @@ -759,11 +710,12 @@ function zen_get_product_is_always_free_shipping($product_id): bool */ function zen_products_lookup($product_id, $what_field = 'products_name', $language = null) { - $product_lookup = zen_get_product_details($product_id, $language); - if ($product_lookup->EOF || !array_key_exists($what_field, $product_lookup->fields)) { + $product = new Product($product_id); + $data = $product->getDataForLanguage($language); + if (empty($data) || !array_key_exists($what_field, $data)) { return ''; } - return $product_lookup->fields[$what_field]; + return $data[$what_field]; } /** @@ -773,7 +725,7 @@ function zen_products_lookup($product_id, $what_field = 'products_name', $langua */ function zen_get_parent_category_id($product_id) { - $result = zen_get_product_details($product_id); + $result = new Product($product_id); return ($result->EOF) ? '' : $result->fields['master_categories_id']; } diff --git a/includes/modules/also_purchased_products.php b/includes/modules/also_purchased_products.php index 77bbeeb2a0..101c0e3022 100644 --- a/includes/modules/also_purchased_products.php +++ b/includes/modules/also_purchased_products.php @@ -1,4 +1,5 @@ 0 && MIN_DISPLAY_ALSO_PURCHASED > 0) { + $also_purchased_products = $db->ExecuteRandomMulti(sprintf(SQL_ALSO_PURCHASED, (int)$_GET['products_id'], (int)$_GET['products_id']), (int)MAX_DISPLAY_ALSO_PURCHASED); - $also_purchased_products = $db->ExecuteRandomMulti(sprintf(SQL_ALSO_PURCHASED, (int)$_GET['products_id'], (int)$_GET['products_id']), (int)MAX_DISPLAY_ALSO_PURCHASED); + $num_products_ordered = $also_purchased_products->RecordCount(); - $num_products_ordered = $also_purchased_products->RecordCount(); + $row = 0; + $col = 0; + $list_box_contents = []; + $title = ''; - $row = 0; - $col = 0; - $list_box_contents = []; - $title = ''; + // show only when 1 or more and equal to or greater than minimum set in admin + if ($num_products_ordered >= MIN_DISPLAY_ALSO_PURCHASED && $num_products_ordered > 0) { + if ($num_products_ordered < SHOW_PRODUCT_INFO_COLUMNS_ALSO_PURCHASED_PRODUCTS) { + $col_width = floor(100 / $num_products_ordered); + } else { + $col_width = floor(100 / SHOW_PRODUCT_INFO_COLUMNS_ALSO_PURCHASED_PRODUCTS); + } - // show only when 1 or more and equal to or greater than minimum set in admin - if ($num_products_ordered >= MIN_DISPLAY_ALSO_PURCHASED && $num_products_ordered > 0) { - if ($num_products_ordered < SHOW_PRODUCT_INFO_COLUMNS_ALSO_PURCHASED_PRODUCTS) { - $col_width = floor(100/$num_products_ordered); - } else { - $col_width = floor(100/SHOW_PRODUCT_INFO_COLUMNS_ALSO_PURCHASED_PRODUCTS); - } + while (!$also_purchased_products->EOF) { + $product_info = new Product($also_purchased_products->fields['products_id']); + $data = array_merge($also_purchased_products->fields, $product_info->getDataForLanguage()); - while (!$also_purchased_products->EOF) { - $also_purchased_products->fields['products_name'] = zen_get_products_name($also_purchased_products->fields['products_id']); - $list_box_contents[$row][$col] = [ - 'params' => 'class="centerBoxContentsAlsoPurch"' . ' ' . 'style="width:' . $col_width . '%;"', - 'text' => ((empty($also_purchased_products->fields['products_image']) && (int)PRODUCTS_IMAGE_NO_IMAGE_STATUS === 0) ? '' : '' . zen_image(DIR_WS_IMAGES . $also_purchased_products->fields['products_image'], $also_purchased_products->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '
') . '' . $also_purchased_products->fields['products_name'] . '' - ]; + $list_box_contents[$row][$col] = [ + 'params' => 'class="centerBoxContentsAlsoPurch"' . ' ' . 'style="width:' . $col_width . '%;"', + 'text' => ((empty($data['products_image']) && (int)PRODUCTS_IMAGE_NO_IMAGE_STATUS === 0) ? '' + : '' + . zen_image(DIR_WS_IMAGES . $data['products_image'], $data['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) + . '
') + . '' . $data['products_name'] . '', + ]; - $col ++; - if ($col > (SHOW_PRODUCT_INFO_COLUMNS_ALSO_PURCHASED_PRODUCTS - 1)) { - $col = 0; - $row ++; - } - $also_purchased_products->MoveNextRandom(); + $col++; + if ($col > (SHOW_PRODUCT_INFO_COLUMNS_ALSO_PURCHASED_PRODUCTS - 1)) { + $col = 0; + $row++; + } + $also_purchased_products->MoveNextRandom(); + } + } + if ($also_purchased_products->RecordCount() > 0 && $also_purchased_products->RecordCount() >= MIN_DISPLAY_ALSO_PURCHASED) { + $title = '

' . TEXT_ALSO_PURCHASED_PRODUCTS . '

'; + $zc_show_also_purchased = true; } - } - if ($also_purchased_products->RecordCount() > 0 && $also_purchased_products->RecordCount() >= MIN_DISPLAY_ALSO_PURCHASED) { - $title = '

' . TEXT_ALSO_PURCHASED_PRODUCTS . '

'; - $zc_show_also_purchased = true; - } } diff --git a/includes/modules/featured_products.php b/includes/modules/featured_products.php index 68205b35b6..d24f44a518 100644 --- a/includes/modules/featured_products.php +++ b/includes/modules/featured_products.php @@ -1,4 +1,5 @@ 0 && empty($_GET['filter_id'])) || !empty($_GET['music_genre_id']) || !empty($_GET['record_company_id'])) || empty($new_products_category_id) ) { - $featured_products_query = "SELECT p.products_id, p.products_image, pd.products_name, p.master_categories_id - FROM " . TABLE_PRODUCTS . " p - LEFT JOIN " . TABLE_FEATURED . " f ON p.products_id = f.products_id - LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON p.products_id = pd.products_id - AND pd.language_id = " . (int)$_SESSION['languages_id'] . " - WHERE p.products_status = 1 - AND f.status = 1"; +if ((($manufacturers_id > 0 && empty($_GET['filter_id'])) || !empty($_GET['music_genre_id']) || !empty($_GET['record_company_id'])) || empty($new_products_category_id)) { + $sql = "SELECT p.products_id, p.products_image, pd.products_name, p.master_categories_id + FROM " . TABLE_PRODUCTS . " p + LEFT JOIN " . TABLE_FEATURED . " f ON p.products_id = f.products_id + LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON p.products_id = pd.products_id + AND pd.language_id = " . (int)$_SESSION['languages_id'] . " + WHERE p.products_status = 1 + AND f.status = 1"; } else { - // get all products and cPaths in this subcat tree - $productsInCategory = zen_get_categories_products_list( (($manufacturers_id > 0 && !empty($_GET['filter_id'])) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath), false, true, 0, $display_limit); + // get all products and cPaths in this subcat tree + $productsInCategory = zen_get_categories_products_list((($manufacturers_id > 0 && !empty($_GET['filter_id'])) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath), false, true, 0, $display_limit); - if (is_array($productsInCategory) && sizeof($productsInCategory) > 0) { - // build products-list string to insert into SQL query - foreach($productsInCategory as $key => $value) { - $list_of_products .= $key . ', '; + if (is_array($productsInCategory) && count($productsInCategory) > 0) { + // build products-list string to insert into SQL query + foreach ($productsInCategory as $key => $value) { + $list_of_products .= $key . ', '; + } + $list_of_products = substr($list_of_products, 0, -2); // remove trailing comma + $sql = "SELECT p.products_id, p.products_image, pd.products_name, p.master_categories_id + FROM " . TABLE_PRODUCTS . " p + LEFT JOIN " . TABLE_FEATURED . " f ON p.products_id = f.products_id + LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON p.products_id = pd.products_id + AND pd.language_id = " . (int)$_SESSION['languages_id'] . " + WHERE p.products_status = 1 + AND f.status = 1 + AND p.products_id IN (" . $list_of_products . ")"; } - $list_of_products = substr($list_of_products, 0, -2); // remove trailing comma - $featured_products_query = "SELECT p.products_id, p.products_image, pd.products_name, p.master_categories_id - FROM " . TABLE_PRODUCTS . " p - LEFT JOIN " . TABLE_FEATURED . " f ON p.products_id = f.products_id - LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON p.products_id = pd.products_id - AND pd.language_id = " . (int)$_SESSION['languages_id'] . " - WHERE p.products_status = 1 - AND f.status = 1 - AND p.products_id IN (" . $list_of_products . ")"; - } } -if ($featured_products_query != '') $featured_products = $db->ExecuteRandomMulti($featured_products_query, MAX_DISPLAY_SEARCH_RESULTS_FEATURED); +if ($sql !== '') { + $featured_products = $db->ExecuteRandomMulti($sql, MAX_DISPLAY_SEARCH_RESULTS_FEATURED); +} $row = 0; $col = 0; -$list_box_contents = array(); +$list_box_contents = []; $title = ''; -$num_products_count = ($featured_products_query == '') ? 0 : $featured_products->RecordCount(); +$num_products_count = ($sql === '') ? 0 : $featured_products->RecordCount(); // show only when 1 or more if ($num_products_count > 0) { - if ($num_products_count < SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS || SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS == 0) { - $col_width = floor(100/$num_products_count); - } else { - $col_width = floor(100/SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS); - } - while (!$featured_products->EOF) { - $products_price = zen_get_products_display_price($featured_products->fields['products_id']); - if (!isset($productsInCategory[$featured_products->fields['products_id']])) $productsInCategory[$featured_products->fields['products_id']] = zen_get_generated_category_path_rev($featured_products->fields['master_categories_id']); + if ($num_products_count < SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS || SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS == 0) { + $col_width = floor(100 / $num_products_count); + } else { + $col_width = floor(100 / SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS); + } + while (!$featured_products->EOF) { + $product_info = new Product($featured_products->fields['products_id']); + $data = $product_info->getDataForLanguage(); + + $products_price = zen_get_products_display_price($data['products_id']); + if (!isset($productsInCategory[$data['products_id']])) { + $productsInCategory[$data['products_id']] = zen_get_generated_category_path_rev($data['master_categories_id']); + } - $zco_notifier->notify('NOTIFY_MODULES_FEATURED_PRODUCTS_B4_LIST_BOX', array(), $featured_products->fields, $products_price); + $zco_notifier->notify('NOTIFY_MODULES_FEATURED_PRODUCTS_B4_LIST_BOX', [], $data, $products_price); - $list_box_contents[$row][$col] = array('params' =>'class="centerBoxContentsFeatured centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"', - 'text' => (($featured_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '' . zen_image(DIR_WS_IMAGES . $featured_products->fields['products_image'], $featured_products->fields['products_name'], IMAGE_FEATURED_PRODUCTS_LISTING_WIDTH, IMAGE_FEATURED_PRODUCTS_LISTING_HEIGHT) . '
') . '' . $featured_products->fields['products_name'] . '
' . $products_price); + $list_box_contents[$row][$col] = [ + 'params' => 'class="centerBoxContentsFeatured centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"', + 'text' => (($data['products_image'] === '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' + : '' + . zen_image(DIR_WS_IMAGES . $data['products_image'], $data['products_name'], IMAGE_FEATURED_PRODUCTS_LISTING_WIDTH, IMAGE_FEATURED_PRODUCTS_LISTING_HEIGHT) + . '
') + . '' . $data['products_name'] + . '
' . $products_price, + ]; - $col ++; - if ($col > (SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS - 1)) { - $col = 0; - $row ++; + $col++; + if ($col > (SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS - 1)) { + $col = 0; + $row++; + } + $featured_products->MoveNextRandom(); } - $featured_products->MoveNextRandom(); - } - if ($featured_products->RecordCount() > 0) { - if (!empty($current_category_id)) { - $category_title = zen_get_category_name((int)$current_category_id); - $title = '

' . TABLE_HEADING_FEATURED_PRODUCTS . ($category_title != '' ? ' - ' . $category_title : '') . '

'; - } else { - $title = '

' . TABLE_HEADING_FEATURED_PRODUCTS . '

'; + if ($featured_products->RecordCount() > 0) { + if (!empty($current_category_id)) { + $category_title = zen_get_category_name((int)$current_category_id); + $title = '

' . TABLE_HEADING_FEATURED_PRODUCTS . ($category_title !== '' ? ' - ' . $category_title : '') . '

'; + } else { + $title = '

' . TABLE_HEADING_FEATURED_PRODUCTS . '

'; + } + $zc_show_featured = true; } - $zc_show_featured = true; - } } diff --git a/includes/modules/new_products.php b/includes/modules/new_products.php index 3f8185d6d7..fe0fdf1a96 100644 --- a/includes/modules/new_products.php +++ b/includes/modules/new_products.php @@ -70,7 +70,7 @@ $products_price = zen_get_products_display_price($new_products_id); $new_products_link = zen_href_link(zen_get_info_page($new_products_id), 'cPath=' . $productsInCategory[$new_products_id] . '&products_id=' . $new_products_id); - $new_products_name = $new_products->fields['products_name']; + $new_products_name = zen_get_products_name($new_products->fields['products_id']); if ($new_products->fields['products_image'] === '' && PRODUCTS_IMAGE_NO_IMAGE_STATUS === '0') { $new_products_image = ''; @@ -98,7 +98,7 @@ if (!empty($current_category_id)) { $category_title = zen_get_category_name((int)$current_category_id); - $title = '

' . sprintf(TABLE_HEADING_NEW_PRODUCTS, $zcDate->output('%B')) . ($category_title != '' ? ' - ' . $category_title : '' ) . '

'; + $title = '

' . sprintf(TABLE_HEADING_NEW_PRODUCTS, $zcDate->output('%B')) . ($category_title !== '' ? ' - ' . $category_title : '' ) . '

'; } else { $title = '

' . sprintf(TABLE_HEADING_NEW_PRODUCTS, $zcDate->output('%B')) . '

'; } diff --git a/includes/modules/pages/document_general_info/header_php.php b/includes/modules/pages/document_general_info/header_php.php index c44c674db9..b934912416 100644 --- a/includes/modules/pages/document_general_info/header_php.php +++ b/includes/modules/pages/document_general_info/header_php.php @@ -13,9 +13,9 @@ require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php')); -$product_info = zen_get_product_details($products_id_current = (!empty($_GET['products_id']) ? (int)$_GET['products_id'] : 0)); -if (!empty($product_info->fields['type_handler']) && $current_page !== $product_info->fields['type_handler'] . '_info') { - zen_redirect(zen_href_link($product_info->fields['type_handler'] . '_info', zen_get_all_get_params())); +$product_info = new Product($products_id_current = (!empty($_GET['products_id']) ? (int)$_GET['products_id'] : 0)); +if ($current_page !== $product_info->get('info_page')) { + zen_redirect(zen_href_link($product_info->get('info_page'), zen_get_all_get_params())); } zen_product_set_header_response($products_id_current, $product_info); diff --git a/includes/modules/pages/document_general_info/main_template_vars.php b/includes/modules/pages/document_general_info/main_template_vars.php index 140096054b..7a8d0b58c3 100644 --- a/includes/modules/pages/document_general_info/main_template_vars.php +++ b/includes/modules/pages/document_general_info/main_template_vars.php @@ -14,11 +14,13 @@ // This should be first line of the script: $zco_notifier->notify('NOTIFY_MAIN_TEMPLATE_VARS_START_DOCUMENT_GENERAL_INFO'); - if (!isset($product_info->EOF, $product_info->fields['products_id'], $product_info->fields['products_status']) || (int)$product_info->fields['products_id'] !== (int)$_GET['products_id']) { - $product_info = zen_get_product_details($_GET['products_id']); + $product_info = $product_info ?? new Product($_GET['products_id']); + + if (!isset($product_info->fields['products_id'], $product_info->fields['products_status']) || (int)$product_info->fields['products_id'] !== (int)$_GET['products_id']) { + $product_info = new Product($_GET['products_id']); } - $product_not_found = $product_info->EOF; + $product_not_found = !$product_info->exists(); if (!defined('DISABLED_PRODUCTS_TRIGGER_HTTP200') || DISABLED_PRODUCTS_TRIGGER_HTTP200 !== 'true') { if (!$product_not_found && $product_info->fields['products_status'] != 1) { @@ -38,7 +40,7 @@ $products_price = $currencies->display_price($product_info->fields['products_price'], zen_get_tax_rate($product_info->fields['products_tax_class_id'])); - $manufacturers_name= zen_get_products_manufacturers_name((int)$_GET['products_id']); + $manufacturers_name = $product_info->fields['manufacturers_name']; if ($new_price = zen_get_products_special_price($product_info->fields['products_id'])) { $specials_price = $currencies->display_price($new_price, zen_get_tax_rate($product_info->fields['products_tax_class_id'])); @@ -61,17 +63,17 @@ $reviews = $db->Execute($reviews_query); - $products_name = $product_info->fields['products_name']; + $products_name = $product_info->fields['lang'][$_SESSION['languages_code']]['products_name']; $products_model = $product_info->fields['products_model']; // if no common markup tags in description, add line breaks for readability: - $products_description = (!preg_match('/(fields['products_description']) ? nl2br($product_info->fields['products_description']) : $product_info->fields['products_description']); + $products_description = (!preg_match('/(fields['lang'][$_SESSION['languages_code']]['products_description']) ? nl2br($product_info->fields['lang'][$_SESSION['languages_code']]['products_description']) : $product_info->fields['lang'][$_SESSION['languages_code']]['products_description']); $products_image = (($product_not_found || $product_info->fields['products_image'] == '') && PRODUCTS_IMAGE_NO_IMAGE_STATUS == '1') ? PRODUCTS_IMAGE_NO_IMAGE : ''; if ($product_info->fields['products_image'] != '' || PRODUCTS_IMAGE_NO_IMAGE_STATUS != '1') { $products_image = $product_info->fields['products_image']; } - $products_url = $product_info->fields['products_url']; + $products_url = $product_info->fields['lang'][$_SESSION['languages_code']]['products_url']; $products_date_available = $product_info->fields['products_date_available']; $products_date_added = $product_info->fields['products_date_added']; $products_manufacturer = $manufacturers_name; diff --git a/includes/modules/pages/document_product_info/header_php.php b/includes/modules/pages/document_product_info/header_php.php index 046b4809af..b96f76d1fe 100644 --- a/includes/modules/pages/document_product_info/header_php.php +++ b/includes/modules/pages/document_product_info/header_php.php @@ -13,9 +13,9 @@ require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php')); -$product_info = zen_get_product_details($products_id_current = (!empty($_GET['products_id']) ? (int)$_GET['products_id'] : 0)); -if (!empty($product_info->fields['type_handler']) && $current_page !== $product_info->fields['type_handler'] . '_info') { - zen_redirect(zen_href_link($product_info->fields['type_handler'] . '_info', zen_get_all_get_params())); +$product_info = new Product($products_id_current = (!empty($_GET['products_id']) ? (int)$_GET['products_id'] : 0)); +if ($current_page !== $product_info->get('info_page')) { + zen_redirect(zen_href_link($product_info->get('info_page'), zen_get_all_get_params())); } zen_product_set_header_response($products_id_current, $product_info); diff --git a/includes/modules/pages/document_product_info/main_template_vars.php b/includes/modules/pages/document_product_info/main_template_vars.php index 85b721c23c..8f27117666 100644 --- a/includes/modules/pages/document_product_info/main_template_vars.php +++ b/includes/modules/pages/document_product_info/main_template_vars.php @@ -14,11 +14,13 @@ // This should be first line of the script: $zco_notifier->notify('NOTIFY_MAIN_TEMPLATE_VARS_START_DOCUMENT_PRODUCT_INFO'); - if (!isset($product_info->EOF, $product_info->fields['products_id'], $product_info->fields['products_status']) || (int)$product_info->fields['products_id'] !== (int)$_GET['products_id']) { - $product_info = zen_get_product_details($_GET['products_id']); + $product_info = $product_info ?? new Product($_GET['products_id']); + + if (!isset($product_info->fields['products_id'], $product_info->fields['products_status']) || (int)$product_info->fields['products_id'] !== (int)$_GET['products_id']) { + $product_info = new Product($_GET['products_id']); } - $product_not_found = $product_info->EOF; + $product_not_found = !$product_info->exists(); if (!defined('DISABLED_PRODUCTS_TRIGGER_HTTP200') || DISABLED_PRODUCTS_TRIGGER_HTTP200 !== 'true') { if (!$product_not_found && $product_info->fields['products_status'] != 1) { @@ -38,7 +40,7 @@ $products_price = $currencies->display_price($product_info->fields['products_price'], zen_get_tax_rate($product_info->fields['products_tax_class_id'])); - $manufacturers_name= zen_get_products_manufacturers_name((int)$_GET['products_id']); + $manufacturers_name = $product_info->fields['manufacturers_name']; if ($new_price = zen_get_products_special_price($product_info->fields['products_id'])) { $specials_price = $currencies->display_price($new_price, zen_get_tax_rate($product_info->fields['products_tax_class_id'])); @@ -61,17 +63,17 @@ $reviews = $db->Execute($reviews_query); - $products_name = $product_info->fields['products_name']; + $products_name = $product_info->fields['lang'][$_SESSION['languages_code']]['products_name']; $products_model = $product_info->fields['products_model']; // if no common markup tags in description, add line breaks for readability: - $products_description = (!preg_match('/(fields['products_description']) ? nl2br($product_info->fields['products_description']) : $product_info->fields['products_description']); + $products_description = (!preg_match('/(fields['lang'][$_SESSION['languages_code']]['products_description']) ? nl2br($product_info->fields['lang'][$_SESSION['languages_code']]['products_description']) : $product_info->fields['lang'][$_SESSION['languages_code']]['products_description']); $products_image = (($product_not_found || $product_info->fields['products_image'] == '') && PRODUCTS_IMAGE_NO_IMAGE_STATUS == '1') ? PRODUCTS_IMAGE_NO_IMAGE : ''; if ($product_info->fields['products_image'] != '' || PRODUCTS_IMAGE_NO_IMAGE_STATUS != '1') { $products_image = $product_info->fields['products_image']; } - $products_url = $product_info->fields['products_url']; + $products_url = $product_info->fields['lang'][$_SESSION['languages_code']]['products_url']; $products_date_available = $product_info->fields['products_date_available']; $products_date_added = $product_info->fields['products_date_added']; $products_manufacturer = $manufacturers_name; diff --git a/includes/modules/pages/product_free_shipping_info/header_php.php b/includes/modules/pages/product_free_shipping_info/header_php.php index 472e937e81..4f40bf15a3 100644 --- a/includes/modules/pages/product_free_shipping_info/header_php.php +++ b/includes/modules/pages/product_free_shipping_info/header_php.php @@ -13,9 +13,9 @@ require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php')); -$product_info = zen_get_product_details($products_id_current = (!empty($_GET['products_id']) ? (int)$_GET['products_id'] : 0)); -if (!empty($product_info->fields['type_handler']) && $current_page !== $product_info->fields['type_handler'] . '_info') { - zen_redirect(zen_href_link($product_info->fields['type_handler'] . '_info', zen_get_all_get_params())); +$product_info = new Product($products_id_current = (!empty($_GET['products_id']) ? (int)$_GET['products_id'] : 0)); +if ($current_page !== $product_info->get('info_page')) { + zen_redirect(zen_href_link($product_info->get('info_page'), zen_get_all_get_params())); } zen_product_set_header_response($products_id_current, $product_info); diff --git a/includes/modules/pages/product_free_shipping_info/main_template_vars.php b/includes/modules/pages/product_free_shipping_info/main_template_vars.php index dcac2d8c6b..9810e12b11 100644 --- a/includes/modules/pages/product_free_shipping_info/main_template_vars.php +++ b/includes/modules/pages/product_free_shipping_info/main_template_vars.php @@ -14,11 +14,13 @@ // This should be first line of the script: $zco_notifier->notify('NOTIFY_MAIN_TEMPLATE_VARS_START_PRODUCT_FREE_SHIPPING_INFO'); - if (!isset($product_info->EOF, $product_info->fields['products_id'], $product_info->fields['products_status']) || (int)$product_info->fields['products_id'] !== (int)$_GET['products_id']) { - $product_info = zen_get_product_details($_GET['products_id']); + $product_info = $product_info ?? new Product($_GET['products_id']); + + if (!isset($product_info->fields['products_id'], $product_info->fields['products_status']) || (int)$product_info->fields['products_id'] !== (int)$_GET['products_id']) { + $product_info = new Product($_GET['products_id']); } - $product_not_found = $product_info->EOF; + $product_not_found = !$product_info->exists(); if (!defined('DISABLED_PRODUCTS_TRIGGER_HTTP200') || DISABLED_PRODUCTS_TRIGGER_HTTP200 !== 'true') { if (!$product_not_found && $product_info->fields['products_status'] != 1) { @@ -38,7 +40,7 @@ $products_price = $currencies->display_price($product_info->fields['products_price'], zen_get_tax_rate($product_info->fields['products_tax_class_id'])); - $manufacturers_name= zen_get_products_manufacturers_name((int)$_GET['products_id']); + $manufacturers_name = $product_info->fields['manufacturers_name']; if ($new_price = zen_get_products_special_price($product_info->fields['products_id'])) { $specials_price = $currencies->display_price($new_price, zen_get_tax_rate($product_info->fields['products_tax_class_id'])); @@ -61,17 +63,17 @@ $reviews = $db->Execute($reviews_query); - $products_name = $product_info->fields['products_name']; + $products_name = $product_info->fields['lang'][$_SESSION['languages_code']]['products_name']; $products_model = $product_info->fields['products_model']; // if no common markup tags in description, add line breaks for readability: - $products_description = (!preg_match('/(fields['products_description']) ? nl2br($product_info->fields['products_description']) : $product_info->fields['products_description']); + $products_description = (!preg_match('/(fields['lang'][$_SESSION['languages_code']]['products_description']) ? nl2br($product_info->fields['lang'][$_SESSION['languages_code']]['products_description']) : $product_info->fields['lang'][$_SESSION['languages_code']]['products_description']); $products_image = (($product_not_found || $product_info->fields['products_image'] == '') && PRODUCTS_IMAGE_NO_IMAGE_STATUS == '1') ? PRODUCTS_IMAGE_NO_IMAGE : ''; if ($product_info->fields['products_image'] != '' || PRODUCTS_IMAGE_NO_IMAGE_STATUS != '1') { $products_image = $product_info->fields['products_image']; } - $products_url = $product_info->fields['products_url']; + $products_url = $product_info->fields['lang'][$_SESSION['languages_code']]['products_url']; $products_date_available = $product_info->fields['products_date_available']; $products_date_added = $product_info->fields['products_date_added']; $products_manufacturer = $manufacturers_name; diff --git a/includes/modules/pages/product_info/header_php.php b/includes/modules/pages/product_info/header_php.php index eb94317c9b..50ab0ca018 100644 --- a/includes/modules/pages/product_info/header_php.php +++ b/includes/modules/pages/product_info/header_php.php @@ -13,9 +13,9 @@ require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php')); -$product_info = zen_get_product_details($products_id_current = (!empty($_GET['products_id']) ? (int)$_GET['products_id'] : 0)); -if (!empty($product_info->fields['type_handler']) && $current_page !== $product_info->fields['type_handler'] . '_info') { - zen_redirect(zen_href_link($product_info->fields['type_handler'] . '_info', zen_get_all_get_params())); +$product_info = new Product($products_id_current = (!empty($_GET['products_id']) ? (int)$_GET['products_id'] : 0)); +if ($current_page !== $product_info->get('info_page')) { + zen_redirect(zen_href_link($product_info->get('info_page'), zen_get_all_get_params())); } zen_product_set_header_response($products_id_current, $product_info); diff --git a/includes/modules/pages/product_info/main_template_vars.php b/includes/modules/pages/product_info/main_template_vars.php index 7a88542216..9e5da75829 100644 --- a/includes/modules/pages/product_info/main_template_vars.php +++ b/includes/modules/pages/product_info/main_template_vars.php @@ -14,11 +14,13 @@ // This should be first line of the script: $zco_notifier->notify('NOTIFY_MAIN_TEMPLATE_VARS_START_PRODUCT_INFO'); - if (!isset($product_info->EOF, $product_info->fields['products_id'], $product_info->fields['products_status']) || (int)$product_info->fields['products_id'] !== (int)$_GET['products_id']) { - $product_info = zen_get_product_details($_GET['products_id']); + $product_info = $product_info ?? new Product($_GET['products_id']); + + if (!isset($product_info->fields['products_id'], $product_info->fields['products_status']) || (int)$product_info->fields['products_id'] !== (int)$_GET['products_id']) { + $product_info = new Product($_GET['products_id']); } - $product_not_found = $product_info->EOF; + $product_not_found = !$product_info->exists(); if (!defined('DISABLED_PRODUCTS_TRIGGER_HTTP200') || DISABLED_PRODUCTS_TRIGGER_HTTP200 !== 'true') { if (!$product_not_found && $product_info->fields['products_status'] != 1) { @@ -38,7 +40,7 @@ $products_price = $currencies->display_price($product_info->fields['products_price'], zen_get_tax_rate($product_info->fields['products_tax_class_id'])); - $manufacturers_name = zen_get_products_manufacturers_name((int)$_GET['products_id']); + $manufacturers_name = $product_info->fields['manufacturers_name']; if ($new_price = zen_get_products_special_price($product_info->fields['products_id'])) { $specials_price = $currencies->display_price($new_price, zen_get_tax_rate($product_info->fields['products_tax_class_id'])); @@ -53,25 +55,25 @@ $review_status = " AND r.status = 1"; $reviews_query = "SELECT count(*) AS count FROM " . TABLE_REVIEWS . " r, " - . TABLE_REVIEWS_DESCRIPTION . " rd + . TABLE_REVIEWS_DESCRIPTION . " rd WHERE r.products_id = " . (int)$_GET['products_id'] . " AND r.reviews_id = rd.reviews_id AND rd.languages_id = " . (int)$_SESSION['languages_id'] . - $review_status; + $review_status; $reviews = $db->Execute($reviews_query); - $products_name = $product_info->fields['products_name']; + $products_name = $product_info->fields['lang'][$_SESSION['languages_code']]['products_name']; $products_model = $product_info->fields['products_model']; // if no common markup tags in description, add line breaks for readability: - $products_description = (!preg_match('/(fields['products_description']) ? nl2br($product_info->fields['products_description']) : $product_info->fields['products_description']); + $products_description = (!preg_match('/(fields['lang'][$_SESSION['languages_code']]['products_description']) ? nl2br($product_info->fields['lang'][$_SESSION['languages_code']]['products_description']) : $product_info->fields['lang'][$_SESSION['languages_code']]['products_description']); $products_image = (($product_not_found || $product_info->fields['products_image'] == '') && PRODUCTS_IMAGE_NO_IMAGE_STATUS == '1') ? PRODUCTS_IMAGE_NO_IMAGE : ''; if ($product_info->fields['products_image'] != '' || PRODUCTS_IMAGE_NO_IMAGE_STATUS != '1') { $products_image = $product_info->fields['products_image']; } - $products_url = $product_info->fields['products_url']; + $products_url = $product_info->fields['lang'][$_SESSION['languages_code']]['products_url']; $products_date_available = $product_info->fields['products_date_available']; $products_date_added = $product_info->fields['products_date_added']; $products_manufacturer = $manufacturers_name; diff --git a/includes/modules/pages/product_music_info/header_php.php b/includes/modules/pages/product_music_info/header_php.php index 6ba96d9106..c1828a633b 100644 --- a/includes/modules/pages/product_music_info/header_php.php +++ b/includes/modules/pages/product_music_info/header_php.php @@ -13,9 +13,9 @@ require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php')); -$product_info = zen_get_product_details($products_id_current = (!empty($_GET['products_id']) ? (int)$_GET['products_id'] : 0)); -if (!empty($product_info->fields['type_handler']) && $current_page !== $product_info->fields['type_handler'] . '_info') { - zen_redirect(zen_href_link($product_info->fields['type_handler'] . '_info', zen_get_all_get_params())); +$product_info = new Product($products_id_current = (!empty($_GET['products_id']) ? (int)$_GET['products_id'] : 0)); +if ($current_page !== $product_info->get('info_page')) { + zen_redirect(zen_href_link($product_info->get('info_page'), zen_get_all_get_params())); } zen_product_set_header_response($products_id_current, $product_info); diff --git a/includes/modules/pages/product_music_info/main_template_vars.php b/includes/modules/pages/product_music_info/main_template_vars.php index 4d4ee8392b..499f26ab18 100644 --- a/includes/modules/pages/product_music_info/main_template_vars.php +++ b/includes/modules/pages/product_music_info/main_template_vars.php @@ -14,11 +14,13 @@ // This should be first line of the script: $zco_notifier->notify('NOTIFY_MAIN_TEMPLATE_VARS_START_PRODUCT_MUSIC_INFO'); - if (!isset($product_info->EOF, $product_info->fields['products_id'], $product_info->fields['products_status']) || (int)$product_info->fields['products_id'] !== (int)$_GET['products_id']) { - $product_info = zen_get_product_details($_GET['products_id']); + $product_info = $product_info ?? new Product($_GET['products_id']); + + if (!isset($product_info->fields['products_id'], $product_info->fields['products_status']) || (int)$product_info->fields['products_id'] !== (int)$_GET['products_id']) { + $product_info = new Product($_GET['products_id']); } - $product_not_found = $product_info->EOF; + $product_not_found = !$product_info->exists(); if (!defined('DISABLED_PRODUCTS_TRIGGER_HTTP200') || DISABLED_PRODUCTS_TRIGGER_HTTP200 !== 'true') { if (!$product_not_found && $product_info->fields['products_status'] != 1) { @@ -38,7 +40,7 @@ $products_price = $currencies->display_price($product_info->fields['products_price'], zen_get_tax_rate($product_info->fields['products_tax_class_id'])); - $manufacturers_name = zen_get_products_manufacturers_name((int)$_GET['products_id']); + $manufacturers_name = $product_info->fields['manufacturers_name']; if ($new_price = zen_get_products_special_price($product_info->fields['products_id'])) { $specials_price = $currencies->display_price($new_price, zen_get_tax_rate($product_info->fields['products_tax_class_id'])); @@ -61,17 +63,17 @@ $reviews = $db->Execute($reviews_query); - $products_name = $product_info->fields['products_name']; + $products_name = $product_info->fields['lang'][$_SESSION['languages_code']]['products_name']; $products_model = $product_info->fields['products_model']; // if no common markup tags in description, add line breaks for readability: - $products_description = (!preg_match('/(fields['products_description']) ? nl2br($product_info->fields['products_description']) : $product_info->fields['products_description']); + $products_description = (!preg_match('/(fields['lang'][$_SESSION['languages_code']]['products_description']) ? nl2br($product_info->fields['lang'][$_SESSION['languages_code']]['products_description']) : $product_info->fields['lang'][$_SESSION['languages_code']]['products_description']); $products_image = (($product_not_found || $product_info->fields['products_image'] == '') && PRODUCTS_IMAGE_NO_IMAGE_STATUS == '1') ? PRODUCTS_IMAGE_NO_IMAGE : ''; if ($product_info->fields['products_image'] != '' || PRODUCTS_IMAGE_NO_IMAGE_STATUS != '1') { $products_image = $product_info->fields['products_image']; } - $products_url = $product_info->fields['products_url']; + $products_url = $product_info->fields['lang'][$_SESSION['languages_code']]['products_url']; $products_date_available = $product_info->fields['products_date_available']; $products_date_added = $product_info->fields['products_date_added']; $products_manufacturer = $manufacturers_name; diff --git a/includes/modules/product_listing.php b/includes/modules/product_listing.php index cc377fc6af..b4f156a4f4 100644 --- a/includes/modules/product_listing.php +++ b/includes/modules/product_listing.php @@ -129,17 +129,16 @@ // Retrieve all records into an array to allow for sorting and insertion of additional data if needed $records = []; foreach ($listing as $record) { + $product_info = new Product($record['products_id']); $category_id = !empty($record['categories_id']) ? $record['categories_id'] : $record['master_categories_id']; $parent_category_name = trim(zen_get_categories_parent_name($category_id)); $category_name = trim(zen_get_category_name($category_id, (int)$_SESSION['languages_id'])); - $product_details = zen_get_product_details($record['products_id']); + $records[] = array_merge($record, [ 'parent_category_name' => (!empty($parent_category_name)) ? $parent_category_name : $category_name, 'category_name' => $category_name, -// 'master_categories_id' => $record['master_categories_id'], -// 'products_sort_order' => $record['products_sort_order'], - ], $product_details->fields ?? []); + ], $product_info->getDataForLanguage((int)$_SESSION['languages_id']) ?? []); } if (!empty($_GET['keyword'])) $skip_sort = true; @@ -219,7 +218,7 @@ $listing_product_name = zen_get_products_name((int)$record['products_id']); $listing_description = ''; if ((int)PRODUCT_LIST_DESCRIPTION > 0) { - $listing_description = zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($record['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION); + $listing_description = zen_trunc_string(zen_clean_html(stripslashes($record['products_description'])), PRODUCT_LIST_DESCRIPTION); } $listing_model = $record['products_model'] ?? ''; $listing_mfg_name = $record['manufacturers_name'] ?? ''; diff --git a/includes/modules/responsive_classic/product_listing.php b/includes/modules/responsive_classic/product_listing.php index 1739515725..34a17e5283 100644 --- a/includes/modules/responsive_classic/product_listing.php +++ b/includes/modules/responsive_classic/product_listing.php @@ -129,17 +129,16 @@ // Retrieve all records into an array to allow for sorting and insertion of additional data if needed $records = []; foreach ($listing as $record) { + $product_info = new Product($record['products_id']); $category_id = !empty($record['categories_id']) ? $record['categories_id'] : $record['master_categories_id']; $parent_category_name = trim(zen_get_categories_parent_name($category_id)); $category_name = trim(zen_get_category_name($category_id, (int)$_SESSION['languages_id'])); + $records[] = array_merge($record, [ 'parent_category_name' => (!empty($parent_category_name)) ? $parent_category_name : $category_name, 'category_name' => $category_name, -// 'products_name' => $record['products_name'], -// 'master_categories_id' => $record['master_categories_id'], -// 'products_sort_order' => $record['products_sort_order'], - ]); + ], $product_info->getDataForLanguage((int)$_SESSION['languages_id']) ?? []); } if (!empty($_GET['keyword'])) $skip_sort = true; @@ -215,7 +214,7 @@ $listing_product_name = $record['products_name'] ?? ''; $listing_description = ''; if ((int)PRODUCT_LIST_DESCRIPTION > 0) { - $listing_description = zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($record['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION); + $listing_description = zen_trunc_string(zen_clean_html(stripslashes($record['products_description'])), PRODUCT_LIST_DESCRIPTION); $lc_text .= '
' . $listing_description . '
'; } $listing_model = $record['products_model'] ?? ''; diff --git a/includes/modules/sideboxes/best_sellers.php b/includes/modules/sideboxes/best_sellers.php index 2da886642f..0051a967e9 100644 --- a/includes/modules/sideboxes/best_sellers.php +++ b/includes/modules/sideboxes/best_sellers.php @@ -38,6 +38,8 @@ if ($best_sellers->RecordCount() >= MIN_DISPLAY_BESTSELLERS) { $bestsellers_list = []; foreach ($best_sellers as $bestseller) { + $product_info = (new Product($bestseller['products_id']))->withDefaultLanguage(); + $bestseller = array_merge($bestseller, $product_info->getData()); $best_products_id = $bestseller['products_id']; $bestsellers_list[] = [ 'id' => $best_products_id, diff --git a/includes/modules/specials_index.php b/includes/modules/specials_index.php index 4e7ef618bc..335e66eaae 100644 --- a/includes/modules/specials_index.php +++ b/includes/modules/specials_index.php @@ -1,4 +1,5 @@ 0 && empty($_GET['filter_id'])) || !empty($_GET['music_genre_id']) || !empty($_GET['record_company_id'])) || empty($new_products_category_id) ) { - $specials_index_query = "SELECT p.products_id, p.products_image, pd.products_name, p.master_categories_id +if ((($manufacturers_id > 0 && empty($_GET['filter_id'])) || !empty($_GET['music_genre_id']) || !empty($_GET['record_company_id'])) || empty($new_products_category_id)) { + $specials_index_query = "SELECT p.products_id, p.products_image, pd.products_name, p.master_categories_id FROM (" . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_SPECIALS . " s ON p.products_id = s.products_id LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON p.products_id = pd.products_id ) @@ -27,16 +28,16 @@ AND p.products_status = 1 AND s.status = 1 AND pd.language_id = " . (int)$_SESSION['languages_id']; } else { - // get all products and cPaths in this subcat tree - $productsInCategory = zen_get_categories_products_list( (($manufacturers_id > 0 && !empty($_GET['filter_id'])) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath), false, true, 0, $display_limit); + // get all products and cPaths in this subcat tree + $productsInCategory = zen_get_categories_products_list((($manufacturers_id > 0 && !empty($_GET['filter_id'])) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath), false, true, 0, $display_limit); - if (is_array($productsInCategory) && sizeof($productsInCategory) > 0) { - // build products-list string to insert into SQL query - foreach($productsInCategory as $key => $value) { - $list_of_products .= $key . ', '; - } - $list_of_products = substr($list_of_products, 0, -2); // remove trailing comma - $specials_index_query = "SELECT DISTINCT p.products_id, p.products_image, pd.products_name, p.master_categories_id + if (is_array($productsInCategory) && sizeof($productsInCategory) > 0) { + // build products-list string to insert into SQL query + foreach ($productsInCategory as $key => $value) { + $list_of_products .= $key . ', '; + } + $list_of_products = substr($list_of_products, 0, -2); // remove trailing comma + $specials_index_query = "SELECT DISTINCT p.products_id, p.products_image, pd.products_name, p.master_categories_id FROM (" . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_SPECIALS . " s ON p.products_id = s.products_id LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON p.products_id = pd.products_id ) @@ -45,46 +46,64 @@ AND p.products_status = 1 AND s.status = 1 AND pd.language_id = " . (int)$_SESSION['languages_id'] . " AND p.products_id in (" . $list_of_products . ")"; - } + } +} +if ($specials_index_query !== '') { + $specials_index = $db->ExecuteRandomMulti($specials_index_query, MAX_DISPLAY_SPECIAL_PRODUCTS_INDEX); } -if ($specials_index_query != '') $specials_index = $db->ExecuteRandomMulti($specials_index_query, MAX_DISPLAY_SPECIAL_PRODUCTS_INDEX); $row = 0; $col = 0; -$list_box_contents = array(); +$list_box_contents = []; $title = ''; -$num_products_count = ($specials_index_query == '') ? 0 : $specials_index->RecordCount(); +$num_products_count = ($specials_index_query === '') ? 0 : $specials_index->RecordCount(); // show only when 1 or more if ($num_products_count > 0) { - if ($num_products_count < SHOW_PRODUCT_INFO_COLUMNS_SPECIALS_PRODUCTS || SHOW_PRODUCT_INFO_COLUMNS_SPECIALS_PRODUCTS == 0 ) { - $col_width = floor(100/$num_products_count); - } else { - $col_width = floor(100/SHOW_PRODUCT_INFO_COLUMNS_SPECIALS_PRODUCTS); - } + if ($num_products_count < SHOW_PRODUCT_INFO_COLUMNS_SPECIALS_PRODUCTS || SHOW_PRODUCT_INFO_COLUMNS_SPECIALS_PRODUCTS == 0) { + $col_width = floor(100 / $num_products_count); + } else { + $col_width = floor(100 / SHOW_PRODUCT_INFO_COLUMNS_SPECIALS_PRODUCTS); + } + + $list_box_contents = []; + while (!$specials_index->EOF) { + $product_info = new Product($specials_index->fields['products_id']); + $data = array_merge($specials_index->fields, $product_info->getDataForLanguage()); - $list_box_contents = array(); - while (!$specials_index->EOF) { - $products_price = zen_get_products_display_price($specials_index->fields['products_id']); - if (!isset($productsInCategory[$specials_index->fields['products_id']])) $productsInCategory[$specials_index->fields['products_id']] = zen_get_generated_category_path_rev($specials_index->fields['master_categories_id']); + $products_price = zen_get_products_display_price($data['products_id']); + if (!isset($productsInCategory[$data['products_id']])) { + $productsInCategory[$data['products_id']] = zen_get_generated_category_path_rev($data['master_categories_id']); + } - $zco_notifier->notify('NOTIFY_MODULES_SPECIALS_INDEX_B4_LIST_BOX', array(), $specials_index->fields, $products_price); + $zco_notifier->notify('NOTIFY_MODULES_SPECIALS_INDEX_B4_LIST_BOX', [], $data, $products_price); - $specials_index->fields['products_name'] = zen_get_products_name($specials_index->fields['products_id']); - $list_box_contents[$row][$col] = array('params' => 'class="centerBoxContentsSpecials centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"', - 'text' => (($specials_index->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '' . zen_image(DIR_WS_IMAGES . $specials_index->fields['products_image'], $specials_index->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '
') . '' . $specials_index->fields['products_name'] . '
' . $products_price); + $data['products_name'] = zen_get_products_name($data['products_id']); + $list_box_contents[$row][$col] = [ + 'params' => 'class="centerBoxContentsSpecials centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"', + 'text' => (($data['products_image'] === '' && PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) + ? '' + : '' + . zen_image(DIR_WS_IMAGES . $data['products_image'], $data['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) + . '
') + . '' . $data['products_name'] + . '
' . $products_price, + ]; - $col ++; - if ($col > (SHOW_PRODUCT_INFO_COLUMNS_SPECIALS_PRODUCTS - 1)) { - $col = 0; - $row ++; + $col++; + if ($col > (SHOW_PRODUCT_INFO_COLUMNS_SPECIALS_PRODUCTS - 1)) { + $col = 0; + $row++; + } + $specials_index->MoveNextRandom(); } - $specials_index->MoveNextRandom(); - } - if ($specials_index->RecordCount() > 0) { - $title = '

' . sprintf(TABLE_HEADING_SPECIALS_INDEX, $zcDate->output('%B')) . '

'; - $zc_show_specials = true; - } + if ($specials_index->RecordCount() > 0) { + $title = '

' . sprintf(TABLE_HEADING_SPECIALS_INDEX, $zcDate->output('%B')) . '

'; + $zc_show_specials = true; + } } diff --git a/includes/modules/upcoming_products.php b/includes/modules/upcoming_products.php index f86aa7cf83..f6a9329d88 100644 --- a/includes/modules/upcoming_products.php +++ b/includes/modules/upcoming_products.php @@ -1,4 +1,5 @@ 0 && empty($_GET['filter_id'])) || !empty($_GET['music_genre_id']) || !empty($_GET['record_company_id'])) || empty($new_products_category_id) ) { - $expected_query = "SELECT p.products_id, pd.products_name, products_date_available AS date_expected, p.master_categories_id - FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd - WHERE p.products_id = pd.products_id - AND p.products_status = 1 - AND pd.language_id = " . (int)$_SESSION['languages_id'] . - $display_limit . - $limit_clause; +if ((($manufacturers_id > 0 && empty($_GET['filter_id'])) || !empty($_GET['music_genre_id']) || !empty($_GET['record_company_id'])) || empty($new_products_category_id)) { + $sql = "SELECT p.products_id, pd.products_name, products_date_available AS date_expected, p.master_categories_id + FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd + WHERE p.products_id = pd.products_id + AND p.products_status = 1 + AND pd.language_id = " . (int)$_SESSION['languages_id'] . + $display_limit . + $limit_clause; } else { - // get all products and cPaths in this subcat tree - $productsInCategory = zen_get_categories_products_list( (($manufacturers_id > 0 && !empty($_GET['filter_id'])) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath), false, true, 0, $display_limit); + // get all products and cPaths in this subcat tree + $productsInCategory = zen_get_categories_products_list((($manufacturers_id > 0 && !empty($_GET['filter_id'])) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath), false, true, 0, $display_limit); + + if (is_array($productsInCategory) && count($productsInCategory) > 0) { + // build products-list string to insert into SQL query + foreach ($productsInCategory as $key => $value) { + $list_of_products .= $key . ', '; + } + $list_of_products = substr($list_of_products, 0, -2); // remove trailing comma - if (is_array($productsInCategory) && sizeof($productsInCategory) > 0) { - // build products-list string to insert into SQL query - foreach($productsInCategory as $key => $value) { - $list_of_products .= $key . ', '; + $sql = "SELECT p.products_id, pd.products_name, products_date_available AS date_expected, p.master_categories_id + FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd + WHERE p.products_id = pd.products_id + AND p.products_id IN (" . $list_of_products . ") + AND p.products_status = 1 + AND pd.language_id = " . (int)$_SESSION['languages_id'] . + $display_limit . + $limit_clause; } - $list_of_products = substr($list_of_products, 0, -2); // remove trailing comma - - $expected_query = "SELECT p.products_id, pd.products_name, products_date_available AS date_expected, p.master_categories_id - FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd - WHERE p.products_id = pd.products_id - AND p.products_id IN (" . $list_of_products . ") - AND p.products_status = 1 - AND pd.language_id = " . (int)$_SESSION['languages_id'] . - $display_limit . - $limit_clause; - } } -if ($expected_query != '') $expected = $db->Execute($expected_query); -if ($expected_query != '' && $expected->RecordCount() > 0) { - foreach ($expected as $expect) { - if (!isset($productsInCategory[$expect['products_id']])) $productsInCategory[$expect['products_id']] = zen_get_generated_category_path_rev($expect['master_categories_id']); - $expectedItems[] = $expect; - } - require($template->get_template_dir('tpl_modules_upcoming_products.php', DIR_WS_TEMPLATE, $current_page_base,'templates'). '/' . 'tpl_modules_upcoming_products.php'); +if ($sql !== '') { + $expected = $db->Execute($sql); +} +if ($sql !== '' && $expected->RecordCount() > 0) { + foreach ($expected as $expect) { + if (!isset($productsInCategory[$expect['products_id']])) { + $productsInCategory[$expect['products_id']] = zen_get_generated_category_path_rev($expect['master_categories_id']); + } + $expectedItems[] = array_merge($expect, (new Product($expect['products_id']))->getDataForLanguage()); + } + require $template->get_template_dir('tpl_modules_upcoming_products.php', DIR_WS_TEMPLATE, $current_page_base, 'templates') . '/' . 'tpl_modules_upcoming_products.php'; } diff --git a/includes/psr4Autoload.php b/includes/psr4Autoload.php index aca60ffae5..e12227eda6 100644 --- a/includes/psr4Autoload.php +++ b/includes/psr4Autoload.php @@ -25,6 +25,7 @@ $psr4Autoloader->addPrefix('Zencart\Paginator', DIR_FS_ADMIN . DIR_WS_CLASSES); } $psr4Autoloader->setClassFile('language', DIR_FS_CATALOG . DIR_WS_CLASSES . 'language.php' ); +$psr4Autoloader->setClassFile('Product', DIR_FS_CATALOG . DIR_WS_CLASSES . 'Product.php' ); $psr4Autoloader->setClassFile('Settings', DIR_FS_CATALOG . DIR_WS_CLASSES . 'Settings.php' ); $psr4Autoloader->setClassFile('TemplateSettings', DIR_FS_CATALOG . DIR_WS_CLASSES . 'TemplateSettings.php' ); $psr4Autoloader->setClassFile('ZenShipping', DIR_FS_CATALOG . DIR_WS_CLASSES . 'ZenShipping.php'); diff --git a/includes/templates/responsive_classic/sideboxes/tpl_reviews_random.php b/includes/templates/responsive_classic/sideboxes/tpl_reviews_random.php index ed987e9c9f..b478132bad 100644 --- a/includes/templates/responsive_classic/sideboxes/tpl_reviews_random.php +++ b/includes/templates/responsive_classic/sideboxes/tpl_reviews_random.php @@ -7,12 +7,16 @@ * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @version $Id: DrByte 2020 Dec 25 Modified in v1.5.8-alpha $ */ - $content = ""; - $review_box_counter = 0; - while (!$random_review_sidebox_product->EOF) { +$content = ""; +$review_box_counter = 0; +while (!$random_review_sidebox_product->EOF) { $review_box_counter++; $content .= '
'; - $content .= '' . zen_image(DIR_WS_IMAGES . $random_review_sidebox_product->fields['products_image'], $random_review_sidebox_product->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '
' . nl2br(zen_trunc_string(zen_output_string_protected(stripslashes($random_review_sidebox_product->fields['reviews_text'])), 60)) . '


' . zen_image(DIR_WS_TEMPLATE_IMAGES . 'stars_' . $random_review_sidebox_product->fields['reviews_rating'] . '.png' , sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $random_review_sidebox_product->fields['reviews_rating'])); + $content .= '' + . zen_image(DIR_WS_IMAGES . $random_review_sidebox_product->fields['products_image'], zen_get_products_name($random_review_sidebox_product->fields['products_id']), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) + . '
' . nl2br(zen_trunc_string(zen_output_string_protected(stripslashes($random_review_sidebox_product->fields['reviews_text'])), 60)) + . '


' + . zen_image(DIR_WS_TEMPLATE_IMAGES . 'stars_' . $random_review_sidebox_product->fields['reviews_rating'] . '.png', sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $random_review_sidebox_product->fields['reviews_rating'])); $content .= '
'; $random_review_sidebox_product->MoveNextRandom(); - } +} diff --git a/includes/templates/template_default/sideboxes/tpl_featured.php b/includes/templates/template_default/sideboxes/tpl_featured.php index 0cad6f550d..5792ca08fe 100644 --- a/includes/templates/template_default/sideboxes/tpl_featured.php +++ b/includes/templates/template_default/sideboxes/tpl_featured.php @@ -1,4 +1,5 @@ '; - $featured_box_counter = 0; - while (!$random_featured_product->EOF) { +$content = ""; +$content .= '
'; +$featured_box_counter = 0; +while (!$random_featured_product->EOF) { + $data = (new Product($random_featured_product->fields['products_id']))->withDefaultLanguage()->getData(); $featured_box_counter++; - $featured_box_price = zen_get_products_display_price($random_featured_product->fields['products_id']); + $featured_box_price = zen_get_products_display_price($data['products_id']); $content .= "\n" . ' '; $random_featured_product->MoveNextRandom(); - } - $content .= '
' . "\n"; +} +$content .= '' . "\n"; diff --git a/includes/templates/template_default/sideboxes/tpl_reviews_random.php b/includes/templates/template_default/sideboxes/tpl_reviews_random.php index f5eb98d3f8..ace65db745 100644 --- a/includes/templates/template_default/sideboxes/tpl_reviews_random.php +++ b/includes/templates/template_default/sideboxes/tpl_reviews_random.php @@ -7,12 +7,16 @@ * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @version $Id: DrByte 2020 Dec 25 Modified in v1.5.8-alpha $ */ - $content = ""; - $review_box_counter = 0; - while (!$random_review_sidebox_product->EOF) { +$content = ""; +$review_box_counter = 0; +while (!$random_review_sidebox_product->EOF) { $review_box_counter++; $content .= '
'; - $content .= '' . zen_image(DIR_WS_IMAGES . $random_review_sidebox_product->fields['products_image'], $random_review_sidebox_product->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '
' . nl2br(zen_trunc_string(zen_output_string_protected(stripslashes($random_review_sidebox_product->fields['reviews_text'])), 60)) . '


' . zen_image(DIR_WS_TEMPLATE_IMAGES . 'stars_' . $random_review_sidebox_product->fields['reviews_rating'] . '.gif' , sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $random_review_sidebox_product->fields['reviews_rating'])); + $content .= '' + . zen_image(DIR_WS_IMAGES . $random_review_sidebox_product->fields['products_image'], zen_get_products_name($random_review_sidebox_product->fields['products_id']), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) + . '
' . nl2br(zen_trunc_string(zen_output_string_protected(stripslashes($random_review_sidebox_product->fields['reviews_text'])), 60)) + . '


' + . zen_image(DIR_WS_TEMPLATE_IMAGES . 'stars_' . $random_review_sidebox_product->fields['reviews_rating'] . '.gif', sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $random_review_sidebox_product->fields['reviews_rating'])); $content .= '
'; $random_review_sidebox_product->MoveNextRandom(); - } +} diff --git a/includes/templates/template_default/sideboxes/tpl_specials.php b/includes/templates/template_default/sideboxes/tpl_specials.php index 659fe82954..514a9d717a 100644 --- a/includes/templates/template_default/sideboxes/tpl_specials.php +++ b/includes/templates/template_default/sideboxes/tpl_specials.php @@ -1,4 +1,5 @@ '; - $specials_box_counter = 0; - while (!$random_specials_sidebox_product->EOF) { +$content = ""; +$content .= '
'; +$specials_box_counter = 0; +while (!$random_specials_sidebox_product->EOF) { + $data = array_merge($random_specials_sidebox_product->fields, (new Product($random_specials_sidebox_product->fields['products_id']))->withDefaultLanguage()->getData()); $specials_box_counter++; - $specials_box_price = zen_get_products_display_price($random_specials_sidebox_product->fields['products_id']); + $specials_box_price = zen_get_products_display_price($data['products_id']); $content .= "\n" . ' '; $random_specials_sidebox_product->MoveNextRandom(); - } - $content .= '
' . "\n"; +} +$content .= '' . "\n"; diff --git a/includes/templates/template_default/sideboxes/tpl_whats_new.php b/includes/templates/template_default/sideboxes/tpl_whats_new.php index 6a077ccea3..3c39bd28f0 100644 --- a/includes/templates/template_default/sideboxes/tpl_whats_new.php +++ b/includes/templates/template_default/sideboxes/tpl_whats_new.php @@ -1,4 +1,5 @@ '; - $whats_new_box_counter = 0; - while (!$random_whats_new_sidebox_product->EOF) { +$content = ""; +$content .= '
'; +$whats_new_box_counter = 0; +while (!$random_whats_new_sidebox_product->EOF) { + $data = (new Product($random_whats_new_sidebox_product->fields['products_id']))->withDefaultLanguage()->getData(); + $whats_new_box_counter++; - $whats_new_price = zen_get_products_display_price($random_whats_new_sidebox_product->fields['products_id']); + $whats_new_price = zen_get_products_display_price($data['products_id']); $content .= "\n" . ' '; $random_whats_new_sidebox_product->MoveNextRandom(); - } - $content .= '
' . "\n"; +} +$content .= '' . "\n";