Prestashop 1.7 : How to get remove from cart URL in accessories

916 Views Asked by At

How can I get properly the remove from cart URL in each $accessories item ? I tried from the template :

{foreach from=$accessories item=accessory}
  {assign var="deleteURL" value=Link::getRemoveFromCartURL($accessory.id_product,$accessory.id_product_attribute,null)}
{/foreach}

But I get an error :

Runtime Notice: Non-static method LinkCore::getRemoveFromCartURL() should not be called statically 

Which controller should I modify to access to remove from cart URL with $accessories ?

1

There are 1 best solutions below

0
On BEST ANSWER

In controllers/front/ProductController.php, edit the function initContent.

$accessories = $this->product->getAccessories($this->context->language->id);
        if (is_array($accessories)) {
            foreach ($accessories as &$accessory) {
                $accessory = $presenter->present(
                    $presentationSettings,
                    Product::getProductProperties($this->context->language->id, $accessory, $this->context),
                    $this->context->language
                );
            }
            unset($accessory);
        }

to

$accessories = $this->product->getAccessories($this->context->language->id);
        if (is_array($accessories)) {
            foreach ($accessories as &$accessory) {
                $accessory = $presenter->present(
                    $presentationSettings,
                    Product::getProductProperties($this->context->language->id, $accessory, $this->context),
                    $this->context->language
                );
                $accessory['remove_from_cart_url'] = $this->context->link->getRemoveFromCartURL($accessory['id'],$accessory['id_product_attribute']);
            }
            unset($accessory);
        }

EDIT : You should not edit the controller directly, but creating an override in override/controllers/front/ProductController.php. If the file is not created yet, do it yourself.