Skip to content

Commit

Permalink
Merge pull request #36394 from nicosomb/merge-81-develop
Browse files Browse the repository at this point in the history
Merge `8.1.x` into `develop`
  • Loading branch information
nicosomb committed Jun 21, 2024
2 parents 0e52338 + 82382dc commit 0316dda
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 1 deletion.
2 changes: 2 additions & 0 deletions admin-dev/themes/new-theme/js/app/utils/init-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import TextWithLengthCounter from '@components/form/text-with-length-counter';
import TinyMCEEditor from '@js/components/tinymce-editor';
import TranslatableField from '@js/components/translatable-field';
import TranslatableInput from '@js/components/translatable-input';
import EntitySearchInput from '@js/components/entity-search-input';

// Grid extensions
import AsyncToggleColumnExtension from '@components/grid/extension/column/common/async-toggle-column-extension';
Expand Down Expand Up @@ -160,6 +161,7 @@ const initPrestashopComponents = (): void => {
TinyMCEEditor,
TranslatableField,
TranslatableInput,
EntitySearchInput,
};
};
export default initPrestashopComponents;
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class RelatedProductsManager {

constructor(eventEmitter: EventEmitter) {
this.eventEmitter = eventEmitter;
this.entitySearchInput = new EntitySearchInput($(ProductMap.relatedProducts.searchInput), {
this.entitySearchInput = new window.prestashop.component.EntitySearchInput($(ProductMap.relatedProducts.searchInput), {
onRemovedContent: () => {
this.eventEmitter.emit(ProductEventMap.updateSubmitButtonState);
},
Expand Down
10 changes: 10 additions & 0 deletions controllers/front/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,11 @@ public function displayAjaxRefresh()
$product = $this->getTemplateVarProduct();
$minimalProductQuantity = $this->getProductMinimalQuantity($product);

// If the product is already in the cart, we can set the minimal quantity to 1
if ($product['cart_quantity'] >= $minimalProductQuantity) {
$minimalProductQuantity = 1;
}

ob_end_clean();
header('Content-Type: application/json');
$this->ajaxRender(json_encode([
Expand Down Expand Up @@ -1223,6 +1228,7 @@ public function getTemplateVarProduct()
$product['out_of_stock'] = (int) $this->product->out_of_stock;
$product['id_product_attribute'] = $this->getIdProductAttributeByGroupOrRequestOrDefault();
$product['minimal_quantity'] = $this->getProductMinimalQuantity($product);
$product['cart_quantity'] = $this->context->cart->getProductQuantity($product['id_product'], $product['id_product_attribute'])['quantity'];
$product['quantity_wanted'] = $this->getRequiredQuantity($product);
$product['extraContent'] = $extraContentFinder->addParams(['product' => $this->product])->present();
$product['ecotax_tax_inc'] = $this->product->getEcotax(null, true, true);
Expand Down Expand Up @@ -1344,6 +1350,10 @@ protected function getRequiredQuantity(array $product)
$requiredQuantity = $product['minimal_quantity'];
}

if ($product['cart_quantity'] >= $requiredQuantity) {
return 0;
}

return $requiredQuantity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,14 @@ protected function getGridActions()
],
])
)
->add(
(new LinkGridAction('export'))
->setName($this->trans('Export', [], 'Admin.Actions'))
->setIcon('cloud_download')
->setOptions([
'route' => 'admin_products_export',
])
)
->add(
(new SimpleGridAction('common_refresh_list'))
->setName($this->trans('Refresh list', [], 'Admin.Advparameters.Feature'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\ProductGridDefinitionFactory;
use PrestaShop\PrestaShop\Core\Search\Filters\ProductFilters;
use PrestaShop\PrestaShop\Core\Security\Permission;
use PrestaShopBundle\Component\CsvResponse;
use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use PrestaShopBundle\Controller\BulkActionsTrait;
use PrestaShopBundle\Entity\AdminFilter;
Expand Down Expand Up @@ -711,6 +712,52 @@ public function disableForAllShopsAction(int $productId): RedirectResponse
return $this->updateProductStatusByShopConstraint($productId, false, ShopConstraint::allShops());
}

/**
* Export filtered products
*
* @AdminSecurity("is_granted('read', request.get('_legacy_controller'))")
*
* @param ProductFilters $filters
*
* @return CsvResponse
*/
public function exportAction(ProductFilters $filters)
{
$productGridFactory = $this->get('prestashop.core.grid.factory.product');
$grid = $productGridFactory->getGrid($filters);

$headers = [
'id_product' => 'Product ID',
'image_link' => $this->trans('Image', 'Admin.Global'),
'name' => $this->trans('Name', 'Admin.Global'),
'reference' => $this->trans('Reference', 'Admin.Global'),
'name_category' => $this->trans('Category', 'Admin.Global'),
'price' => $this->trans('Price (tax excl.)', 'Admin.Catalog.Feature'),
'price_final' => $this->trans('Price (tax incl.)', 'Admin.Catalog.Feature'),
'sav_quantity' => $this->trans('Quantity', 'Admin.Global'),
];

$data = [];

foreach ($grid->getData()->getRecords()->all() as $record) {
$data[] = [
'id_product' => $record['id_product'],
'image_link' => $record['image'],
'name' => $record['name'],
'reference' => $record['reference'],
'name_category' => $record['category'],
'price' => $record['final_price_tax_excluded'],
'price_final' => $record['price_tax_included'],
'sav_quantity' => $record['quantity'],
];
}

return (new CsvResponse())
->setData($data)
->setHeadersData($headers)
->setFileName('product_' . date('Y-m-d_His') . '.csv');
}

/**
* Updates product position.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ admin_products_preview:
requirements:
productId: \d+

admin_products_export:
path: /export
methods: [ GET ]
defaults:
_controller: PrestaShopBundle\Controller\Admin\Sell\Catalog\Product\ProductController::exportAction
_legacy_controller: AdminProducts
_legacy_link: AdminProducts

admin_products_search:
path: /
methods: [ POST ]
Expand Down

0 comments on commit 0316dda

Please sign in to comment.