Created
September 25, 2017 21:22
-
-
Save waylay/33194b2d89baf562d5465f307da3fc7a to your computer and use it in GitHub Desktop.
Map Magento attachment file to WooCommerce product file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//SQL | |
$mydb = new wpdb('root','root','magento','localhost'); | |
$rows = $mydb->get_results(" | |
select p.entity_id, p.sku, f.title, f.uploaded_file | |
from pml_uni_fileuploader f | |
inner join pml_catalog_product_entity p | |
on find_in_set(p.entity_id, f.product_ids) | |
order by p.entity_id | |
"); | |
echo count($rows); | |
echo "<ul>"; | |
foreach ($rows as $obj) : | |
echo "<li>".$obj->entity_id." - ".$obj->sku." - ".$obj->title." - ".str_replace('custom/upload/','',$obj->uploaded_file)."</li>"; | |
$product_id = wc_get_product_id_by_sku($obj->sku); | |
$file_url = 'http://site.dev/wp-content/uploads/woocommerce_uploads/'.str_replace('custom/upload/','',$obj->uploaded_file); | |
$woo_files[$product_id][md5( $file_url )] = array( | |
'name' => $obj->title, | |
'file' => $file_url | |
); | |
update_post_meta( $product_id, '_downloadable', 'yes'); | |
update_post_meta( $product_id, '_downloadable_files', $woo_files[$product_id]); | |
update_post_meta( $product_id, '_download_limit', '-1'); | |
update_post_meta( $product_id, '_download_expiry', '-1'); | |
echo "Product: ".$product_id ." updated!"; | |
endforeach; | |
echo "</ul>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment