On this page
- Overview
- Function overview
- magento_products_settings()
- magento_products_cache_time_validate()
- magento_products_test()
- magento_product_synchronize($product)
- magento_products_get_nid($product_id)
- magento_products_get_product()
- magento_products_copy_image($url,$new_url,$nid = NULL)
- getSizeFile($url)
- magento_products_nodeapi()
- magento_products_get_actual_price($node, $user)
- magento_products_get_tier_price($node, $price)
- magento_products_form_alter()
magento_products
Overview
Module synchronizes Magento products catalogue to Drupal content.
During installation of module, new content type product is created, which is being used for storing information of product. Necessary fields are created for that content type:
Product ID - the ID of product
Description - description of product
Short Description - short description of product
SKU - the SKU of product
Weight - weight of product
Price - price of product
Special Price - special price of product
Special Price from date - start date of product special price
Special Price to date - end date of product special price
New from date - start date of marking product as New
New to date - end date of marking product as New
Status - status of product
Visibility - visibility of product
Stock Availability - availability of product in stock
Rule ID - the ID of applied rule
Discount price - information of product price considering applied rules
Tier price - information of Tier Price
Image - image of product
Function overview
magento_products_settings()
Description: Function outputs the form of product synchronization settings.
It allows to specify the time of keeping data in cache: Always, Temporarily or Specify time in hours.
magento_products_cache_time_validate()
Description: Function validates entered to magento_products_settings form time.
An error occurs if enter negative number or non-digit.
magento_products_test()
Description: Function retrieves all the products array from Magento. Function magento_product_synchronize($product) is called to create corresponded node at Drupal for each product.
Also this function defines the list of products from Magento. Comparing newly retrieved list of products with already synchronized to Drupal list of products (retrieved via magento_products_get_product function), function figures outdated products and removes them from Drupal.
magento_product_synchronize($product)
Arguments: $product is product data array
Description: Function creates new node of product type basing on retrieved $product array.
To save image of product into Drupal function magento_products_copy_image is called.
If current product already has a node at Drupal to store its data (this is detected by its identifier), the actual node is updated.
magento_products_get_nid($product_id)
Arguments: $product_id is the ID of product
Return value: $nid is the ID of node
Description: Using the ID of product, function figures if corresponded node exists at Drupal and if it does, function returns the ID of that node.
magento_products_get_product()
Return value: $old_products is already synchronized to Drupal products array
Description: Function gets the list of all products, having been already synchronized to Drupal (this is necessary for detection of outdated products).
magento_products_copy_image($url,$new_url,$nid = NULL)
Arguments: $url is the absolute address of image
$new_url is the relative address for storing at Drupal
$nid is the ID of product node
Return value: $image is an image object
Description: Function copies image by its absolute address, creating the required hierarchy of directories.
If that image already exists at Drupal (this is detected by its relative address at Drupal and filesize), a file presence in filesystem is checked.
If file was removed from filesystem by some reasons, it's copied there over again. Otherwise, an information of file is captured and object is created.
If such image does not exist at Drupal yet, it's copied to Drupal, an information of it is entered to database, file information is captured and object is created.
If such current node already has an image (this is detected by received $nid argument) different from retrieved, the old one is deleted.
getSizeFile($url)
Arguments: $url is the absolute address of image
Return value: $filesize is the size of file in bytes
Description: Function defines the size of file.
magento_products_nodeapi()
Description: Hook shows an actual price of product considering all the discounts and Tier Price upon fill node view.
Also additional information of product is received from Magento and added to Drupal cache, if it doesn't exist there yet or it's out-of-date.
magento_products_magento_event($event, $productId)
Arguments: $event is an event
$productId is the ID of product which was event-occured
Description: Hook, by which updating of product node at Drupal when it's updated at Magento is performed.
And hook removes product node at Drupal when it's removed at Magento.
magento_products_get_actual_price($node, $user)
Arguments: $node is the node of product
$user is an actual user
Return value: $price is an actual price of product
Description: Function calculates an actual price of product basing on Product price, Special price and Discounts price.
magento_products_get_tier_price($node, $price)
Arguments: $node is the node of product
$price is the price of product
Return value: $product_tier is applicable Tier Prices information array
Description: Function calculates applicable Tier Prices of actual node for current user.
magento_products_form_alter()
Description: Hook adds a button of manual synchronization of products with Magento to Drupal settings page.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion