Fetches a product.

@param int $id
@param string $locale

@throws ProductNotFoundException

@return ApiProductInterface
555344
protected function fetchProduct($id, $locale)
    {
        $product = $this->productRepository->findByIdAndLocale($id, $locale);

        if (!$product) {
            throw new ProductNotFoundException($id);
        }

        return $this->productFactory->createApiEntity($product, $locale);
    }
800855
static function idByLocale( $locale )
    {
        $language = eZContentLanguage::fetchByLocale( $locale );
        if ( $language )
        {
            return (int)$language->attribute( 'id' );
        }
        else
        {
            return false;
        }
    }
238934
public function getProductAddonsAction(Request $request, $productId)
    {
        $locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));

        if ($request->get('flat') == 'true') {
            $fieldDescriptors = $this->getFieldDescriptors($locale);
            $listBuilder = $this->getListBuilder(self::$entityName, $fieldDescriptors);
            $listBuilder->where($fieldDescriptors['productId'], $productId);

            $list = new ListRepresentation(
                $listBuilder->execute(),
                'addons',
                'get_product_addons',
                array_merge($request->query->all(), ['productId' => $productId]),
                $listBuilder->getCurrentPage(),
                $listBuilder->getLimit(),
                $listBuilder->count()
            );
        } else {
            $addons = $this->getManager()->findAddonsByProductIdAndLocale($productId, $locale);
            $list = new CollectionRepresentation(
                $addons,
                'addons'
            );
        }

        $view = $this->view($list, 200);

        return $this->handleView($view);
    }
589053
protected function findProductModelById(string $id): ?ProductInterface
    {
        /**
         * @var ProductInterface
         */
        $class = $this->modelBuilder->getInterfaceClass($this->config, ProductInterface::class);

        return $class::findProductBy1c($id);
    }
588352
public function get($name, $locale=null, $hook=true) {
		if(!$locale)
			$locale = $this->getLocale();

		if($hook && ($res = $this->getDefinition()->trigger('get', [$this, $name, $locale])) !== null)
			return $res;

		return $this->_get($name, $locale);
	}
1037264
public function findByOrderId($orderId, $locale)
    {
        $result = array();
        $items = $this->getShippingRepository()->findByOrderId($orderId, $locale);
        foreach ($items as $item) {
            $result[] = $this->shippingFactory->createApiEntity($item, $locale);
        }
        return $result;
    }
751176
public function getOrFail($id)
    {
        if ($model = $this->get($id)) {
            return $model;
        }

        throw (new NotFoundException("No results for id $id"))->setModel(get_class($this->model));
    }
1249270
protected function getApiObject($account, $locale)
    {
        $apiObject = $this->accountFactory->createApiEntity($account, $locale);
        if ($account->getLogo()) {
            $apiLogo = $this->mediaManager->getById($account->getLogo()->getId(), $locale);
            $apiObject->setLogo($apiLogo);
        }

        return $apiObject;
    }
996027
static public function fetch( $tagID, $locale, $includeDrafts = false )
    {
        $fetchParams = array( 'keyword_id' => $tagID, 'locale' => $locale );
        if ( !$includeDrafts )
            $fetchParams['status'] = self::STATUS_PUBLISHED;

        return parent::fetchObject( self::definition(), null, $fetchParams );
    }
269517
public function getAction(Request $request, $productId)
    {
        $locale = $request->get('locale');
        $product = $this->fetchProduct($productId);

        $content = $this->getProductContentMapper()->get($product, $locale);

        $view = $this->view($content, Response::HTTP_OK);

        return $this->handleView($view);
    }
689085
public function getByIdAndInclude($id, $locale, $includes)
    {
        $account = $this->accountRepository->findAccountById($id, in_array('contacts', $includes));

        if (!$account) {
            throw new EntityNotFoundException($this->accountRepository->getClassName(), $id);
        }

        return $this->getApiObject($account, $locale);
    }
