Returns an array of rating data for a given product
@param integer $product_id
@return array
436019
public function getByProduct($product_id)
    {
        $result = null;
        $this->hook->attach('rating.get.before', $product_id, $result, $this);

        if (isset($result)) {
            return $result;
        }

        $sql = 'SELECT rating, votes FROM rating WHERE product_id=?';
        $result = $this->db->fetch($sql, array($product_id));

        $this->hook->attach('rating.get.after', $product_id, $result, $this);
        return $result;
    }
223300
public function findOneByProductIdAndWebsite($productId, $websiteId)
    {

        // prepare the params
        $params = array(
            MemberNames::PRODUCT_ID => $productId,
            MemberNames::WEBSITE_ID => $websiteId
        );

        // load and return the product with the passed product/website ID
        $this->productWebsiteStmt->execute($params);
        return $this->productWebsiteStmt->fetch(\PDO::FETCH_ASSOC);
    }
723083
public function actionList(int $productId, int $languageId)
    {

        $product = Product::findOne($productId);
        $products = Product::find()->joinWith('translations')->orderBy('title')->all();
        $relatedProducts = $product->relatedProducts;
        $newRelatedProduct = new RelatedProduct();

        $selectedLanguage = Language::findOne($languageId);
        $languages = Language::find()->all();

        if (\Yii::$app->request->isPost && $newRelatedProduct->load(\Yii::$app->request->post())) {
            if (empty(RelatedProduct::find()
                ->where(['product_id' => $productId, 'related_product_id' => $newRelatedProduct->related_product_id])->one())
            ) {

                $newRelatedProduct->product_id = $productId;
                if ($newRelatedProduct->validate()) $newRelatedProduct->save();
                \Yii::$app->session->setFlash('info', \Yii::t('shop', 'Relation product has added successfully'));
            } else {
                \Yii::$app->session->setFlash('info', \Yii::t('shop', 'Such relation product already exists for this product'));
            }

            return $this->redirect(\Yii::$app->request->referrer);
        }

        return $this->render('../product/save', [
            'viewName' => '../related-product/list',
            'selectedLanguage' => $selectedLanguage,
            'product' => $product,
            'languages' => $languages,

            'params' => [
                'product' => $product,
                'products' => $products,
                'relatedProducts' => $relatedProducts,
                'newRelatedProduct' => $newRelatedProduct,
                'languages' => $languages,
                'selectedLanguage' => $selectedLanguage,
            ]
        ]);
    }
727882
public function editProduct($product_id = null)
    {
        $this->setProduct($product_id);
        $this->setTitleEditProduct();
        $this->setBreadcrumbEditProduct();

        $this->setData('product', $this->data_product);
        $this->setData('size_units', $this->convertor->getUnitNames('size'));
        $this->setData('weight_units', $this->convertor->getUnitNames('weight'));
        $this->setData('default_currency', $this->currency->getDefault());
        $this->setData('subtract_default', $this->config->get('product_subtract', 0));
        $this->setData('classes', $this->product_class->getList(array('status' => 1)));
        $this->setData('languages', $this->language->getList(array('enabled' => true)));

        $this->submitEditProduct();

        $this->setDataFieldsEditProduct();
        $this->setDataAuthorEditProduct();
        $this->setDataRelatedEditProduct();
        $this->setDataCategoriesEditProduct();
        $this->setDataImagesEditProduct();

        $this->setJsEditProduct();
        $this->outputEditProduct();
    }
1374001
public function loadProductById($productId)
    {
        $collection = $this->catalogCollection->create()
            ->addFieldToFilter('product_id', $productId)
            ->setPageSize(1);

        return $collection->getFirstItem();
    }
176530
public function getData(ProductInterface $product)
    {
        $productItemData = [
            'id'          => $product->getId(),
            'sku'         => $product->getSku(),
            'name'        => $product->getName(),
            'price'       => $this->getProductPrice($product),
            'image'       => $this->getImageUrl($product),
            'score'       => $product->getDocumentScore(),
            'is_in_stock' => $this->isInStockProduct($product),
        ];

        return $productItemData;
    }
829045
public function getProductValueModel($productId)
    {
        $dataType = ucfirst(strtolower($this->data_type));

        $method = 'productProperty' . $dataType . 'Value';

        $productPropertyModel = $this
                                        ->$method()
                                        ->whereProductId($productId)
                                        ->get();

        if ($productPropertyModel->count() == 0) {
            $valueClass = __NAMESPACE__ . '\\' . ucfirst($method);

            $valueModel = new $valueClass([
                'property_id' => $this->id,
                'product_id' => $productId
            ]);
        } else {
            $valueModel = $this->$method()->whereProductId($productId)->first();
        }

        return $valueModel;
    }
1208964
private function addAttributeData($storeId, $productIds, $indexData = [])
    {
        foreach ($this->attributeIdsByTable as $backendTable => $attributeIds) {
            $attributesData = $this->loadAttributesRawData($storeId, $productIds, $backendTable, $attributeIds);
            foreach ($attributesData as $row) {
                $productId    = (int) $row['entity_id'];
                $attribute    = $this->attributesById[$row['attribute_id']];
                $indexValues  = $this->attributeHelper->prepareIndexValue($attribute, $storeId, $row['value']);
                if (!isset($indexData[$productId])) {
                    $indexData[$productId] = [];
                }

                $indexData[$productId] += $indexValues;

                $this->addIndexedAttribute($indexData[$productId], $attribute);
            }
        }

        return $indexData;
    }
1297968
public function getRatingsByProductId($productId)
    {
        $queryBuilder = $this->queryBuilderFactory->create();
        $queryBuilder
            ->select('r.*')
            ->from('oxratings', 'r')
            ->where('r.oxobjectid = :productId')
            ->andWhere('r.oxtype = :productType')
            ->orderBy('r.oxtimestamp', 'DESC')
            ->setParameters(
                [
                    'productId'     => $productId,
                    'productType'   => 'oxarticle',
                ]
            );

        return $this->mapRatings($queryBuilder->execute()->fetchAll());
    }
851620
public function getByProductID($iProductID)
    {
        if (empty($iProductID)) {
            return $this->arResult;
        }

        //Get product data
        $obProductItem = ProductItem::make($iProductID);
        if ($obProductItem->isEmpty()) {
            return $this->arResult;
        }

        //Add product data to list
        $this->arResult[] = [
            'id'     => $obProductItem->id,
            'name'   => $obProductItem->name,
            'slug'   => $obProductItem->slug,
            'active' => true,
            'item'   => $obProductItem,
        ];

        //Get category data
        $this->addCategoryData($obProductItem->category_id);
        $this->arResult = array_reverse($this->arResult);

        return $this->arResult;
    }
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);
    }
256199
public function getCombinationId(array $field_value_ids, $product_id = null)
    {
        sort($field_value_ids);
        $combination_id = implode('_', $field_value_ids);
        return empty($product_id) ? $combination_id : "$product_id-$combination_id";
    }
325499
public function delete($product_id)
    {
        $result = null;
        $this->hook->attach('product.compare.delete.before', $product_id, $result, $this);

        if (isset($result)) {
            return (bool) $result;
        }

        $compared = $this->getList();

        if (empty($compared)) {
            return false;
        }

        $product_ids = array_flip($compared);
        unset($product_ids[$product_id]);

        $result = $this->set(array_keys($product_ids));
        $this->hook->attach('product.compare.delete.after', $product_id, $result, $this);
        return (bool) $result;
    }
564164
protected function getListCategoryProduct($store_id)
    {
        $types = $this->category_group->getTypes();

        $categories = array();
        foreach (array_keys($types) as $type) {

            $op = array(
                'type' => $type,
                'store_id' => $store_id
            );

            $data = $this->getCategoryOptionsByStore($this->category, $this->category_group, $op);
            $categories[$type] = reset($data);
        }

        return $categories;
    }
486155
protected function setProductProductBundle($product_id)
    {
        $this->data_product = $this->product->get($product_id);

        if (empty($this->data_product)) {
            $this->outputHttpStatus(404);
        }

        $this->prepareProductBundle($this->data_product);
    }
812236
protected function setProductReview($product_id)
    {
        $this->data_product = $this->product->get($product_id);

        if (empty($this->data_product['status']) || $this->data_product['store_id'] != $this->store_id) {
            $this->outputHttpStatus(404);
        }

        $this->prepareProductReview($this->data_product);
    }
1224758
public function delete($product_id)
    {
        $result = null;
        $this->hook->attach('product.compare.delete.product.before', $product_id, $result, $this);

        if (!empty($result)) {
            return (array) $result;
        }

        if (!$this->compare->delete($product_id)) {
            return $this->getResultError();
        }

        $result = $this->getResultDeleted();
        $this->hook->attach('product.compare.delete.product.after', $product_id, $result, $this);
        return (array) $result;
    }