0

I am using sonata-ecommerce. When I try to open single product page then Controller error occure. Here is detailed error. "Application\Sonata\ProductBundle\Controller\ProductController::viewAction()" requires that you provide a value for the "$product" argument (because there is no default value or because there is a non optional argument after this one).

enter image description here

Neha
  • 13
  • 4
  • After try this solution:- Then extend this class from `Symfony\Bundle\FrameworkBundle\Controller\Controller` not `BaseProductController`. Then blank Single product page appears. Please help me if any one know sonata. First time using symfony and sonata bundles. – Neha Jan 08 '18 at 07:35
  • This problem is solved:- – Neha Jan 09 '18 at 04:36
  • Ans:- No need to change the extend. Here is my Code:- Copy viewAction from vendor/sonata-project/ecommerce/ProductBundle/controller/Basecontroller and place it in src/Application/Sonata/COntroller/ProductController. After copy assign $product = null in the ApplicationSonataProductBundle.. public function viewAction($product = null) { //Add these lines. $slug = $this->getRequest()->get('slug'); $productId = $this->getRequest()->get('productId'); $product = $this->get('sonata.product.set.manager')->findEnabledFromIdAndSlug($productId, $slug); – Neha Jan 09 '18 at 04:47

1 Answers1

0

No need to change the extend. Here is my Code:- Copy viewAction from vendor/sonata-project/ecommerce/ProductBundle/controller/Basecontroller and place it in src/Application/Sonata/Controller/ProductController. After copy assign $product = null in the ApplicationSonataProductBundle.

public function viewAction($product = null) { 
    //Add these lines. 
    $slug = $this->getRequest()->get('slug'); 
    $productId = $this->getRequest()->get('productId'); 
    $product = $this->get('sonata.product.set.manager')->findEnabledFromIdAndSlug($productId, $slug);
....
}
Neha
  • 13
  • 4