getAttributeSetId() always error - magento

I tried to get the attribute_set_id with this code:
$SetId = Mage::getModel('eav/entity_setup')
->getAttributeSetId('catalog_product','Default');
However, I always get this error:
Call to a member function select() on a non-object in
magento\app\code\core\Mage\Core\Model\Resource\Setup.php on line 734
And this is Setup.php line 734:
$select = $adapter->select()
->from($table)
->where($adapter->quoteIdentifier($idField) . '= :id_field');
What I know Mage_Eav_Model_Entity_Setup class already extends Mage_Core_Model_Resource_Setup class. Why does it still say non-object?
Thank you.

The eav/entity_setup model is aimed to process for sql updates, so it may fail outside that context.
Here is correct snippet:
Mage::getSingleton('catalog/config')->getAttributeSetId('catalog_product', 'Default')

You need to pass constructor argument, as based on it connection adapter is beeing intialized:
$SetId = Mage::getModel('eav/entity_setup','core_setup')
->getAttributeSetId('catalog_product','Default');

Related

Laravel: Send slack notification after a scheduled task finished

I need to schedule a few tasks on an application built using Laravel and I would like to send a slack notification after those tasks are finished with the output.
Laravel provides an "after" hook (https://laravel.com/docs/5.8/scheduling#task-hooks) so I can do something like this:
$schedule->command('mycommand')
->daily()
->after(function () {
// How can I access the command's name and output from here?
});
I've tried with $this->output but $this points to App\Console\Kernel and it says Undefined property: App\Console\Kernel::$output. I've also tried to pass a parameter to the closure, but I think I need to specify a type, but I have no idea and the documentation is not very clear.
Anyone has any idea on how to do this?
Thanks in advance!
Assuming you have this in your command
$this->info('hello');
In your kernel, you can send the output to a temporary file and then read the file and send it
/** #var \Illuminate\Console\Scheduling\Event $command */
$command = $schedule->command('mycommand')
->daily()
->sendOutputTo('storage/app/logs.txt');
$command->after(function () use ($command) {
\Log::debug([$command->command, $command->output]);
\Log::debug(file_get_contents($command->output));
});
You will get
[2019-10-11 13:03:38] local.DEBUG: array (
0 => '\'/usr/bin/php7.3\' \'artisan\' command:name',
1 => 'storage/app/logs.txt',
)
[2019-10-11 13:03:38] local.DEBUG: hello
Maybe it would be the time to re-open this proposal https://github.com/laravel/ideas/issues/122#issuecomment-228215251
What kind of output does your command generate? is it command line or is just a variable you're trying to pass to the after()?
Alternativly in your handle() method of the command you can call the desired command after all the code has been excuted, you can even pass a parameter to the command.
You can do that by using Artisan
Artisan::call('*command_name_here*');

Getting Exception for multiple receivers usimg Swiftmailer

follwoing code will send mail to multiple recievers as intended
$SendObject = Yii::$app->mailer->compose()->setFrom($string)
->setTo(array('goetz.bewerber#gmx.net','schulze.bewerber#gmail.com','susanne.bewerber#web.de'))
->setHtmlBody($model->bodytext)
->setSubject($model->betreff)
->setTextBody($model->bodytext);
$SendObject->send();
Unfortunately, I will get Exception if I try like this:
$ZieladresseTest = "'goetz.bewerber#gmx.net','schulze.bewerber#gmail.com','susanne.bewerber#web.de'";
$SendObject = Yii::$app->mailer->compose()->setFrom($string)
->setTo(array($ZieladresseTest))
->setHtmlBody($model->bodytext)
->setSubject($model->betreff)
->setTextBody($model->bodytext);
$SendObject->send();
Exception:
Address in mailbox given ['goetz.bewerber#gmx.net','schulze.bewerber#gmail.com','susanne.bewerber#web.de']
does not comply with RFC 2822, 3.6.2.
Any ideas,
why exception will be thrown out
how to avoid Exception using variables for setTo() ?
Thx in advance. I will give reputation points for every answer solving my problem. Promised!
Edit: Defining variable as an array like this won't fix problem,too:
$ZieladresseTest = array($ZieladresseTest);
Change this
$SendObject = Yii::$app->mailer->compose()->setFrom($string)
->setTo(array('goetz.bewerber#gmx.net','schulze.bewerber#gmail.com','susanne.bewerber#web.de'))
->setHtmlBody($model->bodytext)
->setSubject($model->betreff)
->setTextBody($model->bodytext);
$SendObject->send();
To this
$ZieladresseTest = array('goetz.bewerber#gmx.net','schulze.bewerber#gmail.com','susanne.bewerber#web.de');
$SendObject = Yii::$app->mailer->compose()->setFrom($string)
->setTo($ZieladresseTest)
->setHtmlBody($model->bodytext)
->setSubject($model->betreff)
->setTextBody($model->bodytext);
$SendObject->send();

Magento get invoice number

I'm trying to build a module for Magento that gets the invoice number. The main problem is that I get a Fatal error: Call to a member function getIncrementId() on a non-object...on line 19 ($invoice creation line). My Function is:
$invoice = $observer->getEvent()->getInvoice()->getIncrementId();
$last4 = substr($invoice, -4);
$shipment = $observer->getEvent()->getShipment();
$track = Mage::getModel('sales/order_shipment_track')
->setNumber($last4) //tracking number / awb number
->setCarrierCode('custom') //carrier code
->setTitle('Custom'); //carrier title
$shipment->addTrack($track);
Try replacing the first line of code with this
$invoice = $observer->getEvent()->getOrder()->getIncrementId();
Using the getInvoice() method to get the order may be returning null which will give you the error you have on line 19.

Trouble with getting magento attributes while checkout

Help pls with getting magento attribute while checkbout. I have 'only_registered' attribute. I trying to get attribute via this code:
$cart = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
foreach ($cart as $_item){
$_product = Mage::getModel('catalog/product')->load($_item->getProduct());
$registeredonly = $_product->getRegisteredOnly();
}
but this code generate magento error.
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1";i:1;s:4723:"#0 /work/www/topps.loc/lib/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
I could see the following error in code:
$_product = Mage::getModel('catalog/product')->load($_item->getProduct());
Should be:
$_product = Mage::getModel('catalog/product')->load($_item->getProductId());
And I see you said the variable name to be 'only_registered' so you should access it by:
$registeredonly = $_product->getOnlyRegistered();
And if that doesn't works simply do:
$registeredonly = $_product->getData('only_registered');

PHP parse error in rss parse function

I have a client who needs a website urgently, but I have no access to information such as the control panel.
PHP Version is 4.4 Which is a pain as I'm used to 5.
The first problem is I keep getting:
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')' in D:\hshome\*******\********\includes\functions.php on line 37
This is the function in question:
function read_rss($display=0,$url='') {
$doc = new DOMDocument();
$doc->load($url);
$itemArr = array();
foreach ($doc->getElementsByTagName('item') as $node) {
if ($display == 0) {
break;
}
$itemRSS = array(
'title'=>$node->getElementsByTagName('title')->item(0)->nodeValue,
'description'=>$node->getElementsByTagName('description')->item(0)->nodeValue,
'link'=>$node->getElementsByTagName('link')->item(0)->nodeValue);
array_push($itemArr, $itemRSS);
$display--;
}
return $itemArr;
}
And the line in question:
'title'=>$node->getElementsByTagName('title')->item(0)->nodeValue,
PHP4 does not support object dereferencing. So $obj->something()->something will not work. You need to do $tmp = $obj->something(); $tmp->something...
You can't do that in PHP 4.
Have to do something like
$nodes = $node->getElementsByTagName('title');
$item = $nodes->item(0);
$value = $item->nodeValue,
Try it and it will work.
You can't chain object calls in PHP 4. You're going to have to make each call separately to a variable and store it all.
$titleobj = $node->getElementsByTagName('title');
$itemobj = $titleobj->item(0);
$value = $itemobj->nodeValue;
...
'title'=>$value,
you'll have to do it on all those chained calls
As for .htaccess ... you need to talk to someone who controls the actual server. It sounds like .htaccess isn't allowed to change the setting you're trying to change.
You need to break down that line into individual variables. PHP 4 does not like -> following parentheses. Do this instead:
$title = $node->getElementsByTagName('title');
$title = $title->item(0);
$description = $node->getElementsByTagName('description');
$description = $description->item(0);
$link = $node->getElementsByTagName('link');
$link = $link->item(0);
$itemRSS = array(
'title'=>$title->nodeValue,
'description'=>$description->nodeValue,
'link'=>$link->nodeValue);
The two variable declarations for each may be redundant and condensed, I'm not sure how PHP4 will respond. You can try to condense them if you want.
DOMDocument is php 5 function.You cant use it.
you may need to use DOM XML (PHP 4) Functions

Resources