List the latest trades for a product.

@param RequestProduct $product

@return ResponseTypeInterface
170492
public function getTrades(RequestProduct $product) {
        return $this->get(['products', $product->getProductId(), 'trades'], ResponseTrade::class, $product->toArray());
    }
229657
public function showAction(Product $product)
    {
        $deleteForm = $this->createDeleteForm($product);

        //disable notification
        $em = $this->getDoctrine()->getManager();
        $admin = $em->getRepository('CoreBundle:Actor')->find(1);//admin
        $notificationManager = $this->container->get('notification_manager');
        $notificationManager->disableNotificationByDetail(
                $admin, //current user
                $admin,//admin
                'new_product', 
                '"product":'.$product->getId().'}'
                );
        
        return array(
            'entity' => $product,
            'delete_form' => $deleteForm->createView(),
        );
    }
1207361
public function findAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();

        $productRepo = $em->getRepository(Product::class);
        $productsQb = $productRepo->findAllFilteredQB([
            'q' => $request->get('q')
        ]);
        $products = $productsQb->getQuery()->getResult();
        $productArr = [];
        /* @var Product $product */
        foreach ($products as $product) {
            $productArrItem = [
                'id' => $product->getId(),
                'text' => $product->getName() . ' - $' . $product->getPrice()
            ];

            array_push($productArr, $productArrItem);
        }

        return new JsonResponse($productArr);

    }
949294
protected static function deleteProductByIdAsyncWithHttpInfo($product_id) 
    {
        $returnType = '';  
        $request = self::deleteProductByIdRequest($product_id); 

        return self::getHttpClient()
            ->sendAsync($request, self::createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $response->getStatusCode(), $response->getHeaders()];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }
575841
private function isInStockProduct(ProductInterface $product)
    {
        $isInStock = false;
        $document = $this->getDocumentSource($product);
        if (isset($document['stock']['is_in_stock'])) {
            $isInStock = (bool) $document['stock']['is_in_stock'];
        }

        return $isInStock;
    }
732786
public function showAction(Product $product)
    {

        if (!$product) {
            throw $this->createNotFoundException('Unable to find Product entity.');
        }

        $deleteForm = $this->createDeleteForm($product->getId());

        return array(
            'entity' => $product,
            'delete_form' => $deleteForm->createView(),
        );
    }
807186
public function removeProduct(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Product\Product $product)
    {
        return $this->products->removeElement($product);
    }
460283
public function updateAction()
    {
        $this->checkAuth(AdminResources::PRODUCT, [], AccessManager::UPDATE);

        $baseForm = $this->createForm(ApiForm::PRODUCT_SALE_ELEMENTS, "form", [], [
            "validation_groups" => ["update", "Default"],
            'csrf_protection' => false,
            "cascade_validation" => true,
            "method" => "PUT",
        ]);

        $baseForm->getFormBuilder()
            ->addEventListener(
                FormEvents::PRE_SUBMIT,
                [$this, "loadProductSaleElements"],
                192
            );

        $updatedId = array();

        $con = Propel::getConnection(ProductSaleElementsTableMap::DATABASE_NAME);
        $con->beginTransaction();

        try {
            $form = $this->validateForm($baseForm);

            $entries = $form->getData();

            foreach ($entries["pse"] as $entry) {
                $this->processUpdateAction(
                    $entry,
                    $pse = ProductSaleElementsQuery::create()->findPk($entry["id"]),
                    $pse->getProduct()
                );

                $updatedId[] = $pse->getId();
            }

            $con->commit();
        } catch (\Exception $e) {
            $con->rollBack();

            return new JsonResponse(["error" => $e->getMessage()], 500);
        }

        return new JsonResponse(
            $this->getProductSaleElements(
                array_merge(
                    $this->getRequest()->query->all(),
                    [
                        "id" => implode(",", $updatedId),
                        "limit" => \count($updatedId),
                    ]
                )
            ),
            201
        );
    }
509205
public function retrievedStatForProduct(BaseProduct $product, $event, $trackingKey)
    {
        $qb = $this->createQueryBuilder('s')
            ->select('s')
            ->where('s.product = :product and s.type = :event and s.trackingKey = :key and s.createdAt between :start and :end')
            ->setParameters(array(
                'product' => $product,
                'event' => $event,
                'key' => $trackingKey,
                'start' => new \DateTime('today'),
                'end' => new \DateTime('tomorrow'),
            ))
        ;

        return $qb->getQuery()->getResult();
    }
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);
    }
471711
public function postProductAddonsAction(Request $request, $productId)
    {
        $locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));

        $addonId = $request->get('addon');
        $prices = $request->get('prices');

        $addon = $this->getManager()->saveProductAddon($productId, $addonId, $locale, $prices);

        $this->getDoctrine()->getManager()->flush();

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

        return $this->handleView($view);
    }
