0

I'll spare everyone the drudgery of why, but I have a script here that should create an invoice for an order and send that invoice email. It works fine, except the email isn't going out.

I've dug into it a while and it seems it's a problem with finding the config value for sales_email/invoice/enabled. I wrote a script to just get the information for that path for a given store, and it seems to be always return true, even when I've disabled it. Some stores appear to be the opposite.

Enough talk, here's the code:

magetestconfig.php

<?php

require_once '/var/www/html/magento/app/Mage.php';
Mage::app();

$path = $argv[1];
$store = $argv[2];

$result = Mage::getStoreConfigFlag($path, $store);
$resultFlag = Mage::getStoreConfigFlag($path, $store);
echo "The path is $path, store is $store, results are ($result,$resultFlag)".PHP_EOL;

Running that gives me:

The path is sales_email/invoice/enabled, store is 2, results are (1,1)

Yet, in admin it's disabled for that store, and this seems to be accurately reflected in the database:

mysql> select scope,scope_id,path,value from core_config_data where path like '%invoice/enabled%' and scope_id = 2;
+----------+----------+-----------------------------+-------+
| scope    | scope_id | path                        | value |
+----------+----------+-----------------------------+-------+
| websites |        2 | sales_email/invoice/enabled | 0     |
+----------+----------+-----------------------------+-------+
1 row in set (0.00 sec)

The only time I've noticed this problem is in this script, run in a terminal, but I don't see how that would matter, but I haven't had to do this particular thing before, so it's entirely possible I just missed something.

As a bit of a disclaimer, I am overwriting some classes for what I'm working on, but nothing that I can imagine affecting this, but if no one has ideas with this, it could just be that I'm wrong on that assumption. I am not overwriting anything related to the site config, though, only a few things with with store emails, which is (other than this) working correctly.

Edit: Here's another example.

<?php

require_once '/var/www/html/magento/shell/abstract.php';

class Mage_Shell_Configtest extends Mage_Shell_Abstract {
    public function run() {  
        $path = "sales_email/invoice/template";
        $template = Mage::getStoreConfig($path, 2);
        echo "Template: $template".PHP_EOL;

        echo "The path is '$path'".PHP_EOL;
        echo "--------------------------------------------------------------------------".PHP_EOL;
        echo "Store | getStoreConfig()                            | getStoreConfigFlag()".PHP_EOL;
        echo "--------------------------------------------------------------------------".PHP_EOL;
        foreach (range(1,13) as $store) {
            $result = Mage::getStoreConfig($path, $store);
            $resultFlag = Mage::getStoreConfigFlag($path, $store);
            printf(" %4s | %-43s | %s \n",$store,$result,$resultFlag);
        }
    }

    public function usageHelp() {
        return "Run it.";
    }
}

$shell = new Mage_Shell_Configtest();
$shell->run();

This gives:

Template: sales_email_invoice_template
The path is 'sales_email/invoice/template'
--------------------------------------------------------------------------
Store | getStoreConfig()                            | getStoreConfigFlag()
--------------------------------------------------------------------------
    1 | sales_email_invoice_template                | 1
    2 | sales_email_invoice_template                | 1
    3 | sales_email_invoice_template                | 1
    4 | sales_email_invoice_template                | 1
    5 | sales_email_invoice_template                | 1
    6 | sales_email_invoice_template                | 1
    7 | sales_email_invoice_template                | 1
    8 | sales_email_invoice_template                | 1
    9 | sales_email_invoice_template                | 1
   10 | sales_email_invoice_template                | 1
   11 | sales_email_invoice_template                | 1
   12 | sales_email_invoice_template                | 1
   13 | sales_email_invoice_template                | 1

But checking the database shows:

mysql> select scope,scope_id,path,value from core_config_data where path like '%invoice/template%';
+----------+----------+------------------------------+------------------------------+
| scope    | scope_id | path                         | value                        |
+----------+----------+------------------------------+------------------------------+
| default  |        0 | sales_email/invoice/template | sales_email_invoice_template |
| websites |        2 | sales_email/invoice/template | 10                           |
+----------+----------+------------------------------+------------------------------+
2 rows in set (0.01 sec)
0

I was barking up the wrong tree entirely. The problem had nothing to do with code, it was that I was running these scripts as my own user, rather than as something like 'apache' - I'm guessing it was an issue with file permissions and the cache. As soon as I just tried running it with sudo, everything worked properly.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.