Adds stock levels to the given product in the database.

@param string $productid ID of the product item where the stock levels should be associated to
@param array $data Two dimensional associative list of product stock data
5816
protected function _addProductStock( $productid, array $data )
	{
		$manager = MShop_Factory::createManager( $this->_getContext(), 'product/stock/warehouse' );

		$warehouses = array();
		foreach( $manager->searchItems( $manager->createSearch() ) as $id => $item ) {
			$warehouses[ $item->getCode() ] = $id;
		}

		$manager = MShop_Factory::createManager( $this->_getContext(), 'product/stock' );

		$item = $manager->createItem();
		$item->setProductId( $productid );

		foreach( $data as $entry )
		{
			$item->setId( null );
			$item->setDateBack( $entry['dateback'] );
			$item->setStockLevel( $entry['stocklevel'] );
			$item->setWarehouseId( $warehouses[ $entry['warehouse'] ] );

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

        return $collection->getFirstItem();
    }
582076
protected function _addRefItems( array $entry, $id )
	{
		if( isset( $entry['stock'] ) ) {
			$this->_addProductStock( $id, $entry['stock'] );
		}

		if( isset( $entry['attribute'] ) ) {
			$this->_addAttributes( $id, $entry['attribute'], 'product' );
		}

		if( isset( $entry['media'] ) ) {
			$this->_addMedia( $id, $entry['media'], 'product' );
		}

		if( isset( $entry['price'] ) ) {
			$this->_addPrices( $id, $entry['price'], 'product' );
		}

		if( isset( $entry['text'] ) ) {
			$this->_addTexts( $id, $entry['text'], 'product' );
		}

		if( isset( $entry['product'] ) ) {
			$this->_addProducts( $id, $entry['product'], 'product' );
		}
	}
357725
public function addItem($parentId, $data)
    {
        if (empty($parentId)) {
            $this->items[0][] = $data;
        } else {
            $this->items[$parentId][] = $data;
        }
    }
439182
public function addData($storeId, array $indexData)
    {
        $categoryData = $this->resourceModel->loadCategoryData($storeId, array_keys($indexData));

        foreach ($categoryData as $categoryDataRow) {
            $productId = (int) $categoryDataRow['product_id'];
            unset($categoryDataRow['product_id']);

            $categoryDataRow = array_merge(
                $categoryDataRow,
                [
                    'category_id' => (int) $categoryDataRow['category_id'],
                    'is_parent'   => (bool) $categoryDataRow['is_parent'],
                    'name'        => (string) $categoryDataRow['name'],
                ]
            );

            if (isset($categoryDataRow['position']) && $categoryDataRow['position'] !== null) {
                $categoryDataRow['position'] = (int) $categoryDataRow['position'];
            }

            if (isset($categoryDataRow['is_blacklisted'])) {
                $categoryDataRow['is_blacklisted'] = (bool) $categoryDataRow['is_blacklisted'];
            }

            $indexData[$productId]['category'][] = array_filter($categoryDataRow);
        }

        return $indexData;
    }
44355
public function actionAddAdditional(int $productId, int $languageId)
    {
        $additionalProductsCategories = Category::find()->with('products')
            ->where(['additional_products' => true])->all();

        $productAdditionalProducts = ProductAdditionalProduct::find()->where(['product_id' => $productId])->all();
        return $this->render('../product/save', [
            'viewName' => '../additional-product/add-additional',
            'selectedLanguage' => Language::findOne($languageId),
            'product' => Product::findOne($productId),
            'languages' => Language::find()->all(),

            'params' => [
                'additionalProductsCategories' => $additionalProductsCategories,
                'productAdditionalProducts' => $productAdditionalProducts,
                'productId' => $productId
            ]
        ]);
    }
706991
protected function addOptions(array $data)
    {
        if (empty($data['combination'])) {
            return false;
        }

        foreach ($data['combination'] as $combination) {

            if (empty($combination['fields'])) {
                continue;
            }

            foreach ($combination['fields'] as $field_id => $field_value_id) {

                $options = array(
                    'type' => 'option',
                    'field_id' => $field_id,
                    'product_id' => $data['product_id'],
                    'field_value_id' => $field_value_id
                );

                $this->product_field->add($options);
            }
        }

        return true;
    }
1058006
public function addProduct($dealId, array $data)
    {
        //if there is no product_id set throw error as it is a required field
        if (!isset($data['product_id'])) {
            throw new PipedriveMissingFieldError('You must include a "pdoruct_id" field when adding a product to a deal');
        }
        //if there is no item_price set throw error as it is a required field
        if (!isset($data['item_price'])) {
            throw new PipedriveMissingFieldError('You must include a "item_price" field when adding a product to a deal');
        }
        //if there is no quantity set throw error as it is a required field
        if (!isset($data['quantity'])) {
            throw new PipedriveMissingFieldError('You must include a "quantity" field when adding a product to a deal');
        }

        return $this->curl->post('deals/' . $dealId . '/products', $data);
    }
848412
public function actionAdd($productId)
    {
        if (!empty($productId)) {
            if (!Yii::$app->user->isGuest) {
                $model = new FavoriteProduct();

                $model->product_id = $productId;
                $model->user_id = Yii::$app->user->id;

                if ($model->save()) {
                    if (Yii::$app->request->isAjax) {
                        return Yii::t('shop', 'You have successfully added this product to favorites.');
                    }
                    else {
                        Yii::$app->session->setFlash('success', Yii::t('shop', 'You have successfully added this product to favorites.'));
                    }
                }
                else {
                    if (Yii::$app->request->isAjax) {
                        return Yii::t('shop', 'Error has occurred.');
                    }
                    else {
                        Yii::$app->session->setFlash('error', Yii::t('shop', 'Error has occurred.'));
                    }
                }
                return $this->redirect(Yii::$app->request->referrer);
            }
            throw new ForbiddenHttpException();
        }
        else throw new NotFoundHttpException();
    }
1362186
public function setProductTemplateAction($productId)
    {
        // Check current user authorization
        if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) {
            return $response;
        }

        $product = ProductQuery::create()->findPk($productId);

        if ($product != null) {
            $template_id = \intval($this->getRequest()->get('template_id', 0));

            $this->dispatch(
                TheliaEvents::PRODUCT_SET_TEMPLATE,
                new ProductSetTemplateEvent($product, $template_id, $this->getCurrentEditionCurrency()->getId())
            );
        }

        return $this->redirectToEditionTemplate();
    }
