Magento, i need define first product image as thumbnail - mysql

I had imported my old oscommerce site with 15000 produts for magento!
But unfortably, the thumbnails are dont defined automatically
http://imgur.com/cNdXd
i can do maually, but 15000 produts is a larg number and i need sped a big amout of time for do it
if anywone can give-me a mysql command to set the first produts image as Base Image, Small Image and Thumbnail will be awesome
thanks

Try update them via api:
$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
$products = $proxy->call($sessionId, 'product.list');
foreach ($products as $product) {
$images = $proxy->call($sessionId, 'product_media.list', $product['sku'])
$imageFilename = $images[0]['file'];
$proxy->call($sessionId, 'product_media.update', array(
$product['sku'],
$imageFilename,
array('types' => array('image', 'thumbnail')
));
}
Related documentation links:
http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product_attribute_media
http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product#catalog_product.list

Im having a problem with this SQL code i got somewhere which is supposed to set your first image as image, small image and thumbnail:
UPDATE catalog_product_entity_media_gallery AS mg,
catalog_product_entity_media_gallery_value AS mgv,
catalog_product_entity_varchar AS ev
SET ev.value = mg.value
WHERE mg.value_id = mgv.value_id
AND mg.entity_id = ev.entity_id
AND ev.attribute_code IN ('image', 'small_image', 'thumbnail')
AND mgv.position = 1;
Doesn't change any rows...
Also, my attribute_id's for image, small_image, thumbnail and media_gallery in Magento CE v1.6.2 are 106,109,493,703 using EMSupermarket template.
The following code also does nothing:
UPDATE catalog_product_entity_media_gallery AS mg,
catalog_product_entity_media_gallery_value AS mgv,
catalog_product_entity_varchar AS ev
SET ev.value = mg.value
WHERE mg.value_id = mgv.value_id
AND mg.entity_id = ev.entity_id
AND ev.attribute_id IN (106,109,493)
AND mgv.position = 1;
Anyone how to do this correctly with my id's?
What happened with my oscommerce product import was that the imported product images only end up under the field name media_image, but not image, small_image or thumbnail so i want to copy the media_image values over to the other 3, any ideas how to do this?

I had the same problem. I found this page and ran that SQL command, and also did not get any results. But I modified it to work for me. Here is what I did.
First of all, I changed line 7 from:
AND ev.attribute_code IN ('image', 'small_image', 'thumbnail')
to
AND ev.attribute_ID = '74'
the 74 is my unique attribute id for 'image'. You will have a different number here. You find it by looking it up in mySQL...
75 was for 'small_image' and 76 for 'thumbnail'.
So I ran this code 3 times, 1 for each of those attribute number. Each time I change line 7 ev.attribute_ID = '75' :
UPDATE catalog_product_entity_media_gallery AS mg,
catalog_product_entity_media_gallery_value AS mgv,
catalog_product_entity_varchar AS ev
SET ev.value = mg.value
WHERE mg.value_id = mgv.value_id
AND mg.entity_id = ev.entity_id
AND ev.attribute_ID = '76'
AND mgv.position = 1;

Related

MYSQL DELETE INNER JOIN only shows deletes after page reload

I have managed to get working a Duplicate field Check using INNER JOIN with PHP MYSQL , however the delete only shows after a page reload , the 1st time i load the page the duplicate entry's are shown then i reload the page and the DELETES are no longer showing. i dont understand why, does this code show any reason for this to happen? a page refresh does not happen no matter what code i use, nothing is run during the IF ($RowsDC >1) check other than the DELETE statement
here is the code:
while($row = $stat->fetch()){
//checking for duplicates
try {
$db2 = new PDO("mysql:host=localhost;dbname=classifieds2", 'root', ''); // 1. set database with this instead of conect - or change conect to this
$db2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$queryDC="SELECT * FROM listings WHERE listID = ? AND UID = ? ";
$statDC=$db2->prepare($queryDC);
$statDC->execute(array("$listID","$UID"));
$ResultDC = $statDC->fetchAll();
$RowsDC = count($ResultDC);
if ($RowsDC >1){ $db2A = new PDO("mysql:host=localhost;dbname=classifieds2", 'root', ''); // 1. set database with this instead of conect - or change conect to this
$db2A->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query01DC="DELETE a FROM listings a INNER JOIN listings a2 WHERE a.id < a2.id AND a.listID = a2.listID ";
$stat01DC=$db2A->prepare($query01DC);
$stat01DC->execute();
??? here i have tried to refresh the page but it does not no matter how i try nothing is run ???
}
}
catch (PDOException $e){
$_SESSION['message']="Database Error #vbmDUPCHECK2 <br> <h6><h6>Signed Out For Security Reasons</h6></h6>";
$_SESSION['loggedin']='000';
echo $errorcall;
die();
exit();
}
}//WHILE END

Pull SKU, Manufacturer and custom attribute from Magento database

I'm trying to pull a full list of products from the database with the SKU, manufacturer and a custom attribute called 'GTIN'.
I'm really struggling with the custom attribute part.
This statement works to pull the manufacturer and SKU
SELECT cpe.sku, m1.manufacturer,
FROM catalog_product_entity AS cpe
INNER JOIN exportview_manufacturer AS m1 ON cpe.entity_id = m1.entity_id
My MySQL is very poor and I can't seem to get this custom attribute. I've found the following statement online which I KNOW has all the details I need to make this work but thus far I've been getting my head in a mess trying to implement it
SELECT e.entity_id AS product_id, var.value AS product_name
FROM catalog_product_entity e, eav_attribute eav, catalog_product_entity_varchar var
WHERE
e.entity_type_id = eav.entity_type_id
AND eav.attribute_code = 'gtin'
AND eav.attribute_id = var.attribute_id
AND var.entity_id = e.entity_id
I simply need the first statement to also include the 'gtin' column, but joining is where I'm falling short. Can someone please assist?
You need to create one PHP script to get all product and it's attribute. So first create all_product.php file on your Magento root and add below code.
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once '../app/Mage.php';
Mage::app();
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*') // select all attributes
->setPageSize(5000) // limit number of results returned
->setCurPage(1); // set the offset (useful for pagination)
foreach ($collection as $product) {
echo $product->getName(); //get name
/*you can get any attribue you want like name above. Even you can get all custom attribule for product for that you need to use print_r($collection->getData()) above foreach*/
}
Hope it will work.

Adding of Generic Markers to tt_news - Database related

I am trying to write a custom output to extend the tt_news-Extension. I have suceeded so far as I have successfully written:
My own extension (via the help of extension builder)
Found a method to output some of my data via GENERIC Markers and TypoScript
What I want to do is:
Read Data from a MySQL Table (from my extensions preferably)
Compare data with a tt_news Column (Column contains VARCHAR "1,2,3,4")
Look for a certain UID (WHERE tt_news.txy7... CONTAINS uid )
Only output the objects found in the list.
Now I know I should probably build a relational database in the end, containing uid, fahrzeug.uid, tt_news.uid , but I'm really trying to figure out a way to output stuff first.
I think I have a basic thinking mistake in there, but I really need to take a break, since im working nearly 6 hours on this now.
Maybe someone could provide me with some directions?
# Output via Generic Markers
temp.fahrzeuge = CONTENT
temp.fahrzeuge {
table = tx_y7fahrzeugdatenbank_domain_model_fahrzeug
wrap = <div class="tx_y7fahrzeuge_ausgabe">|</div>
select {
selectFields = uid,name,beschreibung
# where = tt_news.tx_y7fahrzeugdatenbank_participate CONTAINS uid
}
renderObj = COA
renderObj {
10 = TEXT
10.wrap = <span class="fzname">|</span>
10.field = name
20 = TEXT
20.wrap = <span class="fzdesc">|</span>
20.field = beschreibung
}
}
plugin.tt_news.genericmarkers {
fzparticipate = COA
fzparticipate {
10 = TEXT
10.value = <h2>Fahrzeuge</h2>
20 = CONTENT
20 < temp.fahrzeuge.renderObj
}
#currentnews = plugin.tt_news.currentUid
}
1) add the whole template to your COA not only the renderObj:
fzparticipate = COA
fzparticipate {
10 = TEXT
10.value = <h2>Fahrzeuge</h2>
20 < temp.fahrzeuge
}
2) make sure you have a pid set for the objects you are selecting and that you in some way set the pidInList option within the select. The result will be empty if you don't!:
select {
#set your pid here
pidInList = 35
# selected fields
selectFields=uid
where = 1=1
}
3) You can add where-clauses in 2 ways: Where & andWhere
3.1) andWhere has a cObject which you can set
table = tx_myTable_mapping
select {
#Do not forget the pid!
pidInList = {$plugin.myPlugin.pid}
#did you know that you can use distinct here?
selectFields=DISTINCT(name)
#you can use a COA here as well, for more complex clauses
andWhere.cObject = TEXT
andWhere.cObject {
#This 3 lines come in handy to prevent SQLInjections
#by fully quoting the GET/POST variable
data = GP:myPostVariable
#tell the system for which table it should do the quoting
fullQuoteStr = tx_myTable_mapping
wrap = myTablefield=|
}
}
3.2) where supports data and wrap options
table = tx_myTable_mapping
select {
#you can do joins as well:
join = fe_users on tx_myTable_mapping.fe_user = fe_users.uid
#again with the pageId
pidInList = {$plugin.myPlugin.pid}
selectFields=tx_myTable_mapping.name as MyLabel
#you can set the where in a static way like you did
#or you use the data and wrap options
where.data = TSFE:fe_user|user|uid
where.wrap = (fe_users.uid = | )
}

