Skip to content

Instantly share code, notes, and snippets.

@sn
Created March 9, 2012 15:24
Show Gist options
  • Save sn/2006978 to your computer and use it in GitHub Desktop.
Save sn/2006978 to your computer and use it in GitHub Desktop.
Create new product in Mooblr API
<?php
/**
* Add a new product to the system
*
* @param string $sku
* @param float $cost
* @param string $name
* @param string $desc
* @param float $markup
* @param int $categories_id
* @param string $url
* @return int
*/
public function create_product($sku, $cost, $name, $desc, $markup, $categories_id, $url = "")
{
$date = date("Y-m-d H:i:s");
$price = $cost * $markup;
// Create product
$new_product = array(
'products_model' => $sku,
'products_status' => 0, // Disabled by default
'products_instock' => 1,
'products_tax_class_id' => 1,
'products_cost' => $cost,
'products_markup' => $markup,
'products_price' => $price,
'products_date_added' => $date,
'products_last_modified' => $date,
'products_quantity' => 0
);
$this->db->insert('products', $new_product);
$product_id = $this->db->insert_id();
// Create product desc
$new_product_desc = array(
'products_id' => $product_id,
'products_name' => $name,
'products_description' => $desc,
'products_supplier_description' => $desc,
'products_url' => $url,
'language_id' => 1
);
$this->db->insert('products_description', $new_product_desc);
// Add products to categories
$new_product_category = array(
'products_id' => $product_id,
'categories_id' => $categories_id
);
$this->db->insert('products_to_categories', $new_product_category);
return $product_id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment