sonata-adminsymfony-2.8sonata-user-bundle

Symfony2.8 with sonataEcommerce2.1.1 single Product page "requires that you provide a value for the "$product" argument"


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


Solution

  • 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);
    ....
    }