@name            removeFilesFromProduct ()

@since           1.0.6
@version         1.5.3
@author          Can Berkol

@param           array $files
@param           mixed $product

@return          \BiberLtd\Bundle\CoreBundle\Responses\ModelResponse
330679
public function removeFilesFromProduct($files, $product)
	{
		$timeStamp = time();
		$response = $this->getProduct($product);
		if ($response->error->exist) {
			return $response;
		}
		$product = $response->result->set;
		$idsToRemove = array();
		$fmModel = new FMMService\FileManagementModel($this->kernel, $this->dbConnection, $this->orm);
		foreach ($files as $file) {
			$response = $fmModel->getFile($file);
			if ($response->error->exist) {
				continue;
			}
			$idsToRemove[] = $response->result->set->getId();
		}
		$in = ' IN (' . implode(',', $idsToRemove) . ')';
		$qStr = 'DELETE FROM ' . $this->entity['fop']['name'] . ' ' . $this->entity['fop']['alias']
			. ' WHERE ' . $this->entity['fop']['alias'] . '.product = ' . $product->getId()
			. ' AND ' . $this->entity['fop']['alias'] . '.file ' . $in;

		$q = $this->em->createQuery($qStr);
		$result = $q->getResult();

		$deleted = true;
		if (!$result) {
			$deleted = false;
		}
		if ($deleted) {
			return new ModelResponse(null, 0, 0, null, false, 'S:D:001', 'Selected entries have been successfully removed from database.', $timeStamp, time());
		}
		return new ModelResponse(null, 0, 0, null, true, 'E:E:001', 'Unable to delete all or some of the selected entries.', $timeStamp, time());
	}
33856
public function addProduct(Product $product)
    {
        $this->products->add($product);

        $this->setOwningSideRelation($product);

        return $this;
    }
1074
public function RemoveProductFromProductSet(\Google\Cloud\Vision\V1\RemoveProductFromProductSetRequest $argument,
      $metadata = [], $options = []) {
        return $this->_simpleRequest('/google.cloud.vision.v1.ProductSearch/RemoveProductFromProductSet',
        $argument,
        ['\Google\Protobuf\GPBEmpty', 'decode'],
        $metadata, $options);
    }
983391
public function post(array $products) {
    $storeId = '';
    $requestHeaders = $this->currentRequest->headers;
    if ($requestHeaders->has('X-ACM-UUID')) {
      $storeId = $requestHeaders->get('X-ACM-UUID');
    }

    \Drupal::logger('acm_sku')->info("Updating products for acm_uuid " . $storeId . ".");

    // To avoid even E_RECOVERABLE_ERROR, we set our custom error handler.
    set_error_handler([$this, 'errorHandler']);

    $response = $this->productManager->synchronizeProducts($products, $storeId);
    return (new ModifiedResourceResponse($response));
  }
856087
public function removeFile(\Haven\CoreBundle\Entity\File\File $files)
    {
        $this->files->removeElement($files);
    }
138177
public function remove($files)
    {
        foreach ($files as $file) {
            try {
                $this->filesystem->delete($file);
            }
            catch (Exception $e) {
                // Ignore not found exceptions
            }
        }
    }
1055999
protected function filterFiles($files)
    {
        if (! $files) {
            return;
        }

        foreach ($files as $key => $file) {
            if (is_array($file)) {
                $files[$key] = $this->filterFiles($files[$key]);
            }

            if (empty($files[$key])) {
                unset($files[$key]);
            }
        }

        return $files;
    }
807186
public function removeProduct(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Product\Product $product)
    {
        return $this->products->removeElement($product);
    }
745696
public function delete($files, array $options = [])
    {
        collect(array_wrap($options))->each(function ($file) {
            Storage::delete(sprintf('%s/%s', $this->uploadFolder, array_get($file, 'filename')));
        });

        return response()->json('Files deleted', 200);
    }
864947
protected function prepareProduct(array &$product)
    {
        $selected = $this->getSelectedCombinationProduct($product);
        $this->unshiftSelectedImageProduct($selected, $product);

        $this->setItemImages($product, 'product', $this->image);
        $this->setItemThumbProduct($product, $this->image);
        $this->setItemProductInComparison($product, $this->product_compare);
        $this->setItemProductBundle($product, $this->product, $this->image);
        $this->setItemProductInWishlist($product, $this->wishlist);

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

        $product['selected_combination'] = $selected;
        $product['total_reviews'] = $this->getTotalReviewsProduct($product);

        $this->setItemProductFields($product, $this->image, $this->product_class);
    }