649677
public function getCategories($id, $locale)
    {
        $groups    = $this->getGroups($id, $locale)->toArray();
        $available = antares('memory')->get('extensions.available');
        $list      = ['all' => 'All', 'foundation' => trans('Core')];

        array_walk($groups, function($item) use($available, &$list) {
            $group = str_replace('antares/', '', $item['group']);
            foreach ($available as $extension) {
                if ($group == $extension['name']) {
                    $list[$group] = $extension['full_name'];
                }
            }
        });
        $return = [
            'all'           => 'All',
            'core'          => [
                'label'      => trans('antares/translations::messages.group.core'),
                'extensions' => []
            ],
            'configuration' => [
                'label'      => trans('antares/translations::messages.group.configuration'),
                'extensions' => []
            ],
        ];
        foreach ($list as $name => $value) {
            if (in_array($name, ['foundation', 'widgets', 'search', 'control'])) {
                $return['core']['extensions'][$name] = $value;
            } elseif (in_array($name, ['two_factor_auth', 'api'])) {
                $return['configuration']['extensions'][$name] = $value;
            } else {
                $return[$name] = $value;
            }
        }
        return $return;
    }
744768
public function getParentPagesChoices($locale, $id = null)
    {
        $qb = $this->getParentPagesQuery($locale, $id);

        return $qb->getQuery()->execute();
    }
904245
protected function findModel($id)
    {
        if (($model = Product::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException(t('app', 'The requested page does not exist.'));
        }
    }
224018
protected function getPreview($id, $locale)
    {
        $medias = $this->mediaRepository
            ->findMedia(['collection' => $id, 'paginator' => false], 1);

        if (count($medias) > 0) {
            $media = $medias[0];
            foreach ($media->getFiles() as $file) {
                foreach ($file->getFileVersions() as $fileVersion) {
                    if ($fileVersion->getVersion() == $file->getVersion()) {
                        $format = $this->getPreviewsFromFileVersion($media->getId(), $fileVersion, $locale);

                        if (!empty($format)) {
                            return $format;
                        }
                    }
                }
            }
        }

        return;
    }
1063674
public function findByLocaleAndIds($locale, array $ids = [])
    {
        try {
            $qb = $this->getProductQuery($locale);
            $qb->where('product.id IN (:ids)');
            $qb->setParameter('ids', $ids);
            $query = $qb->getQuery();

            return $query->getResult();
        } catch (NoResultException $ex) {
            return null;
        }
    }
1153996
public function translateAction(Request $request, $id, $locale)
    {
        /** @var PageInterface $page */
        $page = $this->admin->getObject($id);

        if (!$page) {
            throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
        }
        $language = \Locale::getDisplayLanguage($locale);

        if ($request->getMethod() == 'POST') {
            $pageHelper = $this->container->get('networking_init_cms.helper.page_helper');

            try {
                $pageCopy = $pageHelper->makeTranslationCopy($page, $locale);
                $this->admin->createObjectSecurity($pageCopy);
                $status = 'success';
                $message = $this->translate(
                    'message.translation_saved',
                    ['%language%' => $language]
                );
                $result = 'ok';
                $html = $this->renderView(
                    '@NetworkingInitCms/PageAdmin/page_translation_settings.html.twig',
                    ['object' => $page, 'admin' => $this->admin]
                );
            } catch (\Exception $e) {
                $status = 'error';
                $message = $message = $this->translate(
                    'message.translation_not_saved',
                    ['%language%' => $language, '%url%' => $page->getFullPath()]
                );
                $result = 'error';
                $html = '';
            }

            if ($this->isXmlHttpRequest()) {
                return $this->renderJson(
                    [
                        'result' => $result,
                        'status' => $status,
                        'html' => $html,
                        'message' => $message,
                    ]
                );
            }

            $this->get('session')->getFlashBag()->add(
                'sonata_flash_'.$status,
                $message
            );

            return $this->redirect($this->admin->generateUrl('edit', ['id' => $id]));
        }

        return $this->render(
            '@NetworkingInitCms/PageAdmin/page_translation_copy.html.twig',
            [
                'action' => 'copy',
                'page' => $page,
                'id' => $id,
                'locale' => $locale,
                'language' => $language,
                'admin' => $this->admin,
            ]
        );
    }