Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How To Use JoinAttribute
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

How to use JoinAttribute in magento.... I wanna get increment_id of invoice and increment_id of shipping from sales_order....

how should I use JoinAttribute to retrieve those value ?

thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

heloo…

 
Magento Community Magento Community
Magento Community
Magento Community
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

how could I set this command into magento command ??

SELECT SO.increment_id "sales_order Id"SOE.increment_idSOEI.attribute_idEA.attribute_codeSOE.entity_type_idEET.entity_type_codeEET.entity_model
FROM sales_order_entity SOE
LEFT JOIN sales_order_entity_int SOEI ON SOE
.entity_id SOEI.entity_id
LEFT JOIN eav_attribute EA ON EA
.attribute_id SOEI.attribute_id
LEFT JOIN sales_order SO ON SO
.entity_id SOEI.value
LEFT JOIN eav_entity_type EET ON EET
.entity_type_id SOE.entity_type_id

WHERE 
(SOE.entity_type_id 16 OR SOE.entity_type_id 19) AND (EA.attribute_id 481 OR EA.attribute_id 438)

thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

anyone has done this yet ??

 
Magento Community Magento Community
Magento Community
Magento Community
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

I need to retrieve more data at sales_order API of invoice attribute at sales_order_invoice,

has anyone done it before ??

public function items($filters null)
    
{
        
//TODO: add full name logic
        
$collection Mage::getResourceModel('sales/order_collection')
            ->
addAttributeToSelect('*')
            ->
joinAttribute('billing_firstname''order_address/firstname''billing_address_id'null'left')
            ->
joinAttribute('billing_lastname''order_address/lastname''billing_address_id'null'left')
            ->
joinAttribute('shipping_firstname''order_address/firstname''shipping_address_id'null'left')
            ->
joinAttribute('shipping_lastname''order_address/lastname''shipping_address_id'null'left')
            ->
addExpressionAttributeToSelect('billing_name',
                
'CONCAT({{billing_firstname}}, " ", {{billing_lastname}})',
                array(
'billing_firstname''billing_lastname'))
            ->
addExpressionAttributeToSelect('shipping_name',
                
'CONCAT({{shipping_firstname}}, " ", {{shipping_lastname}})',
                array(
'shipping_firstname''shipping_lastname'));
            .................. 
            ..................
           
// what should I do ?? if I use JOin Attribute

}

thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brandlive_br
Guru
 
Avatar
Total Posts:  653
Joined:  2008-05-19
Buenos Aires, Argentina
 

The joinAttribute function works (I think) only with the tables that works like entities (catalog_*, product_*, and others).
If you need to make a join between two tables, for example, with tag tables, you need to use join, joinLeft or the others methods.
I’m not pretty sure, but the sales entities can use joinAttrbiute to make that joins.

I don’t see yet soem method that get the last insert id (like the mysql function last_insert_id() does).
Remember that the Magento database abstraction layer use Zend DB. Maybe you can search into Zend for some extra information.

 
Magento Community Magento Community
Magento Community
Magento Community
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

just wondering of joinAttribute function :

->joinAttribute(ALIAS, ENTITY_ATTRIBUTE, BIND, null, ‘left’)
->joinAttribute(’billing_firstname’, ‘order_address/firstname’, ‘billing_address_id’, null, ‘left’)

what is ALIAS, ENTITY_ATTRIBUTE, and BIND ?? where should I find it ?

can I use joinAttribute to join 2 table or more ??

 
Magento Community Magento Community
Magento Community
Magento Community
 
IcebergCommerce
Sr. Member
 
Avatar
Total Posts:  90
Joined:  2008-06-24
 

I had to figure this out as well, this is my explanation on how to use it:

joinAttribute($alias,$attribute,$bind, ...)

$alias is whatever you want the field selected as

$attribute is the joined entity = <entity_type_code>/<attribute_code>
see eav_entity_type table for entity_type_code
attribute code is attribute of the corresponding entity you want to select out

$bind is the attribute code of the main entity to link to the joined entity

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top