/** * Initialise the product collection from the products service * * @return ProductCollection|null */ private function initialiseChoices() { // Fetch a vendor key if possible, to cache against try { $vendorKey = $this->systemBrandService->getVendorCredentials()['vendorKey']; } catch (\Exception $e) { $vendorKey = 'defaultVendor'; } if (null !== $this->rentGuaranteeOfferingType && null !== $this->propertyLettingType && !$this->isInitialised) { $cacheKey = sprintf('Lookup-Product-Collection-%s-%s-%s', $this->rentGuaranteeOfferingType, $this->propertyLettingType, $vendorKey); $productCollection = $this->cache->fetch($cacheKey); $this->values = array(); $this->choices = array(); if (!$productCollection) { $productCollection = $this->entityManager->find(new ProductCollection(), array('rentGuaranteeOfferingType' => $this->rentGuaranteeOfferingType, 'propertyLettingType' => $this->propertyLettingType)); $this->cache->save($cacheKey, $productCollection); } /** @var \Barbon\HostedApi\AppBundle\Form\Common\Model\Product $product */ foreach ($productCollection as $product) { $this->values[] = (string) $product->getProductId(); $this->choices[] = (string) $product->getProductId(); //$product->getName(); $this->labels[] = (string) $product->getName(); } $this->isInitialised = true; return $productCollection; } return null; }
/** * Attempt to get the vendor credentials from the user object or the MAC data cache. * * @return array * @throws \Exception */ protected function getVendorCredentials() { // Set up system brand service with user token $this->systemBrandService->setUserToken($this->getUser()); return $this->systemBrandService->getVendorCredentials(); }