[solved] how to create products on the fly

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
andy1984
New Member
New Member
Posts: 5
Joined: Mon Sep 12, 2011 2:09 pm

[solved] how to create products on the fly

Post by andy1984 »

i have calguys ecommercebase, cart, products, orders modules installed and all working 100%.

products module works perfectly but im now thinking i could save myself a lot of time and overheads if i got the products from my supplier as a customer is searching on my website.

i wrote a little bit of code to login to one of my suppliers using Curl, retrieve the product, price, description and output it to a page depending on my customers search criteria.

what im trying to figure out is how to allow the customer to add their chosen product to their cart then checkout without the need of adding the product manually through products module myself.

ive been toying with a few ideas and one is if the customer wants the product and clicks add to cart, cmsms will add it to products module in the background and then add it to the actual cart module. after time the products module would become bloated with useless information so will delete it once purchase has been completed.

if anyone has any input or any other method of achieving what im trying to do i would be glad to hear from you.

Regards,

Andy
andy1984
New Member
New Member
Posts: 5
Joined: Mon Sep 12, 2011 2:09 pm

Re: how to create products on the fly

Post by andy1984 »

ive made some success with adding a product to the database. im now struggling with adding it to the cart after this has been done using user defined tags to achieve all of this.

i found this useful little piece of code in the custom udt.

Code: Select all

$gCms = cmsms(); //global $gCms;
$db = &$gCms->db;
if( isset($_POST['autoprod_submit']) )
{
if( !isset( $gCms->modules['Cart'] ) || !isset( $gCms->modules['Cart']['object'] ) )
{
return;
}
//database insert code goes here[removed from thread but does work]
$themoduleiwant = $gCms->modules['Cart']['object'];
$themoduleiwant->_add_cart_item(0,$db->Insert_ID(),0,$_POST['quantity'],0);
echo "product should have been added - check cart contents to confirm";
}
i had to change the _add_cart_item function from protected to public so i could use it outside.

for some odd reason though it is not adding to the cart, am i missing some vital step before adding to the cart?. entire project hinges on this final step.

still a little unfamiliar with inner workings of cmsms but im getting there :D
andy1984
New Member
New Member
Posts: 5
Joined: Mon Sep 12, 2011 2:09 pm

Re: how to create products on the fly

Post by andy1984 »

i figured out my solution.

Code: Select all

$gCms = cmsms();
$themoduleiwant = $gCms->modules['Cart']['object'];

if( isset($_POST['cart_submit']) )
  {
$product_id = 8; //temp
$supplier_mod = 'Products';
$source = 'Products';

$product = cg_ecomm::get_product_info($supplier_mod,$product_id);
$session_obj = new cge_session($themoduleiwant->GetName().'_add');

$obj = new cg_ecomm_cartitem(0,$product_id,$_POST['cart_quantity']);
	$product = cg_ecomm::get_product_info($source,$product_id);
	$obj->set_type($product->get_type());
	$obj->set_source($source);
	$obj->set_product_id($product_id);
	$obj->set_unit_weight($product->get_weight());
	$obj->set_base_price($product->get_price());
    $res = $themoduleiwant->AddCartItem($obj);
    return $res;
}
its cheap and nasty, just how i like it. but it works for me hopefully if anyone else reads this hoping to sdo something similar they will find this helpful.
Post Reply

Return to “Modules/Add-Ons”