aimeos / ai-admin-jqadm

Aimeos e-commerce Vue.js+Bootstrap based admin interface
https://aimeos.org
GNU Lesser General Public License v3.0
177 stars 43 forks source link

Voucher Decorator for Supplier #170

Closed exemplari closed 3 years ago

exemplari commented 3 years ago

Environment "aimeos/aimeos-laravel": "~2020.10" linux

Describe the bug namespace Aimeos\MShop\Coupon\Provider\Decorator; does not work

To Reproduce Steps to reproduce the behavior:

  1. Create a supplier code
  2. Attache supplier code to product
  3. Create a voucher with a supplier decorator
  4. Add products with the supllier code to the basket
  5. Add the coupon code to the basket
  6. the coupon code is in the basket but does not apply

Expected behavior Basket coupon applies to products with the supplier code

Screenshots If applicable, add screenshots to help explain your problem.

Additional context

It was checking the baseOrder->services instead of the baseOrder->products

namespace Aimeos\MShop\Coupon\Provider\Decorator;

/**
 * Checks for requirements.
 *
 * @param \Aimeos\MShop\Order\Item\Base\Iface $base Basic order of the customer
 * @return bool True if the requirements are met, false if not
 */
public function isAvailable( \Aimeos\MShop\Order\Item\Base\Iface $base ) : bool
{
    if( $supplier = $this->getConfigValue( 'supplier.code' ) )
    {
        foreach( $base->getProducts() as $product )
        {
            if( $product->getAttribute( 'supplier.code', 'delivery' ) === $supplier ) {
                return parent::isAvailable( $base );
            }
        }
    }

    return false;
}
exemplari commented 3 years ago

So i ended up with the final if attribute to try and find the product supplier code. $product->getSupplierCode() but that value is empty i double checked that the product does have a supplier code assigned Some issue with the manager / item ?

exemplari commented 3 years ago

even when i complete an order the mshop_order_base_product does not have the appropriate suppliercode in mshop_order_base_product

exemplari commented 3 years ago

not sure if the supplier code issues isnt better solved in the item, manager. This seems to get by for the meantime.


         /**
     * Checks for requirements.
     *
     * @param \Aimeos\MShop\Order\Item\Base\Iface $base Basic order of the customer
     * @return bool True if the requirements are met, false if not
     */
    public function isAvailable( \Aimeos\MShop\Order\Item\Base\Iface $base ) : bool
    {
        $supplier = $this->getConfigValue( 'supplier.code' );
        $context = $this->getContext();
        $manager = \Aimeos\MShop::create($context, 'supplier');

        if( $supplier )
        {
            foreach( $base->getProducts() as $product )
            {
                $filter = $manager->filter( true );
                $filter->add($filter->make('supplier:has', ['product', 'default', $product->getProductId()] ), '!=', null );

                $suppliers = $manager->search( $filter );

                foreach( $suppliers as $sply) {
                    if( $sply->getCode() === $supplier ) {
                        return parent::isAvailable( $base );
                    }
                }
            }   
        }
        return false;
    }
aimeos commented 3 years ago

The coupon supplier decorator limits coupons according to the supplier chosen for Click&Collect delivery option. You want to limit the coupon to the products from one supplier which is a different thing and for that, you have to create you own coupon decorator.

exemplari commented 3 years ago

I should have read that better. Thanks