PageRenderTime 37ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/magmi/integration/samples/sample2_configurables.php

https://bitbucket.org/jit_bec/shopifine
PHP | 79 lines | 32 code | 9 blank | 38 comment | 4 complexity | 4ab28a07812ae27c9ad26bf3edbb68fd MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. require_once("../../inc/magmi_defs.php");
  3. require_once("../inc/magmi_datapump.php");
  4. /** Define a logger class that will receive all magmi logs **/
  5. class TestLogger
  6. {
  7. /**
  8. * logging methos
  9. * @param string $data : log content
  10. * @param string $type : log type
  11. */
  12. public function log($data,$type)
  13. {
  14. echo "$type:$data\n";
  15. }
  16. }
  17. /**
  18. * create a Product import Datapump using Magmi_DatapumpFactory
  19. */
  20. $dp=Magmi_DataPumpFactory::getDataPumpInstance("productimport");
  21. /**
  22. * Start import session
  23. * with :
  24. * - profile : test_ptj
  25. * - mode : create
  26. * - logger : an instance of the class defined above
  27. */
  28. /**
  29. * FOR THE SAMPLE TO WORK CORRECTLY , YOU HAVE TO DEFINE A test_ptj profile with :
  30. * UPSELL/CROSS SELL, ITEM RELATER, CATEGORIES IMPORTER/CREATOR selected
  31. * ON THE FLY INDEXER IS RECOMMENDED (better endimport performance)
  32. * Reindexer needed also to have products show up on front : select all but "catalog_category_product" & "url_rewrite" (both are handled by on the fly indexer)
  33. */
  34. $dp->beginImportSession("default","create",new TestLogger());
  35. /* Create 5000 items , with every 100 :
  36. *
  37. * upsell on last 100 even
  38. * cross sell on last 100 odd
  39. * related on last 100 every 5
  40. * cross sell on last 100 every 10
  41. * categories named catX/even or catX/odd with X is thousand of item (using categories plugin) */
  42. for($sku=0;$sku<=200;$sku++)
  43. {
  44. // price : random between $1 & $500
  45. $item=array("store"=>"admin","type"=>"simple","sku"=>str_pad($sku,5,"0",STR_PAD_LEFT),"name"=>"item".$sku,"description"=>"test".$sku,"price"=>rand(1,500),"min_qty"=>3,"qty"=>"+7");
  46. //color : radom c0/c10
  47. $item["color"]="c".strval(rand(0, 10));
  48. //now some fun, every 100 items, create some relations
  49. if($sku>99 && $sku%100==0)
  50. {
  51. //first, we'll remove all existing relations (upsell/cross sell / related)
  52. $subskus=array();
  53. for($i=$sku-99;$i<$sku;$i++)
  54. {
  55. //related item sku
  56. $subskus[]=str_pad($i,5,"0",STR_PAD_LEFT);
  57. }
  58. $item["simples_skus"]=implode(",",$subskus);
  59. $item["type"]="configurable";
  60. $item["configurable_attributes"]="color";
  61. //cross relate with all skus ending by 2
  62. $item["xre_skus"]="re::.*2$";
  63. //star relate all skus ending with 1
  64. $item["*re_skus"]="re::.*1$";
  65. }
  66. /* import current item */
  67. $dp->ingest($item);
  68. }
  69. /* end import session, will run post import plugins */
  70. $dp->endImportSession();