php - OrderState creation and deletion

198

I'm developing a payment module for Prestashop 1.5. As there is no order state related to the payment, I decided to create one during the install process.

I used this topic from the official forum, which suggests to use this

$OrderState = new OrderState();
            $OrderState->name = array_fill(0,10,"Saman Bank Payment accepted");
            $OrderState->template = array_fill(0,10,"SB24");
            $OrderState->send_email = 1;
            $OrderState->invoice = 1;
            $OrderState->color = "#f8dbec";
            $OrderState->unremovable = false;
            $OrderState->logable = 0;
            $OrderState->add();

So now the createOrderState looks like this

private function createOrderState($db_name, $name)
{
    if (!Configuration::get($db_name))//if status does not exist
    {
        $orderState = new OrderState();
        $orderState->name =  array_fill(0,10,$name);
        $orderState->send_email = false;
        $orderState->color = 'royalblue';
        $orderState->hidden = false;
        $orderState->delivery = false;
        $orderState->logable = false;
        $orderState->invoice = false;
        if ($orderState->add())//save new order status
        {
            Configuration::updateValue($db_name, (int)$orderState->id);
        }
    }
}

However, when I install the module and go to check in the Order States list I find inserted four empty statuses (ids 14,15,16 and 17) and the one I intended to create (id 18).

On the other hand, the uninstall function contains the deleteOrderState function, which is like this

public function deleteOrderState($db_name, $name)
{
    $orderState = new OrderState();
        $orderState->name =  array_fill(0,10,$name);
        $orderState->send_email = false;
        $orderState->color = 'royalblue';
        $orderState->hidden = false;
        $orderState->delivery = false;
        $orderState->logable = false;
        $orderState->invoice = false;

    $order_state.delete();
}

However, when I try to uninstall the module I get the following error message

Fatal error: Call to undefined function delete() in D:\xampp\htdocs\prestashop\modules\example\example.php on line 114
[PrestaShop] Fatal error in module example:
Call to undefined function delete()

TL,DR; I want to know

  • What does the 10 in the array_fill stands for? My best guess is that it is related to the number of installed languages, but couldn't confirm it.
  • Is there any way to retrieve the orderState without querying explicitly the database, such as a getOrderState function?

Thanks in advanced.

832

Answer

Solution:

1º - You have to pass by parameter theorder_state_id.

2º - To access a method, you have to use like this:

$obj->method

instead of

$obj.method

Follow my example:

public function deleteOrderState($id_order_state) {

    $orderState = new OrderState($id_order_state);        
    $orderState->delete();

}

Then, to delete anOrderState, first you need to know its ID.

Later, just do this:

$yourObj->deleteOrderState(59);

People are also looking for solutions to the problem: javascript - Lacking concept on editable html email

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.