Ejemplo n.º 1
0
 * limitations under the License.
 */
require_once 'app/Mage.php';
Mage::init();
define('NUM_ENTITIES', 5000);
define('API_USER', 'apiUser');
define('API_KEY', 'someApiKey123');
define('USE_API', true);
$helper = Mage::helper('api_import/test');
if (USE_API) {
    // Create an API connection. Standard timeout for Zend_Http_Client is 10 seconds, so we must lengthen it.
    $client = new Zend_XmlRpc_Client(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . 'api/xmlrpc/');
    $client->getHttpClient()->setConfig(array('timeout' => -1));
    $session = $client->call('login', array(API_USER, API_KEY));
}
$entityTypes = array('product' => array('entity' => Mage_ImportExport_Model_Export_Entity_Product::getEntityTypeCode(), 'model' => 'catalog/product', 'types' => array('simple', 'configurable', 'bundle', 'grouped')), 'customer' => array('entity' => Mage_ImportExport_Model_Export_Entity_Customer::getEntityTypeCode(), 'model' => 'customer/customer', 'types' => array('standard')), 'category' => array('entity' => Danslo_ApiImport_Model_Import_Entity_Category::getEntityTypeCode(), 'model' => 'catalog/category', 'types' => array('standard')));
foreach ($entityTypes as $typeName => $entityType) {
    foreach ($entityType['types'] as $subType) {
        // Generation method depends on product type.
        printf('Generating %d %s %ss...' . PHP_EOL, NUM_ENTITIES, $subType, $typeName);
        $entities = $helper->{sprintf('generateRandom%s%s', ucfirst($subType), ucfirst($typeName))}(NUM_ENTITIES);
        // Attempt to import generated products.
        printf('Starting import...' . PHP_EOL);
        $totalTime = microtime(true);
        if (USE_API) {
            try {
                $client->call('call', array($session, 'import.importEntities', array($entities, $entityType['entity'])));
            } catch (Exception $e) {
                printf('Import failed: ' . PHP_EOL, $e->getMessage());
                printf('Server returned: %s' . PHP_EOL, $client->getHttpClient()->getLastResponse()->getBody());
                exit;
Ejemplo n.º 2
0
define('API_USER', 'apiUser');
define('API_KEY', 'someApiKey123');
define('USE_API', true);
ini_set('memory_limit', '2048M');
$helper = Mage::helper('api_import/test');
if (USE_API) {
    // Create an API connection
    $soapOptions = array('encoding' => 'UTF-8', 'trace' => true, 'exceptions' => true, 'login' => API_USER, 'password' => API_KEY, 'cache_wsdl' => 3, 'keep_alive' => 1);
    try {
        $client = new SoapClient(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . 'index.php/api/soap/?wsdl', $soapOptions);
        $session = $client->login(API_USER, API_KEY);
    } catch (Exception $e) {
        echo 'Exception :' . $e->getMessage();
    }
}
$entityTypes = array('product' => array('entity' => Mage_ImportExport_Model_Export_Entity_Product::getEntityTypeCode(), 'model' => 'catalog/product', 'types' => array('simple', 'configurable', 'bundle', 'grouped', 'image', 'localizable'), 'behavior' => 'append'), 'attributeSets' => array('entity' => 'attributeSets', 'types' => array('standard'), 'behavior' => 'append'), 'attributes' => array('entity' => 'attributes', 'types' => array('standard'), 'behavior' => 'append'), 'attributeAssociations' => array('entity' => 'attributeAssociations', 'types' => array('standard'), 'behavior' => 'append'), 'customer' => array('entity' => Mage_ImportExport_Model_Export_Entity_Customer::getEntityTypeCode(), 'model' => 'customer/customer', 'types' => array('standard'), 'behavior' => 'append'), 'category' => array('entity' => Danslo_ApiImport_Model_Import_Entity_Category::getEntityTypeCode(), 'model' => 'catalog/category', 'types' => array('standard'), 'behavior' => 'append'));
foreach ($entityTypes as $typeName => $entityType) {
    foreach ($entityType['types'] as $subType) {
        // Generation method depends on product type.
        printf('Generating %d %s %ss...' . PHP_EOL, NUM_ENTITIES, $subType, $typeName);
        $entities = $helper->{sprintf('generateRandom%s%s', ucfirst($subType), ucfirst($typeName))}(NUM_ENTITIES);
        // Attempt to import generated products.
        printf('Starting import...' . PHP_EOL);
        $totalTime = microtime(true);
        if (USE_API) {
            $data = array();
            if (count($entities) <= NUM_ROWS_BY_CALL || !NUM_ROWS_BY_CALL) {
                $data[] = $entities;
            } else {
                $data = array_chunk($entities, NUM_ROWS_BY_CALL);
            }