I have a script that pulls data from 3rd party file. My import simply parses and inserts, which is fine doing work.
The problem comes with images.
When the import script runs, it first deletes all existing items and then starts importing, enter all the products and images in the gallery.
On the first import, everything is fine, the images go and I do not see any problem on the front. The problem occurs when I import these products again, it does not seem to delete all the images, as the products re-import, for example, for example, 4 images are correct, then empty rows Loads like images
I do not want to see these blank lines, but I'm not sure why they are.
Could it be because the image for the product is already in the catalog?
I am really unsure what this is doing and what it is doing.
Thanks
Edit:
My code is:
need_once ('app / mage.php'); $ App = Dana :: app ('default'); $ Product = grain :: getSingleton ('catalog / product'); $ Txt_file = file_get_contents ('test.txt'); $ Rows = explosion ("\ n", $ txt_file); ($ Rows) array_shift; Foreign currency ($ line = & $; $ lines in data form) {// Line get data $ row_data = explosion ('^', $ data); $ Information [$ line] ['unique'] = $ row_data [0]; $ Info [$ row] ['client'] = $ row_data [1]; $ Info [$ row] ['Make'] = $ line_data [2]; $ Information [$ line] ['model'] = $ row_data [3]; $ Info [$ row] ['adtext'] = $ row_data [4]; // Display images $ row_images = explosion (',', $ info [$ line] ['picture protection']); Forex Currency ($ row_image $ row_image) {$ product- & gt; AddImageToMediaGallery (Dana :: Mill-Besedia ('Media'). DS Import ''. $ Row_image, array ('image', 'small_image', 'thumbnail'), false, false); } $ Product- & gt; SetStoreID (Dana :: app) - & gt; GetStore (true) - & gt; getWebsite () - & gt; getId ()); $ Product- & gt; SetWebsiteIds (array (Dana :: app) - & gt; getStore (true) - & gt; getWebsite () - & gt; getId ()); $ Product- & gt; SetId ($ information [$ line] ['id']); $ Product- & gt; SetSku (strtolower ($ info [$ line] ['create']). '-' strtolower ($ information [$ line]. ['Model'])); $ Product- & gt; SetName ($ information [$ line] ['create']); $ Product- & gt; SetDescription ($ information [$ line] ['ad text']); Try {$ product- & gt; Save (); "Saved" echo; } Hold (exception $ east) {echo "prefix" $ Ex. "& Lt; / pre & gt;"; }} Is this because addImageToMediaGallery is said in each iteration and adding each image to each product? Thank you
OK so I figured out my problem The call was transferred to getSingleton inside foreach I and I added the following: $ product = mage :: getModel ('catalog / product') ; I again, after each iteration, unset from the following:
unset ($ product); Not set ($ info); Not set ($ stockData); Not set ($ row_images); It seemed to fix my script and now each product imports the product into the appropriate product instead of importing other products and adding random empty entries
Thanks all
Comments
Post a Comment