748503
public function deleteImage($productId)
    {
        $productId = (int) $productId;

        if ($productId == 0 || $productId == '') {
            $message = 'Product ID not correct: ' . $productId;
            $this->log($message);
            die(json_encode([
                'status' => 0,
                'msg' => $message
            ]));
        }

        $product = $this->Product->find('all', [
            'conditions' => [
                'Products.id_product' => $productId
            ],
            'contain' => [
                'Images',
                'Manufacturers'
            ]
        ])->first();
        
        $this->Product->changeImage(
            [
                [$productId => 'no-image']
            ]
        );

        $actionLogMessage = __d('admin', 'Image_ID_{0}_from_manufacturer_{1}_was_deleted_successfully_Product_{1}_Manufacturer_{2}.', [
            $product->image->id_image,
            '<b>' . $product->name . '</b>',
            '<b>' . $product->manufacturer->name . '</b>'
        ]);

        $this->Flash->success($actionLogMessage);
        $this->ActionLog->customSave('product_image_deleted', $this->AppAuth->getUserId(), $productId, 'products', $actionLogMessage);

        $this->getRequest()->getSession()->write('highlightedRowId', $productId);

        $this->redirect($this->referer());
    }
895813
public function afterGetFiles(RequireJsCollector $subject, array $files)
    {
        $magentoVersion = $this->productMetadata->getVersion();

        if (version_compare($magentoVersion, '2.2.0', '>=')) {

            foreach ($files as $index => $file) {

                if ($file->getModule() === 'Bolt_Boltpay') {
                    unset($files[$index]);
                }
            }
        }
        return $files;
    }
849864
protected function prepareProductsCompare(array &$products)
    {
        foreach ($products as $product_id => &$product) {
            $product['field'] = $this->product_field->getList($product_id);
            $this->setItemProductFields($product, $this->image, $this->product_class);
        }
    }
1360131
public function remove($files)
    {
        if ($files instanceof \Traversable) {
            $files = iterator_to_array($files, false);
        } elseif (!is_array($files)) {
            $files = array($files);
        }
        $files = array_reverse($files);
        foreach ($files as $file) {
            if (is_link($file)) {
                // See https://bugs.php.net/52176
                if (!(self::box('unlink', $file) || '\\' !== DIRECTORY_SEPARATOR || self::box('rmdir', $file)) && file_exists($file)) {
                    throw new IOException(sprintf('Failed to remove symlink "%s": %s.', $file, self::$lastError));
                }
            } elseif (is_dir($file)) {
                $this->remove(new \FilesystemIterator($file, \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::SKIP_DOTS));

                if (!self::box('rmdir', $file) && file_exists($file)) {
                    throw new IOException(sprintf('Failed to remove directory "%s": %s.', $file, self::$lastError));
                }
            } elseif (!self::box('unlink', $file) && file_exists($file)) {
                throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, self::$lastError));
            }
        }
    }
144312
protected function prepareProductsForFrontend($products)
    {
        $this->Product = TableRegistry::getTableLocator()->get('Products');
        $this->Manufacturer = TableRegistry::getTableLocator()->get('Manufacturers');
        $this->ProductAttribute = TableRegistry::getTableLocator()->get('ProductAttributes');

        foreach ($products as &$product) {
            $grossPrice = $this->Product->getGrossPrice($product['id_product'], $product['price']);
            $product['gross_price'] = $grossPrice;
            $product['tax'] = $grossPrice - $product['price'];
            $product['is_new'] = $this->Product->isNew($product['created']);
            
            if ($this->getRequest()->getSession()->check('Auth.instantOrderCustomer')) {
                $product['next_delivery_day'] = Configure::read('app.timeHelper')->getCurrentDateForDatabase();
            } else {
                $product['next_delivery_day'] = $this->Product->calculatePickupDayRespectingDeliveryRhythm(
                    $this->Product->newEntity([
                        'delivery_rhythm_order_possible_until' => $product['delivery_rhythm_order_possible_until'] == '' ? null : new FrozenDate($product['delivery_rhythm_order_possible_until']),
                        'delivery_rhythm_first_delivery_day' => $product['delivery_rhythm_first_delivery_day'] == '' ? null : new FrozenDate($product['delivery_rhythm_first_delivery_day']),
                        'delivery_rhythm_type' => $product['delivery_rhythm_type'],
                        'delivery_rhythm_count' => $product['delivery_rhythm_count'],
                        'delivery_rhythm_send_order_list_weekday' => $product['delivery_rhythm_send_order_list_weekday'],
                        'delivery_rhythm_send_order_list_day' => $product['delivery_rhythm_send_order_list_day'],
                        'is_stock_product' => $product['is_stock_product']
                    ]
                ));
            }
            $product['attributes'] = [];

            if ($this->AppAuth->isTimebasedCurrencyEnabledForCustomer()) {
                if ($this->Manufacturer->getOptionTimebasedCurrencyEnabled($product['timebased_currency_enabled'])) {
                    $product['timebased_currency_money_incl'] = $this->Manufacturer->getTimebasedCurrencyMoney($product['gross_price'], $product['timebased_currency_max_percentage']);
                    $product['timebased_currency_money_excl'] = $this->Manufacturer->getTimebasedCurrencyMoney($product['price'], $product['timebased_currency_max_percentage']);
                    $product['timebased_currency_seconds'] = $this->Manufacturer->getCartTimebasedCurrencySeconds($product['gross_price'], $product['timebased_currency_max_percentage']);
                    $product['timebased_currency_manufacturer_limit_reached'] = $this->Manufacturer->hasManufacturerReachedTimebasedCurrencyLimit($product['id_manufacturer']);
                }
                
            }

            $attributes = $this->ProductAttribute->find('all', [
                'conditions' => [
                    'ProductAttributes.id_product' => $product['id_product']
                ],
                'contain' => [
                    'StockAvailables',
                    'ProductAttributeCombinations.Attributes',
                    'DepositProductAttributes',
                    'UnitProductAttributes'
                ]
            ]);
            $preparedAttributes = [];
            foreach ($attributes as $attribute) {
                $preparedAttributes['ProductAttributes'] = [
                    'id_product_attribute' => $attribute->id_product_attribute
                ];
                $grossPrice = $this->Product->getGrossPrice($attribute->id_product, $attribute->price);
                $preparedAttributes['ProductAttributes'] = [
                    'gross_price' => $grossPrice,
                    'tax' => $grossPrice - $attribute->price,
                    'default_on' => $attribute->default_on,
                    'id_product_attribute' => $attribute->id_product_attribute
                ];
                $preparedAttributes['StockAvailables'] = [
                    'quantity' => $attribute->stock_available->quantity,
                    'quantity_limit' => $attribute->stock_available->quantity_limit
                ];
                $preparedAttributes['DepositProductAttributes'] = [
                    'deposit' => !empty($attribute->deposit_product_attribute) ? $attribute->deposit_product_attribute->deposit : 0
                ];
                $preparedAttributes['ProductAttributeCombinations'] = [
                    'Attributes' => [
                        'name' => $attribute->product_attribute_combination->attribute->name,
                        'can_be_used_as_unit' => $attribute->product_attribute_combination->attribute->can_be_used_as_unit
                    ]
                ];
                $preparedAttributes['Units'] = [
                    'price_per_unit_enabled' => !empty($attribute->unit_product_attribute) ? $attribute->unit_product_attribute->price_per_unit_enabled : 0,
                    'price_incl_per_unit' => !empty($attribute->unit_product_attribute) ? $attribute->unit_product_attribute->price_incl_per_unit : 0,
                    'unit_name' => !empty($attribute->unit_product_attribute) ? $attribute->unit_product_attribute->name : '',
                    'unit_amount' => !empty($attribute->unit_product_attribute) ? $attribute->unit_product_attribute->amount : 0,
                    'quantity_in_units' => !empty($attribute->unit_product_attribute) ? $attribute->unit_product_attribute->quantity_in_units : 0
                ];

                if ($this->AppAuth->isTimebasedCurrencyEnabledForCustomer()) {
                    if ($this->Manufacturer->getOptionTimebasedCurrencyEnabled($product['timebased_currency_enabled'])) {
                        $preparedAttributes['timebased_currency_money_incl'] = $this->Manufacturer->getTimebasedCurrencyMoney($grossPrice, $product['timebased_currency_max_percentage']);
                        $preparedAttributes['timebased_currency_money_excl'] = $this->Manufacturer->getTimebasedCurrencyMoney($attribute->price, $product['timebased_currency_max_percentage']);
                        $preparedAttributes['timebased_currency_seconds'] = $this->Manufacturer->getCartTimebasedCurrencySeconds($grossPrice, $product['timebased_currency_max_percentage']);
                        $preparedAttributes['timebased_currency_manufacturer_limit_reached'] = $this->Manufacturer->hasManufacturerReachedTimebasedCurrencyLimit($product['id_manufacturer']);
                    }
                }

                $product['attributes'][] = $preparedAttributes;
            }
        }
        return $products;
    }
612052
public function removeLibrinfoFile(File $file)
    {
        if ($this->images->contains($file)) {
            $this->images->removeElement($file);
        }

        return $this;
    }
819446
public function removePackage(array $packageNames, $areDevPackages = false)
    {
        $packages = $this->formatPackageNames($packageNames);
        $file = $this->embeddedComposer->getExternalComposerFilename();
        $jsonFile = new JsonFile($file);
        $json = new JsonConfigSource($jsonFile);
        $composerDefinition = $jsonFile->read();
        $type = $areDevPackages ? 'require-dev' : 'require';

        foreach ($packages as $name => $version) {
            if (isset($composerDefinition[$type][$name])) {
                $json->removeLink($type, $name);
                unset($composerDefinition[$type][$name]);

                continue;
            }

            $this->io->writeError(sprintf(
               'Package: "%s" is not required and has not been removed.',
               $name
            ));
        }

        return $composerDefinition[$type];
    }