/** * */ protected function initClassLoader() { require_once __DIR__ . DIRECTORY_SEPARATOR . 'ClassLoader' . DIRECTORY_SEPARATOR . 'ThriftClassLoader.php'; self::$thriftClassLoader = new \Thrift\ClassLoader\ThriftClassLoader(false); self::$thriftClassLoader->registerNamespace('Thrift', __DIR__ . DIRECTORY_SEPARATOR . '..'); self::$thriftClassLoader->register(); foreach ($this->dependencies as $dependency) { require_once __DIR__ . DIRECTORY_SEPARATOR . $dependency; } }
require_once __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'Thrift' . DIRECTORY_SEPARATOR . 'HttpP13n.php'; $p13nHost = 'cdn.bx-cloud.com'; $p13nAccount = 'example-account'; $p13nUsername = '******'; $p13nPassword = '******'; $cookieDomain = '.example.com'; $p13nSearch = 'example search query'; $p13nChoiceId = 'test-search'; $p13nLanguage = 'en'; // or de, fr, it, etc. $p13nFields = array('id'); // fields you want in the response, i.e. title, body, etc. $p13nOffset = 0; $p13nHitCount = 25; // Create basic P13n client $p13n = new HttpP13n(); $p13n->setHost($p13nHost); $p13n->setAuthorization($p13nUsername, $p13nPassword); // Create main choice request object $choiceRequest = $p13n->getChoiceRequest($p13nAccount, $cookieDomain); // Setup main choice inquiry object $inquiry = new \com\boxalino\p13n\api\thrift\ChoiceInquiry(); $inquiry->choiceId = $p13nChoiceId; // Setup a search query $searchQuery = new \com\boxalino\p13n\api\thrift\SimpleSearchQuery(); $searchQuery->indexId = $p13nAccount; $searchQuery->language = $p13nLanguage; $searchQuery->returnFields = $p13nFields; $searchQuery->offset = $p13nOffset; $searchQuery->hitCount = $p13nHitCount; $searchQuery->queryText = $p13nSearch;
public function findRawRecommendations($id, $role, $p13nChoiceId, $count = 5, $offset = 0, $fieldName = 'products_group_id', $context = array(), $contextItems = array()) { $timing = $this->newTiming("findRawRecommendations"); $p13nHost = $this->config->get('boxalino_host'); $p13nAccount = $this->getAccount(); $p13nUsername = $this->config->get('boxalino_username'); $p13nPassword = $this->config->get('boxalino_password'); $cookieDomain = $this->config->get('boxalino_domain'); $p13nLanguage = $this->getShortLocale(); $p13nFields = array('id', 'products_group_id'); // Create basic P13n client $p13n = new HttpP13n(); $p13n->setHost($p13nHost); $p13n->setAuthorization($p13nUsername, $p13nPassword); // Create main choice request object $choiceRequest = $p13n->getChoiceRequest($p13nAccount, $cookieDomain); $choiceRequest->inquiries = array(); // Add context parameters if given if (count($context)) { foreach ($context as $key => $value) { if (!is_array($value)) { $context[$key] = array($value); } } $requestContext = new \com\boxalino\p13n\api\thrift\RequestContext(); $requestContext->parameters = $context; $choiceRequest->requestContext = $requestContext; } $contextItemIds = is_array($id) ? $id : array($id); $contextItems = []; foreach ($contextItemIds as $i => $itemId) { $contextItems[] = new \com\boxalino\p13n\api\thrift\ContextItem(array('indexId' => $p13nAccount, 'fieldName' => $fieldName, 'contextItemId' => $itemId, 'role' => $i == 0 ? $role : 'subProduct')); } // Setup a search query $searchQuery = new \com\boxalino\p13n\api\thrift\SimpleSearchQuery(); $searchQuery->indexId = $p13nAccount; $searchQuery->language = $p13nLanguage; $searchQuery->returnFields = $p13nFields; $searchQuery->offset = $offset; $searchQuery->hitCount = $count; $searchQuery->groupBy = 'products_group_id'; $searchQuery->filters = array(new \com\boxalino\p13n\api\thrift\Filter(array('fieldName' => 'bx_type', 'stringValues' => array('product')))); if (!is_array($p13nChoiceId)) { $p13nChoiceId = array($p13nChoiceId); } foreach ($p13nChoiceId as $choiceId) { // Setup main choice inquiry object $inquiry = new \com\boxalino\p13n\api\thrift\ChoiceInquiry(); $inquiry->choiceId = $choiceId; $inquiry->minHitCount = $count; // Connect search query to the inquiry $inquiry->simpleSearchQuery = $searchQuery; if (!empty($id)) { $inquiry->contextItems = $contextItems; } // Add inquiry to choice request $choiceRequest->inquiries[] = $inquiry; } // Call the service try { $choiceResponse = $p13n->choose($choiceRequest); if ($this->isDebugProtected()) { $this->debug($choiceRequest); $this->debug($choiceResponse); } } catch (Exception $e) { $this->debug("choose failed", $e->getMessage()); if ($this->isDebug()) { exit; } Shopware()->PluginLogger()->debug('Boxalino Recommendation: Error occurred with message ' . $e->getMessage()); return; } $timing(); return $choiceResponse; }