/** * get item params for view push * * @param int $id * @param bool $more * @return array */ public static function getItemArray($id, $more = false) { if (isset(self::$itemArraysMoreCache[$id])) { return self::$itemArraysMoreCache[$id]; } if (isset(self::$itemArraysCache[$id]) && !$more) { return self::$itemArraysCache[$id]; } $libProduct = new \CCatalogProduct(); $libIBlockElem = new \CIBlockElement(); $libPrice = new \CPrice(); $item = $libProduct->GetByID($id); // maybe we have complex item, let's find its first child entry if ($item === false) { $list = $libIBlockElem->GetList(array('ID' => 'ASC'), array('PROPERTY_CML2_LINK' => $id)); if ($itemBlock = $list->Fetch()) { $item = $libProduct->GetByID($itemBlock['ID']); } else { return null; // c'est la vie } // now $item points to the earliest child } else { // we have simple item or child $itemBlock = $libIBlockElem->GetByID($id)->Fetch(); $itemFull = $libProduct->GetByIDEx($id); if (!empty($itemFull['PROPERTIES']['CML2_LINK']['VALUE'])) { $id = $itemFull['PROPERTIES']['CML2_LINK']['VALUE']; } // set id of the parent if we have child } $return = array('item_id' => intval($id)); if (empty($item)) { return null; } // Get categories $categories = array(); $item_categories = CIBlockElement::GetElementGroups($id, true); while ($category = $item_categories->Fetch()) { $categories[] = $category['ID']; } $return['categories'] = $categories; $has_price = false; $return['price'] = self::getFinalPriceInCurrency($return['item_id'], self::getSaleCurrency()); if (!empty($return['price'])) { $has_price = true; } if (isset($item['QUANTITY'])) { $quantity = $item['QUANTITY'] > 0; $return['is_available'] = $quantity && $has_price ? 1 : 0; } if (Options::getRecommendNonAvailable()) { $return['is_available'] = 1; } if ($more) { $libMain = new \CMain(); $libFile = new \CFile(); $itemFull = $libProduct->GetByIDEx($id); $host = ($libMain->IsHTTPS() ? 'https://' : 'http://') . SITE_SERVER_NAME; $return['name'] = $itemFull['NAME']; $return['url'] = $host . $itemFull['DETAIL_PAGE_URL']; $picture_id = Data::getProductPhotoId($id); if ($picture_id !== null) { $return['image_url'] = $host . $libFile->GetPath($picture_id); } self::$itemArraysMoreCache[$id] = $return; } else { self::$itemArraysCache[$id] = $return; } return $return; }
/** * handler for include/rees46-recommender.php, render recommenders */ public static function run() { CModule::IncludeModule('catalog'); CModule::IncludeModule('sale'); CModule::IncludeModule("iblock"); global $USER; $recommended_by = ''; // get recommender name if (isset($_REQUEST['recommended_by'])) { $recommender = strval($_REQUEST['recommended_by']); $recommended_by = '?recommended_by=' . urlencode($recommender); switch ($recommender) { case 'buying_now': $recommender_title = GetMessage('REES_INCLUDE_BUYING_NOW'); break; case 'see_also': $recommender_title = GetMessage('REES_INCLUDE_SEE_ALSO'); break; case 'recently_viewed': $recommender_title = GetMessage('REES_INCLUDE_RECENTLY_VIEWED'); break; case 'also_bought': $recommender_title = GetMessage('REES_INCLUDE_ALSO_BOUGHT'); break; case 'similar': $recommender_title = GetMessage('REES_INCLUDE_SIMILAR'); break; case 'interesting': $recommender_title = GetMessage('REES_INCLUDE_INTERESTING'); break; case 'popular': $recommender_title = GetMessage('REES_INCLUDE_POPULAR'); break; default: $recommender_title = ''; } } $libCatalogProduct = new CCatalogProduct(); $libFile = new CFile(); // render items if (isset($_REQUEST['recommended_items']) && is_array($_REQUEST['recommended_items']) && count($_REQUEST['recommended_items']) > 0) { $found_items = 0; // Currency to display $sale_currency = Data::getSaleCurrency(); $html = ''; $html .= '<div class="recommender-block-title">' . $recommender_title . '</div>'; $html .= '<div class="recommended-items">'; foreach ($_REQUEST['recommended_items'] as $item_id) { $item_id = intval($item_id); $item = $libCatalogProduct->GetByIDEx($item_id); // Get price $final_price = Data::getFinalPriceInCurrency($item_id, $sale_currency); // Check price if ($final_price == false) { continue; } // Url to product with recommended_by attribute $link = $item['DETAIL_PAGE_URL'] . $recommended_by; // Get photo $picture_id = Data::getProductPhotoId($item_id); if ($picture_id === null) { continue; } $file = $libFile->ResizeImageGet($picture_id, array('width' => Options::getImageWidth(), 'height' => Options::getImageHeight()), BX_RESIZE_IMAGE_PROPORTIONAL, true); $html .= '<div class="recommended-item"> <div class="recommended-item-photo"><a href="' . $link . '"><img src="' . $file['src'] . '" class="item_img"/></a></div> <div class="recommended-item-title"><a href="' . $link . '">' . $item['NAME'] . '</a></div> ' . ($final_price ? '<div class="recommended-item-price">' . CCurrencyLang::CurrencyFormat($final_price, $sale_currency, true) . '</div>' : '') . ' <div class="recommended-item-action"><a href="' . $link . '">' . GetMessage('REES_INCLUDE_MORE') . '</a></div> </div>'; $found_items++; } $html .= '</div>'; if ($found_items > 0) { echo $html; } } }