Magento get invoice number - magento

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.

Related

Oracle Query in Codeigniter giving ORA-01722 and ORA-01756

Im usually use mysql database in my website, but i trying to learn more about the oracle...
My code working 2days ago, but right now its giving an error message such as ORA-number
this is my database fields
KODE_GUDANG CHAR
GUDANG CHAR
LASTUPDATE CHAR
KODE_UNIT CHAR
NOMER_REKJURNAL CHAR
KODE_GUDANG_KREDIT CHAR
this is my models for query
function getDataOneColumn($getCol, $table, $column, $id) {
return $this->db->query("SELECT $getCol as val FROM $table WHERE $column = $id")->row_array();
}
This is for my controller that giving an error : ORA-01722
$this->data['no_rek'] = ($this->data['no_rek'] =='')?$this->m_dao->getDataOneColumn("NOMER_REKJURNAL","TBL_MASTER_GUDANG","KODE_GUDANG",$this->data['kode_gdg'])['VAL']:$this->data['no_rek'];
and after that i reading the docummentation, its means "You executed a SQL statement that tried to convert a string to a number"
i try to change my code to
$this->data['no_rek'] = ($this->data['no_rek'] =='')?$this->m_dao->getDataOneColumn("NOMER_REKJURNAL","TBL_MASTER_GUDANG","KODE_GUDANG",'"'.$this->data['kode_gdg'])['VAL'].'"':"'".$this->data['no_rek']."'";
this one giving an other ORA error,ORA-01756. its means "You tried to execute a statement that contained a string that was not surrounded by two single quotes"
New Error
Error Number: 1722
ORA-01722: invalid number
SELECT NOMER_REKJURNAL as val FROM TBL_MASTER_GUDANG WHERE KODE_GUDANG = 04
Filename: C:/xampp/htdocs/formula/system/database/DB_driver.php
Line Number: 691
Can somebody tell me why my code getting an error after 2days ?
And
How to solve this error?
thank you
After reading lot of post with ORA error, I can solve my problem.
I just need adding " ' ".$val." ' "
$this->data['no_rek'] = ($this->data['no_rek'] =='')?$this->m_dao->getDataOneColumn("NOMER_REKJURNAL","TBL_MASTER_GUDANG","KODE_GUDANG","'".$this->data['kode_gdg']."'")['VAL']:$this->data['no_rek'];

Show validation error for phone number format on website page odoo 12

I'm working on sign up process for the user. Where I taking the phone from the user before sign up. And I want to show the validation when wrong phone number format.
My phone number format code in controller file is below:
def passwordless_signup(self, values, qcontext):
.
.
.
if values['phone']:
phone_fields = self._get_phone_fields_to_validate()
for phone_field in phone_fields:
number = values['phone']
fmt_number = request.env['res.partner'].phone_format(number)
request.params.update({phone_field: number})
.
.
.
return request.render("auth_signup.reset_password", qcontext)
On Ubuntu Terminal, I'm getting below error and I want to show this as validation for user:
File "/opt/odoo12/odoo/addons/phone_validation/tools/phone_validation.py", line 25, in phone_parse
raise UserError(_('Invalid number %s: probably incorrect prefix') % number)
odoo.exceptions.UserError: ('Invalid number 4545545: probably incorrect prefix', '')
Thanks in advance
You have to catch the exception and add as error key with error message as the value in the qcontext dictionary to render that as warning provided to the frontend.
if values['phone']:
phone_fields = self._get_phone_fields_to_validate()
for phone_field in phone_fields:
number = values['phone']
try:
fmt_number = request.env['res.partner'].phone_format(number)
request.params.update({phone_field: number})
except Exception as e:
qcontext['error'] = str(e)
in phone_validation.py add: from odoo import exceptions and in _get_phone_fields_to_validate method add
if not {is_valid_phone}:
raise exceptions.ValidationError('Invalid number %s: probably incorrect prefix' % {your_phone_value})
else:
return {your_phone_value}

What is the meaning of null in Mage log (magento)?

In order to create Magento log, one would write something like
Mage::log('Server Side Validation kicked in for Year for '.$currentYearType);
But if I were to add the log in a sepearate file , do I
Mage::log('Server Side Validation kicked in for Year for ' ,null,'serversidevalidation.log');
Please correct me if I am wrong.
If so, what is the use of null in the middle?
Also, does the file need to exist before hand or I think it is created by system when needed. Am I right? Also, will it include timestamp?
Go to to app/Mage.php
line 785
public static function log($message, $level = null, $file = '', $forceLog = false)
you can see the second paramete is level
$level = is_null($level) ? Zend_Log::DEBUG : $level;
lib\Zend\log.php
const EMERG = 0; // Emergency: system is unusable
const ALERT = 1; // Alert: action must be taken immediately
const CRIT = 2; // Critical: critical conditions
const ERR = 3; // Error: error conditions
const WARN = 4; // Warning: warning conditions
const NOTICE = 5; // Notice: normal but significant condition
const INFO = 6; // Informational: informational messages
const DEBUG = 7; // Debug: debug messages
if you this code Mage::log('test', 1);
then you get a output in log file like this
2014-05-17T12:21:51+00:00 ALERT (1): test
Yes, the file is automatically created by system when its call
system include the timestamp when it call
refer this code in app/Mage.php in line 825
$format = '%timestamp% %priorityName% (%priority%): %message%' . PHP_EOL;
$formatter = new Zend_Log_Formatter_Simple($format);
Cheers

getAttributeSetId() always error

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');

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