Trouble with getting magento attributes while checkout - magento

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

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

Replace character in pig

My data is in the following format..
{"Foo":"ABC","Bar":"20090101100000","Quux":"{\"QuuxId\":1234,\"QuuxName\":\"Sam\"}"}
I need it to be in this format:
{"Foo":"ABC","Bar":"20090101100000","Quux":{"QuuxId":1234,"QuuxName":"Sam"}}
I'm trying to using Pig's replace function to get it in the format I need..
So, I tried ..
"LOGS = LOAD 'inputloc' USING TextStorage() as unparsedString:chararray;;" +
"REPL1 = foreach LOGS REPLACE($0, '"{', '{');" +
"REPL2 = foreach REPL1 REPLACE($0, '}"', '}');"
"STORE REPL2 INTO 'outputlocation';"
It throws an error.. Unexpected token '{' in expression or statement.
So based on an answer here, I tried:
"REPL1 = foreach LOGS REPLACE($0, '"\\{', '\\{');"
Now, it gives an error.. Unexpected token '\\' in expression or statement.
Any help is sincerely appreciated..
Thanks
Works for me:
REPL1 = FOREACH LOGS GENERATE REPLACE($0, '"\\{', '\\{');
In your code you are missing the GENERATE and the double quotes at the beginning and end are wrong.
Please check the below code.
LOGS = load 'inputlocation' as unparsedString:chararray;
REPL1 = foreach LOGS generate REPLACE($0, '"\\{', '\\{');
REPL2 = foreach REPL1 generate REPLACE($0, '}"', '}');
STORE REPL2 INTO 'outputlocation';
Hope it will work.
Load the data using the delimiter as shown below:
sam = load 'sampledata' using PigStorage(',');
sam1 = foreach sam generate $0,$1,CONCAT(REPLACE($2,'([^A-Za-z0-9:"{]+)',''),REPLACE($3,'([^A-Za-z0-9:"}]+)',''));
This will give you the desired output.
({"Foo":"ABC","Bar":"20090101100000","Quux":"{"QuuxId":1234"QuuxName":"Sam"}"})

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.

Codeigniter concat_ws not working

Getting error when I tried like this:
$ci =& get_instance();
$ci->db->select("CONCAT_WS(' ',users.name_first,users.name_last) AS user_name,CONCAT_WS(' ',advertisers.name_first,advertisers.name_last) AS advertiser_name,image,advertiser_reviews.last_updated");
$ci->db->join('users', 'users.id = advertiser_reviews.user_id');
$ci->db->join('advertisers', 'advertisers.id = advertiser_reviews.advertiser_id');
$ci->db->order_by('advertiser_reviews.id','desc');
$ci->db->limit(1);
$query = $ci->db->get('advertiser_reviews');
Error as follows:
Error Number: 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 'FROM (`hc_advertiser_reviews`) JOIN `hc_users` ON `hc_users`.`id` = `hc_advertis' at line 2
SELECT CONCAT_WS(' ', `hc_users`.`name_first`, `hc_users`.`name_last)` AS user_name,
CONCAT_WS(' ', `hc_advertisers`.`name_first`, `hc_advertisers`.`name_last)` AS advertiser_name,
`image`,
`hc_advertiser_reviews`.`last_updated`
FROM (`hc_advertiser_reviews`)
JOIN `hc_users` ON `hc_users`.`id` = `hc_advertiser_reviews`.`user_id`
JOIN `hc_advertisers` ON `hc_advertisers`.`id` = `hc_advertiser_reviews`.`advertiser_id`
ORDER BY `hc_advertiser_reviews`.`id` desc LIMIT 1
try to use $this->db->query("your sql query")
EDIT:
try to avoid the auto-quoting feature of the CodeIgniter DB class with
$this->db->select("your-query",FALSE)
There is sign ` at the Codeigniter generated code at the end
SELECT CONCAT_WS(' ', `hc_users`.`name_first`, `hc_users`.`name_last)`
$this->db->select('what of sql uncion' ,false);
the false tell ci to ignor escaping with `
Just came across this post where I had the same issue and you can get around the issue by a clever use of spaces.
$ci->db->select("CONCAT_WS(' ',users.name_first,users.name_last ) AS user_name )
As opposed to
$ci->db->select("CONCAT_WS(' ',users.name_first,users.name_last) AS user_name )
If you insert a space before the last closing bracket of the CONCAT_WS function then the CodeIgniter auto-quoting feature won't get confused about where the `s need to go. It also means you dont have to use the db->query() function.

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