Announcement

Collapse
No announcement yet.

Creating products and options using the runQuery API

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating products and options using the runQuery API

    Hello. I need to be able to create my products (and their options) by directly inserting them into the 3dcart database. I can insert a new product fine. THe problem is when I go to create the option headers in the prodfeatures table I don't know the value of the catalogid just created in the products table.

    I am trying to use the @@Identity function but it just returns 0. Here is the code to create a single product and option. Note the multiple queries sent to the server

    ============================
    #!/usr/bin/php -q
    <?php
    ERROR_REPORTING(E_ALL);
    ini_set('display_errors', true);

    $client = new soapclient('http://api.3dcart.com/cart_advanced.asmx?WSDL', array('trace' => 1,'soap_version' => SOAP_1_1));

    $query = "INSERT IGNORE INTO products (id,name,price) VALUES ('BAG-CART MIZ AEROLIT','Mizuno Aerolite Cart Bag',220.00)|;;|SELECT @@Identity|;;|INSERT IGNORE INTO prodfeatures SET featurecaption = 'Colour',featuretype = 'Dropdown',featurerequired = 1,item_id = (SELECT @@Identity)";

    $param = array(
    'storeUrl'=>"mystore",
    'userKey'=>"xxxxxxxxxxxxxxx",
    'sqlStatement' => "$query",
    'callBackURL' => ""
    );

    $result = $client->runQuery($param);
    echo $result->runQueryResult->any;
    ?>
    ================================

    The result I get is:
    <runQueryResponse xmlns=""><queryResult1>1 affected records</queryResult1><queryResult2><runQueryRecord><Expr10 00>0</Expr1000></runQueryRecord></queryResult2><queryResult3> affected records</queryResult3></runQueryResponse>

    The product inserts ok. Trying to retrieve @@Identity returns 0. Hence the 2nd Insert fails.

    I will have the same issue when I try and insert into the prodfeatures_options table as I will need to know the prodfeatures.id key value created.

    How can I find the record counter generated after an insert?
Working...
X