905141
protected function withBulk(array $data = [])
    {
        if (!$this->isArray($data)) {
            return;
        }

        foreach ($data['data'] as $index => $element) {
            $row = $this->data->addChild('row');

            $row->addAttribute('no', ++$index);

            foreach ($element as $key => $value) {
                $child = $row->addChild('FL', $value);

                $child->addAttribute('val', $key);
            }
        }
    }
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();
    }
750486
public function removeItem(int $productId, int $combinationId = null)
    {
        if (!\Yii::$app->user->isGuest) {
            $order = Order::find()->where([
                'user_id' => \Yii::$app->user->id,
                'status' => OrderStatus::STATUS_INCOMPLETE
            ])->one();
            if (!empty($order)) {
                $orderProduct = OrderProduct::find()->where([
                    'product_id' => $productId,
                    'combination_id' => $combinationId,
                    'order_id' => $order->id
                ])->one();
                if (!empty($orderProduct)) {
                    $orderProduct->delete();
                }
            }
        } else {
            $session = Yii::$app->session;
            if ($session->has(self::SESSION_KEY)) {
                $products = $session[self::SESSION_KEY];
                foreach ($products as $key => $product) {
                    if ($product['id'] == $productId && $product['combinationId'] == $combinationId)
                        unset($_SESSION[self::SESSION_KEY][$key]);
                }
            }
        }
        $this->trigger(self::EVENT_AFTER_REMOVE_PRODUCT);
    }
463328
public function getStockData($minProductId, $maxProductId)
    {
        $this->stockData = [];
        $stockQuery = $this->_resource->getConnection()->select()
            ->from($this->getTable('cataloginventory_stock_item'), ['is_in_stock', 'qty', 'product_id'])
            ->where('product_id >= ?', $minProductId)
            ->where('product_id <= ?', $maxProductId)
            ->where('stock_id = ?', 1);

        $this->iterator->walk(
            (string)$stockQuery,
            [[$this, 'handleStockItem']],
            [],
            $this->_resource->getConnection()
        );

        return $this->stockData;
    }
763534
private function retrieveProductById($productId)
    {
        // Fetch product.
        $product = $this->productRepository->find($productId);
        if (!$product) {
            throw new ProductNotFoundException($productId);
        }

        return $product;
    }
1191942
public function getProductRatingById($productId)
    {
        $this->validateProductId($productId);

        $queryBuilder = $this->queryBuilderFactory->create();
        $queryBuilder
            ->select([
                'OXID',
                'OXRATING',
                'OXRATINGCNT'
            ])
            ->from('oxarticles')
            ->where('oxid = :productId')
            ->setMaxResults(1)
            ->setParameter('productId', $productId);

        return $this->mapper->map(
            new ProductRating(),
            $queryBuilder->execute()->fetch()
        );
    }
854849
protected function addAttributes(array $data)
    {
        if (empty($data['field']['attribute'])) {
            return false;
        }

        foreach ($data['field']['attribute'] as $field_id => $field_value_ids) {
            foreach ((array) $field_value_ids as $field_value_id) {

                $options = array(
                    'type' => 'attribute',
                    'field_id' => $field_id,
                    'product_id' => $data['product_id'],
                    'field_value_id' => $field_value_id
                );

                $this->product_field->add($options);
            }
        }

        return true;
    }