Automated order invoicing in Magento

Some simple functionality for invoicing an order was just released in Magium. Invoicing an order can be accomplished with the following code.

<?php

use Magium\Magento\AbstractMagentoTestCase;
use Magium\Magento\Actions\Admin\Login\Login;
use Magium\Magento\Actions\Admin\Orders\Invoice;
use Magium\Magento\Navigators\Admin\Order;

class InvoiceTest extends AbstractMagentoTestCase
{


    public function testOrderExtraction()
    {

        $this->getAction(Login::ACTION)->login();
        $this->getNavigator(Order::NAVIGATOR)->navigateTo(<provide the order ID>);
        $this->getAction(Invoice::ACTION)->execute();
    }

}

All this functionality does is invoice an order with all of the defaults. If you want to customize some of the settings on the page you can create a separate class that can then be injected into the action prior to execution. This is part of some new functionality I will be added to various actions as time goes on. These are called sub-actions. They are executed prior to an “action button” being clicked.

Consider a case where you want to change the quantity you invoice. You would create a new class to set the quanity.



use Magium\WebDriver\WebDriver; class SetQtyToTwo implements Magium\Actions\SubAction\SubActionInterface { protected $webDriver; public function __construct( WebDriver $webDriver ) { $this->webDriver = $webDriver; } public function execute() { $this->webDriver->byCssSelector('input.qty-input')->setAttribute(2); } }

Then you would rewrite the previous test as such:

<?php

use Magium\Magento\AbstractMagentoTestCase;
use Magium\Magento\Actions\Admin\Login\Login;
use Magium\Magento\Actions\Admin\Orders\Invoice;
use Magium\Magento\Navigators\Admin\Order;

class InvoiceTest extends AbstractMagentoTestCase
{


    public function testOrderExtraction()
    {

        $this->getAction(Login::ACTION)->login();
        $this->getNavigator(Order::NAVIGATOR)->navigateTo(<provide the order ID>);
        $action = $this->getAction(Invoice::ACTION)

                $action->addSubAction($this-get('SetQtyToTwo'));

                $action->execute();
    }

}