/**
  * Process given product and change its type if needed
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return void
  */
 public function processProduct(Product $product)
 {
     if (in_array($product->getTypeId(), $this->compatibleTypes)) {
         $product->setTypeInstance(null);
         $productTypeId = $this->weightResolver->resolveProductHasWeight($product) ? Type::TYPE_SIMPLE : Type::TYPE_VIRTUAL;
         $product->setTypeId($productTypeId);
     }
 }
Ejemplo n.º 2
0
 /**
  * Change product type to downloadable if needed
  *
  * @param \Magento\Catalog\Model\Product\TypeTransitionManager $subject
  * @param Closure $proceed
  * @param \Magento\Catalog\Model\Product $product
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundProcessProduct(\Magento\Catalog\Model\Product\TypeTransitionManager $subject, Closure $proceed, \Magento\Catalog\Model\Product $product)
 {
     $isTypeCompatible = in_array($product->getTypeId(), [\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE, \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL, \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE]);
     $downloadableData = $this->request->getPost('downloadable');
     $hasDownloadableData = false;
     if (isset($downloadableData)) {
         foreach ($downloadableData as $data) {
             foreach ($data as $rowData) {
                 if (empty($rowData['is_delete'])) {
                     $hasDownloadableData = true;
                     break 2;
                 }
             }
         }
     }
     if ($isTypeCompatible && $hasDownloadableData && !$this->weightResolver->resolveProductHasWeight($product)) {
         $product->setTypeId(\Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE);
         return;
     }
     $proceed($product);
 }