Why I Cannot Change A Field in MySQL

"UPDATE transaksi
SET nama ='".$nama."', kamar = '".$kamar."', hp = '".$hp."',
masuk = '".$masuk."', keluar ='".$keluar."', tagih ='".$tagih."',
jumlah ='".$jumlah."', bawa ='".$bawa."', bayar ='".$bayar."'
where kamar ='".$kamar."'"
I made this code and it works normally until I realized that the field "kamar" cannot be changed.
I wonder where is my fault because another fields can be changed when I activate this method.
Please help

mysql update 2 blobs at once not working

i'm having an issue when trying to update two BLOB fields in a row using mysql and php commands.
Inserting the BLOBs into the row seems to work no problem, here is what I do.
$logotemp = $_FILES['eventlogo']['tmp_name'];
$thumbnailtemp = $_FILES['eventthumbnail']['tmp_name'];
$openlogo = fopen($logotemp, 'r');
$openthumbnail = fopen($thumbnailtemp, 'r');
$logo = fread($openlogo, filesize($logotemp));
$logo = addslashes($logo);
$thumbnail = fread($openthumbnail, filesize($thumbnailtemp));
$thumbnail = addslashes($thumbnail);
fclose($openlogo);
fclose($openthumbnail);
So I have two form file inputs, and those files are read, and then set as the variables $log and $thumbnail. I then use the following command to enter this into the DB:
$qry = "INSERT INTO $table (`Event Logo`, `Venue Logo`) VALUES ('$logo', '$thumbnail')";
$result = mysql_query($qry);
if(!$result) {
die(mysql_error());
}
The above works fine, although I have trimmed out the rest of the fields that also get filled. The query works, and I can return the images to a page, and then display them along with all of the other information from that row.
I then want to edit the row, so created a new php file called edit.php, which is a copy of the php file used above, called new.php.
This means that the form is identical, and when the page is displayed, the value for each input is prefilled with the info from the database, the logo and thumbnail are shown next to the upload fields.
If I then run a query to update the row, using almost the same code as above, it always enteres an empty value into both blobs, essentially deleting the uploaded images. Here is what happens:
$id = $_POST['eventid'];
$logotemp = $_FILES['eventlogo']['tmp_name'];
$openlogo = fopen($logotemp, 'r');
$logo = fread($openlogo, filesize($logotemp));
$thumbnailtemp = $_FILES['eventthumbnail']['tmp_name'];
$openthumbnail = fopen($thumbnailtemp, 'r');
$thumbnail = fread($openthumbnail, filesize($thumbnailtemp));
fclose($openlogo);
fclose($openthumbnail);
So once again, the form fields are still called eventlogo and eventthumbnail, and the variables are still $logo and $thumbnail. I then use the following query to update the row:
$qry = "UPDATE $table SET `Event Name` = '$name', `Date` = '$date', `Time` = '$time', `Venue` = '$venue', `Price` = '$price', `Open To` = '$opento', `Rep Name` = '$repname', `Rep Email` = '$repemail', `Address` = '$address', `Website` = '$website', `Phone` = '$phone', `Description` = '$description', `Event Logo` = '$logo', `Venue Logo` = '$thumbnail' WHERE `Event ID` = '$id'";
I have left in the other variables that are updated this time.
$result = mysql_query($qry);
if(!$result) {
die(mysql_error());
}
When the query runs, it will update any other fields I want, except for the two image BLOB fields at the end. Considering I copied and pasted the code for the upload fields, the code to read the contents of that field, and then manually typed out a query to update those fields, I can't see what's going wrong.
Am I missing something obvious? Any help is greatly appreciated.
Thanks, Eds
Cant find the code I sorted this with, but I think I ended up just updating one at a time.