Skip to content

Commit

Permalink
[ADD] support for udropship_vendor attribute (custom source_model)
Browse files Browse the repository at this point in the history
  • Loading branch information
mobilizer committed Feb 18, 2016
1 parent 39641dd commit e9a14fa
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions magmi/plugins/inc/magmi_defaultattributehandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ public function handleIntAttribute($pid, &$item, $storeid, $attrcode, $attrdesc,
case "tax/class_source_product":
$ovalue = $this->getTaxClassId($ivalue);
break;
// if udropship_vendor, get vendor id from udropship_vendor table
case "Unirgy_Dropship_Model_Vendor_Source":
$ovalue = $this->getUdropshipVendorId($ivalue);
break;
// otherwise, standard option behavior
// get option id for value, create it if does not already exist
// do not insert if empty
Expand Down Expand Up @@ -399,4 +403,26 @@ public function handleVarcharAttribute($pid, &$item, $storeid, $attrcode, $attrd

return $ovalue;
}

/**
* returns udropship vendor_id for a given vendor_name
*
* @param $ivalue : vendor_name or vendor_id
*
*/
private function getUdropshipVendorId($ivalue)
{
// allow for ids in udropship_vendor column
if (is_numeric($ivalue)) {
$uvendorid = $ivalue;
} else {
$t = $this->tablename('udropship_vendor');
$uvendorid = $this->selectone("SELECT vendor_id FROM $t WHERE vendor_name=?", array($ivalue), "vendor_id");
}
// bugfix for udropship_vendor, if not found set it to empty
if (!isset($uvendorid)) {
$uvendorid = '';
}
return $uvendorid;
}
}

1 comment on commit e9a14fa

@dweeves
Copy link

@dweeves dweeves commented on e9a14fa May 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, very interesting. maybe it would be nicer to have it in a separate attribute handler, one designed for a specific attribute.
It can be done declaring the following method in a Magmi_Item_Processor plugin:

  public function initialize($params)
    {
.... 
 $this->register_attribute_handler($this,'attribute_code:vendor');
....
}

then declare the following method in your processor

public function handleVendorAttribute(e($pid, &$item, $storeid, $attrcode, $attrdesc, $ivalue)
{
// do your vendor attribute specific code here.

}

and it should override the default behaviour for attribute you want.

Please sign in to comment.