Extending the connector
General considerations
It is not recommended to change the connector code directly. If you need to change it, the best approach is to create a module in app/code/local, then either hook into one of the below events or use class rewrites.
Events list
netsuite_stock_item_save_before
Description: grants a chance to execute custom code right before the stock for an item is saved
Parameters:
- stock_item type cataloginventory/stock_item, the Magento stock item that is to be saved
- item_search_row, type ItemSearchRowBasic, the stock information from Netsuite
//only add 60% of the Netsuite stock in Magento. $stockItem = $observer->getEvent()->getStockItem(); /* @var ItemSearchRowBasic $itemSearchRow */ $itemSearchRow = $observer->getEvent()->getItemSearchRow(); $qty = $itemSearchRow->locationQuantityAvailable[0]->searchValue; $qty = round($qty*0.6); $stockItem->setQty($qty); if($qty>0) $stockItem->setIsInStock(1); else $stockItem->setIsInStock(0);
netsuite_bill_address_create_before
Description: occurs just before a billing address is sent to Netsuite
Parameters:
- netsuite_address, type BillAddress
//pad phone numbers to be at least 10 chars.
$netsuiteAddess = $observer->getEvent()->getNetsuiteAddress();
if($this->phoneIsInvalid($netsuiteAddess->billPhone)) {
$netsuiteAddess->billPhone = $this->getPaddedPhone($netsuiteAddess->billPhone);
}
netsuite_ship_address_create_before
Description: occurs just before a shipping address is sent to Netsuite
Parameters:
- netsuite_address, type ShipAddress
//pad phone numbers to be at least 10 chars.
$netsuiteAddess = $observer->getEvent()->getNetsuiteAddress();
if($this->phoneIsInvalid($netsuiteAddess->shipPhone)) {
$netsuiteAddess->shipPhone = $this->getPaddedPhone($netsuiteAddess->shipPhone);
}
netsuite_address_create_before
Description: occurs just before a customer (address book) address is sent to Netsuite
Parameters:
- netsuite_address, type CustomerAddressbook
//pad phone numbers to be at least 10 chars.
$netsuiteAddess = $observer->getEvent()->getNetsuiteAddress();
if($this->phoneIsInvalid($netsuiteAddess->phone)) {
$netsuiteAddess->phone = $this->getPaddedPhone($netsuiteAddess->phone);
}
netsuite_customer_send_before
Description: occurs just before sending a customer to Netsuite
Parameters:
- netsuite_customer, type Customer
//phone number must be at least 7 chars long if not empty $netsuiteCustomer = $observer->getEvent()->getNetsuiteCustomer(); if($this->phoneIsInvalid($netsuiteCustomer->phone)) $netsuiteCustomer->phone = $this->getPaddedPhone($netsuiteCustomer->phone); return $this;
netsuite_new_order_send_before
Description: occurs just before sending an order to Netsuite
Parameters:
- magento_order type sales/order, the Magento order object
- netsuite_order type SalesOrder, the Netsuite order
//set all Netsuite orders to be printed $netsuiteOrder = $observer->getEvent()->getNetsuiteOrder(); $netsuiteOrder->toBePrinted = true; return $this;
netsuite_import_request_before
Description: occurs before an import operation starts
Parameters:
- record_type the type of the record to be imported
- search_object the search request that will grab the to-be-imported requests, type TransactionSearchBasic
netsuite_import_product_created_after
Description: Occurs when a product is imported
Parameters:
- magento_product, type catalog/product, the Magento product object
- netsuite_product, type InventoryItem, the Netsuite product object
- product_is_new, type bool, whether the product previously existed in the db or not
//set product categories
$magentoProduct = $observer->getEvent()->getMagentoProduct();
/** @var InventoryItem $inventoryItem */
$inventoryItem = $observer->getEvent()->getNetsuiteProduct();
foreach($inventoryItem->customFieldList->customField as $customField) {
if($customField->internalId == 'custitem_magento_category_ids') {
$categoryIds = explode(',',trim($customField->value));
if(count($categoryIds)) {
$magentoProduct->setCategoryIds($categoryIds);
}
}
}
netsuite_inventory_item_is_importable
Description: gives a chance to write custom code in deciding whether a inventory item is importable or not
Parameters:
- inventory_item, type InventoryItem, the Netsuite product
- is_importablebool, whether the product is importable
//items that do not have the custitem_sendtomagento flag set are not to be imported
$inventoryItem = $observer->getEvent()->getInventoryItem();
$isImportable = $observer->getEvent()->getIsImportable();
foreach($inventoryItem->customFieldList->customField as $customField) {
/* @var CustomFieldRef $customField */
if($customField->internalId == 'custitem_sendtomagento') {
if($customField->value == false) {
$excludeFromImport = true;
}
}
}
$isImportable->setFlag(!$excludeFromImport);
netsuite_item_fulfillment_import_save_before
Description: occurs just before a Netsuite fulfillment gets imported as a Magento shipping
Parameters:
- netsuite_shipping, type ItemFulfillment, the Nesuite shipment
- magento_shipping the Magento shipment, not yet saved
//import custom tracking info
/* @var Mage_Sales_Model_Order_Shipment $magentoShipment*/
$magentoShipment = $observer->getEvent()->getMagentoShipping();
/* @var ItemFulfillment $netsuiteShipment */
$netsuiteShipment = $observer->getEvent()->getNetsuiteShipping();
foreach($netsuiteShipment->customFieldList->customField as $customField) {
if($customField->internalId == 'custbody_shipping_carrier') {
$carrier = strtolower(trim($customField->value));
$carrierCode = 'custom';
if($carrier == 'ups') {
$carrierCode = 'ups';
}
if($carrier == 'usps') {
$carrierCode = 'usps';
}
$tracks = $magentoShipment->getTracksCollection();
foreach($tracks as $track) {
$track->setCarrierCode($carrierCode);
}
}
}
product_map_value_extracted
Description: allows writing custom code when field mapping in product import occurs
Parameters:
- product_map_value, type RocketWeb_Netsuite_Model_Product_Map_Value, the mapping
$productMapValue = $observer->getEvent()->getProductMapValue();
if($productMapValue->getMagentoFieldId() == 'batteries_included') {
$this->prepareBatteriesIncludedField($productMapValue);
}
return $this;
No comments to display
No comments to display