1227239
public function getLoadedProductCollection()
    {
        $params = $this->getRequest()->getParams();
        //check for param code and id
        if (! isset($params['customer_id']) ||
            ! isset($params['code']) ||
            ! $this->helper->isCodeValid($params['code'])
        ) {
            $this->helper->log('Recently viewed no id or valid code is set');
            return [];
        }

        $productsToDisplay = [];
        $mode = $this->getRequest()->getActionName();
        $customerId = (int) $this->getRequest()->getParam('customer_id');
        $limit = (int) $this->recommnededHelper->getDisplayLimitByMode($mode);

        //login customer to receive the recent products
        $session = $this->sessionFactory->create();
        $isLoggedIn = $session->loginById($customerId);
        $productIds = $this->catalog->getRecentlyViewed($customerId, $limit);

        //get product collection to check for salable
        $productCollection = $this->catalog->getProductCollectionFromIds($productIds);

        //show products only if is salable
        foreach ($productCollection as $product) {
            if ($product->isSalable()) {
                $productsToDisplay[$product->getId()] = $product;
            }
        }
        $this->helper->log(
            'Recentlyviewed customer  : ' . $customerId . ', mode ' . $mode
            . ', limit : ' . $limit .
            ', items found : ' . count($productIds) . ', is customer logged in : '
            . $isLoggedIn . ', products :' . count($productsToDisplay)
        );

        $session->logout();

        return $productsToDisplay;
    }
1167033
public function setProduct($product)
    {
        $this->id = $product->getId();
        $this->sku = $product->getSku();
        $this->name = $product->getName();

        $this->status = $this->statusFactory->create()
            ->getOptionText($product->getStatus());

        $options = $this->visibilityFactory->create()
            ->getOptionArray();
        $this->visibility = (string)$options[$product->getVisibility()];

        $this->getMinPrices($product);

        $this->url = $this->urlFinder->fetchFor($product);

        $this->imagePath = $this->mediaConfigFactory->create()
            ->getMediaUrl($product->getSmallImage());

        $this->stock = (float)number_format($this->getStockQty($product), 2, '.', '');

        $shortDescription = $product->getShortDescription();
        //limit short description
        if ($this->stringUtils->strlen($shortDescription) > \Dotdigitalgroup\Email\Helper\Data::DM_FIELD_LIMIT) {
            $shortDescription = mb_substr($shortDescription, 0, \Dotdigitalgroup\Email\Helper\Data::DM_FIELD_LIMIT);
        }

        $this->shortDescription = $shortDescription;

        //category data
        $count = 0;
        $categoryCollection = $product->getCategoryCollection()
            ->addNameToResult();
        foreach ($categoryCollection as $cat) {
            $this->categories[$count]['Id'] = $cat->getId();
            $this->categories[$count]['Name'] = $cat->getName();
            ++$count;
        }

        //website data
        $count = 0;
        $websiteIds = $product->getWebsiteIds();
        foreach ($websiteIds as $websiteId) {
            $website = $this->storeManager->getWebsite(
                $websiteId
            );
            $this->websites[$count]['Id'] = $website->getId();
            $this->websites[$count]['Name'] = $website->getName();
            ++$count;
        }

        $this->processProductOptions($product);

        unset(
            $this->itemFactory,
            $this->mediaConfigFactory,
            $this->visibilityFactory,
            $this->statusFactory,
            $this->helper,
            $this->storeManager
        );

        return $this;
    }
1309578
protected function updateProduct()
    {
        $this->controlAccess('product_edit');

        if ($this->product->update($this->data_product['product_id'], $this->getSubmitted())) {
            $this->redirect('admin/content/product', $this->text('Product has been updated'), 'success');
        }

        $this->redirect('', $this->text('Product has not been updated'), 'warning');
    }
945472
public function stockIncreaseDoAction(Request $request, Product $product)
    {
        $em = $this->getDoctrine()->getManager();
        $quantity = $request->get('quantity');
        $affectRawMaterial = $request->get('affect_raw_materials');

        if ($quantity && $quantity > 0) {

            if ($request->get('warehouse')) {
                $warehouse = $em->getRepository(Warehouse::class)->find($request->get('warehouse'));
            } else {
                $warehouse = $product->getWarehouse();
            }
            if ($warehouse) {
                $stockService = $this->get('amulen.shop.service.stock');
                $valid = $stockService->entryStock($warehouse, $product, $quantity, $affectRawMaterial, $request->get('comments'));

                return $this->redirect($this->generateUrl('admin_product_show', array('id' => $product->getId())));
            } else {
                $this->addFlash('warning', "Seleccione un deposito.");
            }

        } else {
            $this->addFlash('warning', "La cantidad no es válida.");
        }

        return $this->redirect($this->generateUrl('admin_product_stock_increase', array('id' => $product->getId())));
    }
250698
public function switchProductOptionsAjax()
    {
        $product_id = $this->getPosted('product_id');
        $field_value_ids = $this->getPosted('values', array(), true, 'array');

        if (empty($product_id)) {
            return array();
        }

        $product = $this->product->get($product_id);
        $response = $this->sku->selectCombination($product, $field_value_ids);
        $response += $product;

        $this->setItemPriceCalculated($response, $this->product);
        $this->setItemPriceFormatted($response, $this->price, $this->current_currency);

        return $response;
    }
1110025
public function addProduct(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Product\Product $product)
    {
        $this->products[] = $product;

        return $this;
    }