File indexing completed on 2025-05-04 05:29:14

0001 <?php
0002 
0003 /**
0004  *  ocs-webserver
0005  *
0006  *  Copyright 2016 by pling GmbH.
0007  *
0008  *    This file is part of ocs-webserver.
0009  *
0010  *    This program is free software: you can redistribute it and/or modify
0011  *    it under the terms of the GNU Affero General Public License as
0012  *    published by the Free Software Foundation, either version 3 of the
0013  *    License, or (at your option) any later version.
0014  *
0015  *    This program is distributed in the hope that it will be useful,
0016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018  *    GNU Affero General Public License for more details.
0019  *
0020  *    You should have received a copy of the GNU Affero General Public License
0021  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0022  **/
0023 class Default_View_Helper_BuildProductUrl
0024 {
0025 
0026     /**
0027      * @param        $product_id
0028      * @param string $action
0029      * @param array  $params
0030      * @param bool   $withHost
0031      * @param string $scheme
0032      *
0033      * @return string
0034      */
0035     public function buildProductUrl($product_id, $action = '', $params = null, $withHost = false, $scheme = null)
0036     {
0037         if (empty($product_id)) {
0038             return '';
0039         }
0040 
0041         /** @var Zend_Controller_Request_Http $request */
0042         $request = Zend_Controller_Front::getInstance()->getRequest();
0043         $baseurl = '';
0044         
0045         $host = '';
0046         if ($withHost) {
0047 //            $member_host = Zend_Registry::get('config')->settings->member->page->server;
0048 //            $http_host = Zend_Registry::get('config')->settings->member->product->server; // set http_host to product server
0049 //
0050 //            if (false === strpos($request->getHttpHost(), $member_host)) {
0051                 $http_host = $request->getHttpHost();
0052 //            }
0053 
0054             $http_scheme = isset($scheme) ? $scheme : $request->getScheme();
0055             $host = $http_scheme . '://' . $http_host;
0056         }
0057 
0058         $storeId = null;
0059         if (false === isset($params['store_id'])) {
0060             if ($request->getParam('domain_store_id')) {
0061                 $storeId = 's/' . $request->getParam('domain_store_id') . '/';
0062             }
0063         } else {
0064             $storeId = "s/{$params['store_id']}/";
0065             unset($params['store_id']);
0066         }
0067         
0068         /*
0069         //20190710 ronald: removed to stay in context, if set in store config
0070         $storeConfig = Zend_Registry::isRegistered('store_config') ? Zend_Registry::get('store_config') : null;
0071         
0072         if(null != $storeConfig && $storeConfig->stay_in_context == false) {
0073             $baseurl = Zend_Registry::get('config')->settings->client->default->baseurl_product;
0074         } else {
0075             
0076             $baseurl = "{$host}{$storeId}";
0077         }*/
0078 
0079         $url_param = '';
0080         if (is_array($params)) {
0081             array_walk($params, create_function('&$i,$k', '$i="$k/$i/";'));
0082             $url_param = implode('/', $params);
0083         }
0084 
0085         if ($action != '') {
0086             $action = $action . '/';
0087         }
0088 
0089         return "{$host}/{$storeId}p/{$product_id}/{$action}{$url_param}";
0090         
0091         //return "{$baseurl}/p/{$product_id}/{$action}{$url_param}";
0092     }
0093 
0094 }