Jump to content

Prestashop 1.5 validateOrder and Error "Can't Save Error"


mirkos90

Recommended Posts

Hi guys,
as usual i'm here for ask for some support :)

I expose my problem quickly:

I'm creating an module for make an order by putting an barcode (ean13) in a input, but i've an problem in the order validation function, here is my snippet of code

$ean = Tools::getValue('barcode');
$id_product = $this->getProductByEAN($ean);
if($id_product){
	$context = Context::getContext();
	$id_cart = $context->cookie->__get('id_cart');
	$cart = new Cart($id_cart);
	$cart->id_currency = $context->cookie->id_currency;
	$cart->id_carrier = 1;
	$cart->recyclable = 0;
	$cart->gift = 0;
	$cart->id_customer = 1;
	$cart->id_lang = $context->cookie->id_lang;
	$cart->add();
	$cart->updateQty(1,$id_product);
	$total = (float)($cart->getOrderTotal(true, Cart::BOTH));
	$currency = $this->context->currency;
	$customer = new Customer($cart->id_customer);

	var_dump(PaymentModule::validateOrder($cart->id,'2',$total));
	
}

Here is my print_r() of my Cart Object:

Cart Object
(
    [id] => 293
    [id_shop_group] => 
    [id_shop] => 1
    [id_address_delivery] => 
    [id_address_invoice] => 
    [id_currency] => 1
    [id_customer] => 1
    [id_guest] => 
    [id_lang] => 1
    [recyclable] => 0
    [gift] => 0
    [gift_message] => 
    [mobile_theme] => 
    [date_add] => 2014-07-03 17:22:58
    [secure_key] => 
    [id_carrier] => 1
    [date_upd] => 2014-07-03 17:22:58
    [checkedTos] => 
    [pictures] => 
    [textFields] => 
    [delivery_option] => 
    [allow_seperated_package] => 
    [_products:protected] => Array
        (
            [0] => Array
                (
                    [id_product_attribute] => 0
                    [id_product] => 132
                    [cart_quantity] => 1
                    [id_shop] => 1
                    [name] => Noch - NH07088 - Field grass, golden-yellow (5mm - 30gr.)
                    [is_virtual] => 0
                    [description_short] => 

- NOME DEL PRODOTTO: Erba di campo alta, giallo oro (5mm)

- AZIENDA: Noch

- MISURE ALTEZZA: 5 mm

- DESCRIZIONE: 30gr 

- CODICE: NH07088 



                    [available_now] => 
                    [available_later] => 
                    [id_category_default] => 199
                    [id_supplier] => 0
                    [id_manufacturer] => 4
                    [on_sale] => 0
                    [ecotax] => 0.000000
                    [additional_shipping_cost] => 0.00
                    [available_for_order] => 1
                    [price] => 6.56
                    [active] => 1
                    [unity] => 
                    [unit_price_ratio] => 0.000000
                    [quantity_available] => 2
                    [width] => 0.000000
                    [height] => 0.000000
                    [depth] => 0.000000
                    [out_of_stock] => 2
                    [weight] => 0.000000
                    [date_add] => 2013-08-05 18:50:48
                    [date_upd] => 2014-06-09 17:36:42
                    [quantity] => 1
                    [link_rewrite] => erba-di-campo-alta-giallo-oro
                    [category] => vegetazione
                    [unique_id] => 13200
                    [id_address_delivery] => 0
                    [wholesale_price] => 0.000000
                    [advanced_stock_management] => 0
                    [supplier_reference] => 
                    [customization_quantity] => 
                    [id_customization] => 
                    [price_attribute] => 
                    [ecotax_attr] => 
                    [reference] => NH07088
                    [weight_attribute] => 
                    [ean13] => 4007246070886
                    [upc] => 
                    [pai_id_image] => 
                    [pai_legend] => 
                    [minimal_quantity] => 1
                    [stock_quantity] => 2
                    [price_wt] => 8
                    [total_wt] => 8
                    [total] => 6.56
                    [id_image] => 132-142
                    [legend] => 
                    [reduction_applies] => 
                    [quantity_discount_applies] => 
                    [allow_oosp] => 0
                    [features] => Array
                        (
                        )

                    [rate] => 22
                    [tax_name] => IVA IT 22%
                )

        )

    [_taxCalculationMethod:protected] => 0
    [webserviceParameters:protected] => Array
        (
            [fields] => Array
                (
                    [id_address_delivery] => Array
                        (
                            [xlink_resource] => addresses
                        )

                    [id_address_invoice] => Array
                        (
                            [xlink_resource] => addresses
                        )

                    [id_currency] => Array
                        (
                            [xlink_resource] => currencies
                        )

                    [id_customer] => Array
                        (
                            [xlink_resource] => customers
                        )

                    [id_guest] => Array
                        (
                            [xlink_resource] => guests
                        )

                    [id_lang] => Array
                        (
                            [xlink_resource] => languages
                        )

                )

            [associations] => Array
                (
                    [cart_rows] => Array
                        (
                            [resource] => cart_row
                            [virtual_entity] => 1
                            [fields] => Array
                                (
                                    [id_product] => Array
                                        (
                                            [required] => 1
                                            [xlink_resource] => products
                                        )

                                    [id_product_attribute] => Array
                                        (
                                            [required] => 1
                                            [xlink_resource] => combinations
                                        )

                                    [id_address_delivery] => Array
                                        (
                                            [required] => 1
                                            [xlink_resource] => addresses
                                        )

                                    [quantity] => Array
                                        (
                                            [required] => 1
                                        )

                                )

                        )

                )

        )

    [id_shop_list] => 
    [get_shop_from_context:protected] => 1
    [table:protected] => cart
    [identifier:protected] => id_cart
    [fieldsRequired:protected] => Array
        (
            [0] => id_currency
            [1] => id_lang
        )

    [fieldsSize:protected] => Array
        (
            [secure_key] => 32
        )

    [fieldsValidate:protected] => Array
        (
            [id_shop_group] => isUnsignedId
            [id_shop] => isUnsignedId
            [id_address_delivery] => isUnsignedId
            [id_address_invoice] => isUnsignedId
            [id_carrier] => isUnsignedId
            [id_currency] => isUnsignedId
            [id_customer] => isUnsignedId
            [id_guest] => isUnsignedId
            [id_lang] => isUnsignedId
            [recyclable] => isBool
            [gift] => isBool
            [gift_message] => isMessage
            [mobile_theme] => isBool
            [allow_seperated_package] => isBool
            [date_add] => isDateFormat
            [date_upd] => isDateFormat
        )

    [fieldsRequiredLang:protected] => Array
        (
        )

    [fieldsSizeLang:protected] => Array
        (
        )

    [fieldsValidateLang:protected] => Array
        (
        )

    [tables:protected] => Array
        (
        )

    [image_dir:protected] => 
    [image_format:protected] => jpg
    [def:protected] => Array
        (
            [table] => cart
            [primary] => id_cart
            [fields] => Array
                (
                    [id_shop_group] => Array
                        (
                            [type] => 1
                            [validate] => isUnsignedId
                        )

                    [id_shop] => Array
                        (
                            [type] => 1
                            [validate] => isUnsignedId
                        )

                    [id_address_delivery] => Array
                        (
                            [type] => 1
                            [validate] => isUnsignedId
                        )

                    [id_address_invoice] => Array
                        (
                            [type] => 1
                            [validate] => isUnsignedId
                        )

                    [id_carrier] => Array
                        (
                            [type] => 1
                            [validate] => isUnsignedId
                        )

                    [id_currency] => Array
                        (
                            [type] => 1
                            [validate] => isUnsignedId
                            [required] => 1
                        )

                    [id_customer] => Array
                        (
                            [type] => 1
                            [validate] => isUnsignedId
                        )

                    [id_guest] => Array
                        (
                            [type] => 1
                            [validate] => isUnsignedId
                        )

                    [id_lang] => Array
                        (
                            [type] => 1
                            [validate] => isUnsignedId
                            [required] => 1
                        )

                    [recyclable] => Array
                        (
                            [type] => 2
                            [validate] => isBool
                        )

                    [gift] => Array
                        (
                            [type] => 2
                            [validate] => isBool
                        )

                    [gift_message] => Array
                        (
                            [type] => 3
                            [validate] => isMessage
                        )

                    [mobile_theme] => Array
                        (
                            [type] => 2
                            [validate] => isBool
                        )

                    [delivery_option] => Array
                        (
                            [type] => 3
                        )

                    [secure_key] => Array
                        (
                            [type] => 3
                            [size] => 32
                        )

                    [allow_seperated_package] => Array
                        (
                            [type] => 2
                            [validate] => isBool
                        )

                    [date_add] => Array
                        (
                            [type] => 5
                            [validate] => isDateFormat
                        )

                    [date_upd] => Array
                        (
                            [type] => 5
                            [validate] => isDateFormat
                        )

                )

            [classname] => Cart
        )

    [update_fields:protected] => 
)

The error that i have, is this:

[PrestaShopException]

Can't save Order
at line 266 in file classes/PaymentModule.php

Why i've this error? i've followed the structure of the module Bankwire for make this.

Thank you!

 

Link to comment
Share on other sites

perhaps its related to empty:

 

variables

 

your customer probably hasn't got any address

 

Thanks Vekia! That's worked, but now i've another problem, my module class extends PaymentModule class, like an normal payment module like the bankwire module, but when I go to make an order, I've an error:

[PrestaShop] Fatal error in module PaymentModule:
Call to a member function addOrderPayment() on a non-object

If I'm not too disturbing: could you help me? :(

Thank you again!

Link to comment
Share on other sites

The PaymentModule class is trying to invoke the "addOrderPayment" function, which exists in the Order class.

 

This happens in the validateOrder function of PaymentModule (code from PS v1.5.6.2, you don't say what version you are using...)

if (!$order->addOrderPayment($amount_paid, null, $transaction_id))

For some reason the PaymentModule does not think the $order variable is a valid object (it says non-object).  So you will need to confirm why that is by further debugging

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...