Created
June 27, 2019 12:25
-
-
Save incrize/abc037320d1db3019919565569127735 to your computer and use it in GitHub Desktop.
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 | |
define('AREA', 'A'); | |
define('ACCOUNT_TYPE', 'admin'); | |
require(dirname(__FILE__) . '/init.php'); | |
\Tygh\Registry::set('runtime.company_id', 0); | |
$products = db_get_array('SELECT product_id, __variation_options FROM cscart_products WHERE __variation_options IS NOT NULL AND product_type = ?s', 'V'); | |
$update_product_ids = []; | |
foreach ($products as $product) { | |
fn_echo("Starting check product {$product['product_id']}<br>"); | |
$variation_options = (array) @json_decode($product['__variation_options'], true); | |
foreach ($variation_options as $option_id => $variant_id) { | |
$option_exists = (bool) db_get_field('SELECT option_id FROM cscart_product_options WHERE option_id = ?i', $option_id); | |
$variant_exists = (bool) db_get_field('SELECT variant_id, option_id FROM cscart_product_option_variants WHERE option_id = ?i AND variant_id = ?i', $option_id, $variant_id); | |
if ($variant_exists && $option_exists) { | |
continue; | |
} | |
if (!$option_exists) { | |
fn_echo("Option {$option_id} not found<br>"); | |
} | |
if (!$variant_exists) { | |
fn_echo("Option variatn {$variant_id} not found<br>"); | |
} | |
db_query("UPDATE cscart_products SET __variation_options = NULL, parent_product_id = 0, product_type = 'P' WHERE product_id = ?i", $product['product_id']); | |
fn_echo("<strong>Product type of product {$product['product_id']} updated from variation to simple product!</strong><br>"); | |
$update_product_ids[] = $product['product_id']; | |
break; | |
} | |
fn_echo("Check product {$product['product_id']} finished<br>"); | |
} | |
foreach ($update_product_ids as $product_id) { | |
$url = fn_url('products.update?product_id=' . $product_id); | |
fn_echo("<a href=\"{$url}\" target=\"_blank\">{$url}</a><br>"); | |
} | |
fn_echo("Done"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment