Jump to content

[PS 1.7] plik na wzór NewProductsProductSearchProvider


chomiczek

Recommended Posts

Witajcie mam problem z taką rzeczą (być może źle podszedłem do tematu - proszę mnie wtedy nakierować), a mianowicie w controllers/front/listing/ utworzyłem sobie plik OutletController.php o zawartości:
 

<?PHP
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
use PrestaShop\PrestaShop\Adapter\Outlet\OutletProductSearchProvider;


	class OutletControllerCore extends ProductListingFrontController
	{

		public $php_self = 'outlet';

		public function initContent()
		{
			parent::initContent();
			$this->doProductSearch('catalog/listing/new-products');
		}

		protected function getProductSearchQuery()
		{
			$query = new ProductSearchQuery();
			$query
				->setQueryType('outlet')
				->setSortOrder(new SortOrder('product', 'date_add', 'desc'))
			;

			return $query;
		}

		protected function getDefaultProductSearchProvider()
		{
			return new OutletProductSearchProvider(
				$this->getTranslator()
			);
		}

		public function getListingLabel()
		{
			return $this->trans(
				'Outlet',
				array(),
				'Shop.Theme.CatalorunQueryg'
			);
		}
	}
?>

Dodatkowo w src/Adapter utworzyłem katalog Outlet i w nim plik OutletProductSearchProvider.php z zawartością:
 

<?PHP
namespace PrestaShop\PrestaShop\Adapter\Outlet;

	use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchProviderInterface;
	use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchContext;
	use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
	use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchResult;
	use PrestaShop\PrestaShop\Core\Product\Search\SortOrderFactory;
	use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
	use Symfony\Component\Translation\TranslatorInterface;
	use Product;

	class OutletProductSearchProvider implements ProductSearchProviderInterface
	{
		private $translator;
		private $sortOrderFactory;

		public function __construct(
			TranslatorInterface $translator
		) {
			$this->translator = $translator;
			$this->sortOrderFactory = new SortOrderFactory($this->translator);
		}

		private function getProductsOrCount(
			ProductSearchContext $context,
			ProductSearchQuery $query,
			$type = 'products'
		) {
			return Product::getPricesDrop(
				$context->getIdLang(),
				$query->getPage(),
				$query->getResultsPerPage(),
				$type !== 'products',
				$query->getSortOrder()->toLegacyOrderBy(),
				$query->getSortOrder()->toLegacyOrderWay()
			);
		}

		public function runQuery(
			ProductSearchContext $context,
			ProductSearchQuery $query
		) {
			if (!$products = $this->getProductsOrCount($context, $query, 'products')) {
				$products = array();
			}
			$count = $this->getProductsOrCount($context, $query, 'count');

			$result = new ProductSearchResult();

			if (!empty($products)) {
				$result
					->setProducts($products)
					->setTotalProductsCount($count);

				$result->setAvailableSortOrders(
					[
						(new SortOrder('product', 'name', 'asc'))->setLabel(
							$this->translator->trans('Name, A to Z', array(), 'Shop.Theme.Catalog')
						),
						(new SortOrder('product', 'name', 'desc'))->setLabel(
							$this->translator->trans('Name, Z to A', array(), 'Shop.Theme.Catalog')
						),
						(new SortOrder('product', 'price', 'asc'))->setLabel(
							$this->translator->trans('Price, low to high', array(), 'Shop.Theme.Catalog')
						),
						(new SortOrder('product', 'price', 'desc'))->setLabel(
							$this->translator->trans('Price, high to low', array(), 'Shop.Theme.Catalog')
						)
					]
				);
			}

			return $result;
		}
	}
?>

Strona utworzona w panelu, ale przy próbie wywołania URLa (mojadomena.pl/outlet) dostaje błąd 500, a w logu widzę takie coś:
 

2018-06-28 08:44:24.118999 [NOTICE] [176.116.202.247:24393] [STDERR] PHP Fatal error:  Uncaught Error: Class 'PrestaShop\PrestaShop\Adapter\Outlet\OutletProductSearchProvider' not found in /home/usermoj/domains/mojadomena.pl/public_html/controllers/front/listing/OutletController.php:36
Stack trace:
#0 /home/usermoj/domains/mojadomena.pl/public_html/classes/controller/ProductListingFrontController.php(287): OutletControllerCore->getDefaultProductSearchProvider()
#1 /home/usermoj/domains/mojadomena.pl/public_html/classes/controller/ProductListingFrontController.php(540): ProductListingFrontControllerCore->getProductSearchVariables()
#2 /home/usermoj/domains/mojadomena.pl/public_html/controllers/front/listing/OutletController.php(20): ProductListingFrontControllerCore->doProductSearch('catalog/listing...')
#3 /home/usermoj/domains/mojadomena.pl/public_html/classes/controller/Controller.php(253): OutletControllerCore->initContent()
#4 /home/usermoj/domains/mojadomena.pl/public_html/classes/Dispatcher.php(428): ControllerCore->run()
#5 /home/usermoj/domains/teraz in /home/usermoj/domains/mojadomena.pl/public_html/controllers/front/listing/OutletController.php on line 36

Jakiś pomysł/sugestia?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...