sonata-project / ecommerce

[Abandoned] E-Commerce solution provided by Sonata
https://sonata-project.org
MIT License
165 stars 139 forks source link

Exception if free_address_not_required #331

Closed pirasterize closed 4 years ago

pirasterize commented 9 years ago

Hi Im trying to avoid or skip in some way the delivery step on payment process. This because I'll sell in my platform a kind of subscription premium. Then don't need a delivery address/step. By the way if there is a possibility to choose yes/no to show delivery step in the configuration could be nice! ;) Or there is a better solution rather cleaning the delivery traces?

---> Exception issue now I'm tryng as explained in https://sonata-project.org/bundles/ecommerce/develop/doc/reference/bundles/delivery.html

to use "free_address_not_required"

services:
    free_address_not_required:
        name:                 No need delivery
        code:                 free_address_not_required
        priority:             1

But I have en exception : Warning: Invalid argument supplied for foreach() from this file#line : https://github.com/sonata-project/ecommerce/blob/develop/src/BasketBundle/Form/PaymentType.php#L88

should be : $methods = $this->paymentSelector->getAvailableMethods($basket, $basket->getBillingAddress()); in place of $methods = $this->paymentSelector->getAvailableMethods($basket, $basket->getDeliveryAddress()); ?

Because as doing so it works!

thanks for your feedback Andrea

StephanePate commented 9 years ago

I also faced the same issue and my current solution is to overide the basket entity:

public function construct() { parent::construct(); $this->setDeliveryMethodCode('free'); } public function reset($full = true) { parent::reset($full); $this->setDeliveryMethodCode('free'); } public function getDeliveryAddress() { if (!$this->deliveryStep()) { return new Address; //to insure that standard validation of delivery address will pass through } else { parent::getDeliveryAddress(); } }

and overide the routing:

id="sonata_basket_delivery_address" pattern="/shop/basket/step/delivery/address" key="_controller">FrameworkBundle:Redirect:redirect key="route">sonata_basket_payment_address key="permanent">true

It works, but I'd be also interested for a smarter solution !

mathewrapid commented 9 years ago

+1

morettienicolas commented 8 years ago

Hi, can you put here the complete files please. I'm trying to implement this but got this error

Attempted to call method "deliveryStep" on class "AppBundle\Entity\Commerce\Basket".

File:

namespace AppBundle\Entity\Commerce;

use Sonata\BasketBundle\Entity\BaseBasket as BaseBasket; use AppBundle\Entity\Commerce\Address as Address; /**

public function getDeliveryAddress() { if (!$this->deliveryStep()) { return new Address; //to insure that standard validation of delivery address will pass through } else { parent::getDeliveryAddress(); }

}

}// entity

Thanks!!!

StephanePate commented 8 years ago
/**
 * {@inheritdoc}
 */
public function getDeliveryAddress()
{
    if ($this->noDelivery()) {
        return new Address(); //insures that standard validation of delivery address will pass through
    } else {
        parent::getDeliveryAddress();
    }
}

/**
 * noDelivery is true if all BasketElement Products are instances of Whatever (just an example depends on your use case) ...
 *
 * @return bool
 */
public function noDelivery()
{
    return $this->getBasketElements()
                ->forAll(function ($key, $basketElement) {
                    return $basketElement->getProduct() instanceof Whatever;
                });
}
stale[bot] commented 4 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.