SELECT
c.entity_id AS category_id,
cev.value AS category_name,
p.entity_id AS product_id,
p.sku AS product_sku,
cp.position AS product_position
FROM
catalog_category_product cp
INNER JOIN
catalog_category_entity c ON cp.category_id = c.entity_id
INNER JOIN
catalog_product_entity p ON cp.product_id = p.entity_id
LEFT JOIN
catalog_category_entity_varchar cev ON c.entity_id = cev.entity_id
AND cev.attribute_id = (
SELECT attribute_id FROM eav_attribute
WHERE attribute_code = 'name' AND entity_type_id = (
SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_category'
)
)
ORDER BY
c.entity_id ASC, cp.position ASC;
EdiSES – Prodotti Disabilitati
SELECT DISTINCT cpe.entity_id, cpe.sku, cpev_name.value AS product_name
FROM catalog_product_entity AS cpe
JOIN catalog_product_entity_int AS cpei_visibility ON cpe.entity_id = cpei_visibility.entity_id
JOIN catalog_product_entity_int AS cpei_status ON cpe.entity_id = cpei_status.entity_id
JOIN cataloginventory_stock_item AS csi ON cpe.entity_id = csi.product_id
JOIN catalog_product_entity_varchar AS cpev_name ON cpe.entity_id = cpev_name.entity_id
WHERE cpei_status.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'status' AND entity_type_id = 4)
AND cpei_status.value = 1 /* Stato abilitato */
AND cpei_visibility.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'visibility' AND entity_type_id = 4)
AND cpei_visibility.value = 2 /* Visibilità solo catalogo */
AND csi.manage_stock = 1 /* Gestione inventario non disponibile */
AND cpev_name.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = 4);
fare riferimento allo script prodotti-disabilitati.php
// TODO
abilitare eliminazione record _rivolgiti_libreria se già esistente
Dea Salus – WooCommerce Print Invoice & Delivery Note/Templates
<?php
/**
* Print order content. Copy this file to your themes
* directory /woocommerce/print-order to customize it.
*
* @package WooCommerce Print Invoice & Delivery Note/Templates
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<div class="order-branding">
<div class="company-logo" style="display:inline-block;width:50%;">
<?php
if ( wcdn_get_company_logo_id() ) :
?>
<?php wcdn_company_logo(); ?><?php endif; ?>
</div>
<div class="order-notes" style="display:inline-block;margin:0px;">
<?php if ( wcdn_has_customer_notes( $order ) ) : ?>
<h4><?php esc_attr_e( 'Customer Note', 'woocommerce-delivery-notes' ); ?></h4>
<?php wcdn_customer_notes( $order ); ?>
<?php endif; ?>
<?php do_action( 'wcdn_after_notes', $order ); ?>
</div><!-- .order-notes -->
<div class="company-info">
<?php
if ( ! wcdn_get_company_logo_id() ) :
?>
<h1 class="company-name"><?php wcdn_company_name(); ?></h1><?php endif; ?>
<div class="company-address"><?php wcdn_company_info(); ?></div>
</div>
<?php do_action( 'wcdn_after_branding', $order ); ?>
</div><!-- .order-branding -->
<div class="order-addresses">
<div class="billing-address">
<h3><?php esc_attr_e( 'Billing Address', 'woocommerce-delivery-notes' ); ?></h3>
<address>
<?php
if ( ! $order->get_formatted_billing_address() ) {
esc_attr_e( 'N/A', 'woocommerce-delivery-notes' );
} else {
echo wp_kses_post( apply_filters( 'wcdn_address_billing', $order->get_formatted_billing_address(), $order ) );
}
?>
</address>
</div>
<div class="shipping-address">
<h3><?php esc_attr_e( 'Shipping Address', 'woocommerce-delivery-notes' ); ?></h3>
<address>
<?php
if ( ! $order->get_formatted_shipping_address() ) {
esc_attr_e( 'N/A', 'woocommerce-delivery-notes' );
} else {
echo wp_kses_post( apply_filters( 'wcdn_address_shipping', $order->get_formatted_shipping_address(), $order ) );
}
?>
</address>
</div>
<?php do_action( 'wcdn_after_addresses', $order ); ?>
</div><!-- .order-addresses -->
<div class="order-info">
<h2><?php wcdn_document_title(); ?></h2>
<ul class="info-list">
<?php
$fields = apply_filters( 'wcdn_order_info_fields', wcdn_get_order_info( $order ), $order );
?>
<?php foreach ( $fields as $field ) : ?>
<li>
<strong><?php echo wp_kses_post( apply_filters( 'wcdn_order_info_name', $field['label'], $field ) ); ?></strong>
<span><?php echo wp_kses_post( apply_filters( 'wcdn_order_info_content', $field['value'], $field ) ); ?></span>
</li>
<?php endforeach; ?>
<?php
$spedizione = $order->get_shipping_method();
if ($spedizione == 'Ritiro in Negozio (Padova, Via Guizza 215)'){
?>
<li>
<strong>Spedizione</strong>
<span style="font-weight:bold;">RITIRO IN NEGOZIO</span>
</li>
<?php
}
?>
<?php
$spedizione = $order->get_shipping_method();
if ($spedizione == 'Ritiro in Negozio (Schiavonia - C/O Sanitaria Ospedale)'){
?>
<li>
<strong>Spedizione</strong>
<span style="font-weight:bold;">RITIRO SCHIAVONIA</span>
</li>
<?php
}
?>
<?php
$payment_method = $order->get_payment_method_title();
if ($payment_method === 'Pay Later'){
?>
<li>
<strong>Pagamento:</strong>
<span style="font-weight:bold;">PayPal in 3 rate</span>
</li>
<?php
}
?>
<?php
// Ottenere lo stato della richiesta di fattura
$fattura_ricevuta = get_post_meta( $order->get_id(), 'fattura_ricevuta', true );
// Verificare se è stata richiesta la fattura
if ( $fattura_ricevuta && $fattura_ricevuta === 'SI' ) :
?>
<li>
<strong><?php esc_attr_e( 'Richiesta Fattura', 'woocommerce-delivery-notes' ); ?></strong>
<span style="font-weight:bold;"><?php esc_html_e( 'Sì', 'woocommerce-delivery-notes' ); ?></span>
</li>
<?php endif; ?>
<?php
// Ottenere lo stato della richiesta di pacco regalo
$pacco_regalo = get_post_meta( $order->get_id(), 'pacco_regalo', true );
// Verificare se è stata richiesta la confezione regalo
if ( $pacco_regalo && $pacco_regalo === 'Sì' ) :
?>
<li>
<strong><?php esc_attr_e( 'Confezione Regalo', 'woocommerce-delivery-notes' ); ?></strong>
<span style="font-weight:bold;"><?php esc_html_e( 'Sì', 'woocommerce-delivery-notes' ); ?></span>
</li>
<?php endif; ?>
</ul>
<?php do_action( 'wcdn_after_info', $order ); ?>
</div><!-- .order-info -->
<div class="order-items">
<table>
<thead>
<tr>
<th class="head-name"><span><?php esc_attr_e( 'Product', 'woocommerce-delivery-notes' ); ?></span></th>
<th class="head-item-price"><span><?php esc_attr_e( 'Price', 'woocommerce-delivery-notes' ); ?></span></th>
<th class="head-quantity"><span><?php esc_attr_e( 'Quantity', 'woocommerce-delivery-notes' ); ?></span></th>
<th class="head-price"><span><?php esc_attr_e( 'Total', 'woocommerce-delivery-notes' ); ?></span></th>
</tr>
</thead>
<tbody>
<?php
if ( count( $order->get_items() ) > 0 ) :
?>
<?php foreach ( $order->get_items() as $item_id => $item ) : ?>
<?php
$product = apply_filters( 'wcdn_order_item_product', $item->get_product(), $item );
if ( ! $product ) {
continue;
}
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
$item_meta = new WC_Order_Item_Product( $item['item_meta'], $product );
} else {
$item_meta = new WC_Order_Item_Meta( $item['item_meta'], $product );
}
?>
<tr>
<td class="product-name">
<?php do_action( 'wcdn_order_item_before', $product, $order, $item ); ?>
<span class="name">
<?php
$addon_name = $item->get_meta( '_wc_pao_addon_name', true );
$addon_value = $item->get_meta( '_wc_pao_addon_value', true );
$is_addon = ! empty( $addon_value );
if ( $is_addon ) { // Displaying options of product addon.
$addon_html = '<div class="wc-pao-order-item-name">' . esc_html( $addon_name ) . '</div><div class="wc-pao-order-item-value">' . esc_html( $addon_value ) . '</div></div>';
echo wp_kses_post( $addon_html );
} else {
$product_id = $item['product_id'];
$prod_name = get_post( $product_id );
$product_name = $prod_name->post_title;
echo wp_kses_post( apply_filters( 'wcdn_order_item_name', $product_name, $item ) );
?>
</span>
<?php
$item_meta_fields = apply_filters( 'wcdn_product_meta_data', $item['item_meta'], $item );
$product_addons = array();
$woocommerce_product_addon = 'woocommerce-product-addons/woocommerce-product-addons.php';
if ( in_array( $woocommerce_product_addon, apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) ), true ) ) {
$product_id = $item['product_id'];
$product_addons = WC_Product_Addons_Helper::get_product_addons( $product_id );
}
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
if ( isset( $item['variation_id'] ) && 0 !== $item['variation_id'] ) {
$variation = wc_get_product( $item['product_id'] );
foreach ( $item_meta_fields as $key => $value ) {
if ( ! ( 0 === strpos( $key, '_' ) ) ) {
if ( is_array( $value ) ) {
continue;
}
$term_wp = get_term_by( 'slug', $value, $key );
$attribute_name = wc_attribute_label( $key, $variation );
if ( ! empty( $product_addons ) ) {
foreach ( $product_addons as $addon ) {
if ( 'file_upload' === $addon['type'] ) {
if ( $key === $addon['name'] ) {
$value = wp_basename( $value );
}
}
}
}
if ( isset( $term_wp->name ) ) {
echo '<br>' . wp_kses_post( $attribute_name . ':' . $term_wp->name );
} else {
echo '<br>' . wp_kses_post( $attribute_name . ':' . $value );
}
}
}
} else {
foreach ( $item_meta_fields as $key => $value ) {
if ( ! ( 0 === strpos( $key, '_' ) ) ) {
if ( is_array( $value ) ) {
continue;
}
if ( ! empty( $product_addons ) ) {
foreach ( $product_addons as $addon ) {
if ( 'file_upload' === $addon['type'] ) {
if ( $key === $addon['name'] ) {
$value = wp_basename( $value );
}
}
}
}
echo '<br>' . wp_kses_post( $key . ':' . $value );
}
}
}
} else {
$item_meta_new = new WC_Order_Item_Meta( $item_meta_fields, $product );
$item_meta_new->display();
}
?>
<br>
<dl class="extras">
<?php if ( $product && $product->exists() && $product->is_downloadable() && $order->is_download_permitted() ) : ?>
<dt><?php esc_attr_e( 'Download:', 'woocommerce-delivery-notes' ); ?></dt>
<dd>
<?php
// translators: files count.
printf( esc_attr__( '%s Files', 'woocommerce-delivery-notes' ), count( $item->get_item_downloads() ) );
?>
</dd>
<?php endif; ?>
<?php
wcdn_print_extra_fields( $item );
$fields = apply_filters( 'wcdn_order_item_fields', array(), $product, $order, $item );
foreach ( $fields as $field ) :
?>
<dt><?php echo esc_html( $field['label'] ); ?></dt>
<dd><?php echo esc_html( $field['value'] ); ?></dd>
<?php endforeach; ?>
</dl>
<?php } ?>
<?php do_action( 'wcdn_order_item_after', $product, $order, $item ); ?>
</td>
<td class="product-item-price">
<span><?php echo wp_kses_post( wcdn_get_formatted_item_price( $order, $item ) ); ?></span>
</td>
<td class="product-quantity">
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $item['qty'], $item ) ); ?></span>
</td>
<td class="product-price">
<span><?php echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) ); ?></span>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
<tfoot>
<?php
$totals_arr = $order->get_order_item_totals();
if ( $totals_arr ) :
foreach ( $totals_arr as $total ) :
?>
<tr>
<td class="total-name"><span><?php echo wp_kses_post( $total['label'] ); ?></span></td>
<td class="total-item-price"></td>
<?php if ( 'Total' === $total['label'] ) { ?>
<td class="total-quantity"><?php echo wp_kses_post( $order->get_item_count() ); ?></td>
<?php } else { ?>
<td class="total-quantity"></td>
<?php } ?>
<td class="total-price"><span><?php echo wp_kses_post( $total['value'] ); ?></span></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tfoot>
</table>
<?php do_action( 'wcdn_after_items', $order ); ?>
</div><!-- .order-items -->
<div class="order-thanks">
<?php wcdn_personal_notes(); ?>
<?php do_action( 'wcdn_after_thanks', $order ); ?>
</div><!-- .order-thanks -->
<div class="order-colophon">
<div class="colophon-policies">
<?php wcdn_policies_conditions(); ?>
</div>
<div class="colophon-imprint">
<?php wcdn_imprint(); ?>
</div>
<?php do_action( 'wcdn_after_colophon', $order ); ?>
</div><!-- .order-colophon -->
EdiSES – Lista categorie
SELECT
cce.entity_id AS category_id,
ccev.value AS category_name,
cce.parent_id,
CASE
WHEN cce.parent_id = 1 THEN 'Principale'
ELSE 'Sottocategoria'
END AS tipo_categoria,
ccei.value AS is_active
FROM
catalog_category_entity AS cce
JOIN catalog_category_entity_varchar AS ccev ON cce.entity_id = ccev.entity_id
JOIN eav_attribute AS ea ON ccev.attribute_id = ea.attribute_id
AND ea.attribute_code = 'name'
JOIN catalog_category_entity_int AS ccei ON cce.entity_id = ccei.entity_id
JOIN eav_attribute AS eai ON ccei.attribute_id = eai.attribute_id
AND eai.attribute_code = 'is_active'
WHERE
ccev.store_id = 0
AND ccei.value = 1
GROUP by
category_id;
EdiSES – Prodotti disabilitati
SELECT DISTINCT cpe.entity_id, cpe.sku, cpev_name.value AS product_name
FROM catalog_product_entity AS cpe
JOIN catalog_product_entity_int AS cpei_visibility ON cpe.entity_id = cpei_visibility.entity_id
JOIN catalog_product_entity_int AS cpei_status ON cpe.entity_id = cpei_status.entity_id
JOIN cataloginventory_stock_item AS csi ON cpe.entity_id = csi.product_id
JOIN catalog_product_entity_varchar AS cpev_name ON cpe.entity_id = cpev_name.entity_id
WHERE cpei_status.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'status' AND entity_type_id = 4)
AND cpei_status.value = 1 /* Stato abilitato */
AND cpei_visibility.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'visibility' AND entity_type_id = 4)
AND cpei_visibility.value = 2 /* Visibilità solo catalogo */
AND csi.manage_stock = 0 /* Gestione inventario non disponibile */
AND cpev_name.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = 4)
vanno eliminati gli ebook
Categorie – Descrizione HTML
Questo script va fatto girare dopo l’import delle categorie, si occupa di sistemare i tag html delle descrizioni senza far tirare 10000 porchi
<?php
// Includi il file wp-load.php per avere accesso alle funzioni di WordPress
require_once('wp-load.php');
// Ottieni tutte le categorie di WooCommerce
$args = array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
);
$product_categories = get_terms($args);
// Controlla se ci sono categorie
if (!empty($product_categories)) {
foreach ($product_categories as $category) {
if (!empty($category) && !is_wp_error($category)) {
// Ottieni l'ID della categoria
$category_id = $category->term_id;
// Ottieni la descrizione della categoria
$description = $category->description;
// Processa la descrizione qui se necessario
// Per esempio, potresti voler usare html_entity_decode() o una funzione simile
// per assicurarti che i tag HTML siano interpretati correttamente
$processed_description = html_entity_decode($description);
// Aggiorna la descrizione della categoria con la versione elaborata
wp_update_term($category_id, 'product_cat', array(
'description' => $processed_description,
));
}
}
echo 'Le descrizioni delle categorie sono state aggiornate con successo.';
} else {
echo 'Non ci sono categorie da aggiornare.';
}
Aggiornamento EdiSES prodotti/categorie
Prima di tutto si esegue l’import sulla macchina virtuale 192.168.220.136/wordpress, a lei è demandato il compito di gestire l’import fin dal giorno 0.
Va copiata la tabella catalog_product_entity sul database edises_import
Si esporta il file csv tramite url: http://192.168.220.136/wordpress/export-attr.php
Si importa il file su un database a caso online, di seguito la stuttura di default in base all’esportazione (potrebbe variare)
I prodotti vanno esportati con l’ultimo template, poi si fa girare uno script che modifica il file csv e si carica quello perché contiene già colonne extra.
Bisogna esportare le categorie WooCommerce, solo dopo fare l’import dei prodotti, prendere CAT-3 come riferimento, va modificato anche woo-custom-menu-link.php come segue
// Aggiungi il campo personalizzato al form di modifica della categoria
add_action('product_cat_edit_form_fields', 'aggiungi_campo_personalizzato_categoria');
function aggiungi_campo_personalizzato_categoria($term) {
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="_id_categoria_magento">ID Categoria Magento</label></th>
<td>
<input type="text" name="_id_categoria_magento" id="_id_categoria_magento" value="<?php echo get_term_meta($term->term_id, '_id_categoria_magento', true ); ?>">
<p class="description">Inserisci qui l'ID Categoria Magento.</p>
</td>
</tr>
<?php
}
// Salva il valore del campo personalizzato quando si modifica la categoria
add_action('edited_product_cat', 'salva_campo_personalizzato_categoria');
function salva_campo_personalizzato_categoria($term_id) {
if (isset($_POST['_id_categoria_magento'])) {
update_term_meta($term_id, '_id_categoria_magento', sanitize_text_field($_POST['_id_categoria_magento']));
}
}
// Aggiungi il campo personalizzato al form di modifica della categoria
add_action('product_cat_edit_form_fields', 'aggiungi_campo_personalizzato_categoria_woocommerce');
function aggiungi_campo_personalizzato_categoria_woocommerce($term) {
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="_id_categoria_woocommerce">ID Categoria WooCommerce</label></th>
<td>
<input type="text" name="_id_categoria_woocommerce" id="_id_categoria_woocommerce" value="<?php echo get_term_meta($term->term_id, '_id_categoria_woocommerce', true ); ?>">
<p class="description">Inserisci qui l'ID Categoria WooCommerce.</p>
</td>
</tr>
<?php
}
// Salva il valore del campo personalizzato quando si modifica la categoria
add_action('edited_product_cat', 'salva_campo_personalizzato_categoria_woocommerce');
function salva_campo_personalizzato_categoria_woocommerce($term_id) {
if (isset($_POST['_id_categoria_woocommerce'])) {
update_term_meta($term_id, '_id_categoria_woocommerce', sanitize_text_field($_POST['_id_categoria_woocommerce']));
}
}
CREATE TABLE `magento_export_beta` (
`id_prodotto` varchar(255) DEFAULT NULL,
`nome_prodotto` varchar(255) DEFAULT NULL,
`slug_prodotto` varchar(255) DEFAULT NULL,
`MAGENTO_ID` varchar(20) DEFAULT NULL,
`Autori` longtext,
`Indice` text,
`pa_has_cd` varchar(255) DEFAULT NULL,
`pa_has_gift` varchar(255) DEFAULT NULL,
`Estensioni_Web` text,
`Autore` varchar(255) DEFAULT NULL,
`Isbn` varchar(50) DEFAULT NULL,
`pa_is_ebook` varchar(255) DEFAULT NULL,
`pa_edizione` varchar(50) DEFAULT NULL,
`Numero_pagine` varchar(255) DEFAULT NULL,
`pa_stampa` varchar(50) DEFAULT NULL,
`pa_is_novita` varchar(255) DEFAULT NULL,
`pa_sfoglia_volume` varchar(255) DEFAULT NULL,
`pa_is_disponible` varchar(255) DEFAULT NULL,
`pa_is_prenotabile` varchar(255) DEFAULT NULL,
`Ricerca_Ebook` text,
`pa_has_software` varchar(255) DEFAULT NULL,
`Sottotitolo` varchar(255) DEFAULT NULL,
`pa_manuale_compet_sost_anief` varchar(255) DEFAULT NULL,
`pa_eb_eserc_sost_anief` varchar(255) DEFAULT NULL,
`pa_in_evidenza` varchar(255) DEFAULT NULL,
`pa_nopromo` varchar(255) DEFAULT NULL,
`pa_coupon` varchar(255) DEFAULT NULL,
`pa_promo20_facebook` varchar(255) DEFAULT NULL,
`pa_is_vst_ebook` varchar(255) DEFAULT NULL,
`pa_maestrena` varchar(255) DEFAULT NULL,
`pa_ripamcoesione` varchar(255) DEFAULT NULL,
`pa_agenziaentratefb` varchar(255) DEFAULT NULL,
`pa_man40` varchar(255) DEFAULT NULL,
`pa_specializzazionimediche` varchar(255) DEFAULT NULL,
`pa_collanads` varchar(255) DEFAULT NULL,
`pa_prometheus` varchar(255) DEFAULT NULL,
`pa_ammissioni` varchar(255) DEFAULT NULL,
`pa_feedlibrerie` varchar(255) DEFAULT NULL,
`pa_itastranieri` varchar(255) DEFAULT NULL,
`pa_mibact` varchar(255) DEFAULT NULL,
`pa_formato` varchar(50) DEFAULT NULL,
`pa_scontostanfield` varchar(255) DEFAULT NULL,
`pa_scontovigili` varchar(255) DEFAULT NULL,
`pa_in_ebook_search` varchar(255) DEFAULT NULL,
`pa_has_vst_ppe_ebook` varchar(255) DEFAULT NULL,
`pa_affiliati_infermieri` varchar(255) DEFAULT NULL,
`pa_profsanitarielavoro` varchar(255) DEFAULT NULL,
`pa_infante` varchar(255) DEFAULT NULL,
`pa_omaggioebook` varchar(255) DEFAULT NULL,
`pa_kitinfante` varchar(255) DEFAULT NULL,
`pa_specmedichevito` varchar(255) DEFAULT NULL,
`pa_cgiltorino` varchar(255) DEFAULT NULL,
`pa_medprofammissioni` varchar(255) DEFAULT NULL,
`pa_sconto_aprile_2020` varchar(255) DEFAULT NULL,
`pa_concorsocattedra100sconto` varchar(255) DEFAULT NULL,
`pa_verdolina` varchar(255) DEFAULT NULL,
`pa_codiceds` varchar(255) DEFAULT NULL,
`pa_sibioc` varchar(255) DEFAULT NULL,
`pa_escludi_pdf_catalogo` varchar(255) DEFAULT NULL,
`pa_scontodisal` varchar(255) DEFAULT NULL,
`pa_disalsingoli` varchar(255) DEFAULT NULL,
`pa_is_edigita_ebook` varchar(255) DEFAULT NULL,
`pa_is_edigita_ebook_ppe` varchar(255) DEFAULT NULL,
`Errata_Corrige` text,
`pa_url_sistema_verifica` varchar(255) DEFAULT NULL,
`pa_vst_ppe_resource_id_prefix` varchar(255) DEFAULT NULL,
`lista_sotto_img` text,
`URL_ebook` text,
`ID_Prodotto_nuova_versione` varchar(255) DEFAULT NULL,
`Data_disponibilita` varchar(255) DEFAULT NULL,
`Codice_Prodotto` varchar(50) DEFAULT NULL,
`VST_resource_id_VBID` varchar(255) DEFAULT NULL,
`Tag` text,
`URL_cartaceo` text,
`pa_acs_resource_id` varchar(255) DEFAULT NULL,
`pa_lingua` varchar(50) DEFAULT NULL,
`pa_versione` varchar(50) DEFAULT NULL,
`pa_apple_store` varchar(255) DEFAULT NULL,
`Brevi_Info` text,
`pa_dispositivi_supportati` text,
`Specifiche` text,
`Struttura` text,
`pa_demo` varchar(255) DEFAULT NULL,
`pa_docebo_info` text,
`pa_elearning` varchar(255) DEFAULT NULL,
`pa_docebo_course` text,
`Descrizione_per_widget` text,
`Country_of_Manufacture` varchar(255) DEFAULT NULL,
`Edizione` varchar(255) DEFAULT NULL,
`id_riferimento_Edigita` varchar(255) DEFAULT NULL,
`pa_market_android` varchar(255) DEFAULT NULL,
`pa_printable_book_cover_url` text,
`pa_edigita_ppe_resource_id` varchar(255) DEFAULT NULL,
`pa_cost` varchar(255) DEFAULT NULL,
`sottotitolo2` varchar(255) DEFAULT NULL,
`isbn2` varchar(50) DEFAULT NULL,
`numero_pagine2` varchar(255) DEFAULT NULL,
`tag2` text,
`codice_prodotto2` varchar(50) DEFAULT NULL,
`ricerca_ebook2` text,
`pa_simulazione_studenti` varchar(255) DEFAULT NULL,
`Formato` varchar(50) DEFAULT NULL,
`pa_ean` varchar(50) DEFAULT NULL,
`Relatori` text,
`pa_demo_link` varchar(255) DEFAULT NULL,
`pa_featured` varchar(255) DEFAULT NULL,
`pa_nome_landing` varchar(255) DEFAULT NULL,
`pa_course_plans` text,
`Programma` text,
`product_cat` varchar(255) DEFAULT NULL,
`product_type` varchar(255) DEFAULT NULL,
`product_visibility` varchar(255) DEFAULT NULL,
`product_tag` text,
PRIMARY KEY (`id_prodotto`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Dopo aver importato il csv estratto, va aggiornata la tabella aggiungendo i campi mancanti
ALTER TABLE magento_export_beta
ADD COLUMN `contiene_ebook` varchar(100) NOT NULL AFTER `MAGENTO_ID`,
ADD COLUMN `isbn_ebook` varchar(100) NOT NULL AFTER `contiene_ebook`,
ADD COLUMN `contiene_cartaceo` varchar(100) NOT NULL AFTER `isbn_ebook`,
ADD COLUMN `isbn_cartaceo` longtext NOT NULL AFTER `contiene_cartaceo`,
ADD COLUMN `volume_kit` longtext NOT NULL AFTER `isbn_cartaceo`,
ADD COLUMN `isbn_volume_kit` longtext NOT NULL AFTER `volume_kit`,
ADD COLUMN `serialized_isbn_kit` longtext NOT NULL AFTER `isbn_volume_kit`;
Prima di mettere mano alla tabella definitiva creiamo una di test
CREATE TABLE magento_export_beta_2
SELECT * FROM magento_export_beta
Isoliamo i prodotti già presenti nel database finale rispetto a quelli nell’ambiente di sviluppo, lo facciamo andando ad esportare i valori ISBN e creando due tabelle definite:
CREATE TABLE `prodotti_destinazione` (
`SKU` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `prodotti_origine` (
`SKU` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
-- da tabella magento_export_beta prendiamo la lista di isbn che caricheremo nella tabella prodotti_origine
SELECT Isbn from magento_export_beta
-- preleviamo anche i prodotti attualmente disponibili su woocommerce
SELECT pm.meta_value AS ISBN
FROM wpcv_postmeta pm
JOIN wpcv_posts p ON pm.post_id = p.ID
WHERE pm.meta_key = 'isbn'
AND p.post_type = 'product'
AND pm.meta_value IS NOT NULL
AND pm.meta_value != '';
-- a questo punto compariamo i risultati ottenuti, la lista di ISBN estratta equivale ai prodotti non ancora presenti
SELECT p1.SKU
FROM prodotti_origine p1
LEFT JOIN prodotti_destinazione p2 ON p1.SKU = p2.SKU
WHERE p2.SKU IS NULL
AND p1.SKU IS NOT NULL
AND p1.SKU != '';
-- creiamo una nuova tabella temporanea dove andiamo a prendere tutti i prodotti nuovi
INSERT INTO nuovi_prodotti (SKU)
SELECT p1.SKU
FROM prodotti_origine p1
LEFT JOIN prodotti_destinazione p2 ON p1.SKU = p2.SKU
WHERE p2.SKU IS NULL
AND p1.SKU IS NOT NULL
AND p1.SKU != '';
-- lavoriamo solo sui nuovi prodotti e lasciamo il mondo come sta
CREATE TABLE magento_export_new
SELECT * FROM magento_export_beta_2 where Isbn IN (Select * from nuovi_prodotti);
Si esegue l’import di prodotti e categorie, per farlo correttamente bisogna esportare come Migrate Prodotti (nel caso possiamo affinare, ma resta il nodo delle categorie prodotti che vengono cambiate a pioggia)
Contiene eBook
campo tabella URL_ebook se è pieno, il valore del campo contiene_ebook deve essere settato su yes
UPDATE magento_export_beta
SET contiene_ebook = CASE WHEN URL_ebook IS NOT NULL AND URL_ebook != '' THEN 'yes' ELSE contiene_ebook END;
ISBN eBook
Logica e script creati sul file http://script/isbn_ebook.php
Script successivo: /ebook-fix.php
Script successivo: /ebook-postmeta-fix.php
Contiene Cartaceo
si utilizza la stessa identica logica utilizzata per “contiene ebook”
UPDATE magento_export_beta
SET contiene_cartaceo = CASE WHEN URL_cartaceo IS NOT NULL AND URL_cartaceo != '' THEN 'yes' ELSE contiene_cartaceo END;
ISBN cartaceo
Logica e script creati sul file http://script/isbn_cartaceo.php
Volume Kit
UPDATE magento_export_beta
SET volume_kit = 'yes'
WHERE nome_prodotto LIKE '%kit%';
ISBN Volume Kit
eseguire lo scritp in /tool/volumi_kit_update.php. Ricordarsi di esportare la tabella aggiornata catalog_product_bundle_selection dal database Magento
-- creo una tabella con dentro tutti i dati solo dei nuovi prodotti
CREATE TABLE nuovi_prodotti_dati AS
SELECT magento.*
FROM magento_export_beta AS magento
INNER JOIN nuovi_prodotti AS nuovi ON magento.Isbn = nuovi.SKU;
Devo poi esportale le tabelle magento_export_beta e nuovi_prodotti verso il database definitivo
uso questa query per fare il match tra isbn della tabella magento con tutti i valori esportati e aggiornare il campo id_prodotto con il post_id di woocommerce
UPDATE magento_export_beta_2 AS m
JOIN wpcv_postmeta AS n ON m.Isbn = n.meta_value AND n.meta_key = 'isbn'
SET m.id_prodotto = n.post_id;
-- nel caso serva aggiornare gli id prodotto woocommerce rispetto a quelli attuali
UPDATE magento_export_new AS m
JOIN wpcv_postmeta AS w ON m.Isbn = w.meta_value
SET m.id_prodotto = w.post_id
WHERE w.meta_key = '_sku';
6. serialized_isbn_kit => script preposto
-- estrae in una tabella il corrispondente ID categoria Magento (funzionalità Legacy)
SELECT tm.meta_value AS ID_CAT_MAGENTO,
tm.term_id AS ID_CAT_WOOCOMMERCE,
t.name AS NOME,
t.slug AS SLUG
FROM wpcv_termmeta as tm
JOIN wpcv_terms as t ON tm.term_id = t.term_id
WHERE tm.meta_key = '_id_categoria_magento';
Si esegue l’import di prodotti e categorie, per farlo correttamente bisogna esportare come Migrate Prodotti (nel caso possiamo affinare, ma resta il nodo delle categorie prodotti che vengono cambiate a pioggia)
Il nodo primario resta quello di sistemare solo i prodotti con differenze sostanziali per gli attributi extra, ad esempio: copertina, pagine, kit etc etc. Esistono già script che si occupano di sistemare tutti i dettagli, ma vengono fatti su tutti i prodotti, non vorrei andare ad intaccare quelli già sistemati, vanno rivisti tutti gli script.
-- questa pontentissima query estrae tutti i prodotti e relative categorie da magento
SELECT
cpe.entity_id AS 'Product_ID',
cpev.value AS 'Product_Name',
GROUP_CONCAT(DISTINCT ccv.value) AS 'Category_Names',
GROUP_CONCAT(DISTINCT ccp.category_id) AS 'Category_IDs',
MAX(ur.request_path) AS 'Product_URL'
FROM
catalog_product_entity AS cpe
JOIN
catalog_product_entity_varchar AS cpev ON cpe.entity_id = cpev.entity_id AND cpev.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_product'))
LEFT JOIN
catalog_category_product AS ccp ON cpe.entity_id = ccp.product_id
LEFT JOIN
catalog_category_entity_varchar AS ccv ON ccp.category_id = ccv.entity_id AND ccv.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_category'))
LEFT JOIN
url_rewrite AS ur ON ur.entity_id = cpe.entity_id AND ur.entity_type = 'product' AND ur.redirect_type = 0 AND ur.store_id = 1
GROUP BY
cpe.entity_id, cpev.value;
-- Creazione della nuova tabella per i risultati, accoppiamo le categorie magento a quelle woocommerce
CREATE TABLE `cat-magento-woocommerce` (
category_id INT,
category_name VARCHAR(255),
magento_category_id INT
);
-- Inserimento dei risultati della query nella nuova tabella
INSERT INTO `cat-magento-woocommerce` (category_id, category_name, magento_category_id)
SELECT t.term_id AS category_id, t.name AS category_name, meta.meta_value AS magento_category_id
FROM wpcv_terms t
INNER JOIN wpcv_term_taxonomy tt ON t.term_id = tt.term_id
LEFT JOIN wpcv_termmeta meta ON t.term_id = meta.term_id AND meta.meta_key = '_id_categoria_magento'
WHERE tt.taxonomy = 'product_cat';
script per far combaciare prodotti e categorie: /cat_magento_woo.php
<?php
// Registra il tempo all'inizio dello script
$time_start = microtime(true);
$servername = "localhost";
$username = "yqmkgwhd_fabios";
$password = "persolino83";
$dbname = "yqmkgwhd_eddef";
$record_count = 0;
$association_count = 0;
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connessione fallita: " . $conn->connect_error);
}
// Query per recuperare i post_id presenti nella tabella cat-prod-magento
$post_ids_query = "SELECT DISTINCT post_id FROM wpcv_postmeta WHERE meta_key = '_magento_id'";
$post_ids_result = $conn->query($post_ids_query);
if ($post_ids_result->num_rows > 0) {
$post_ids = [];
while ($row = $post_ids_result->fetch_assoc()) {
$post_ids[] = $row['post_id'];
}
$post_ids_string = implode(',', $post_ids);
// Query per eliminare i legami relativi ai post_id presenti nella tabella cat-prod-magento
$delete_existing_query = "DELETE FROM wpcv_term_relationships WHERE object_id IN ($post_ids_string)";
$conn->query($delete_existing_query);
echo "Legami esistenti cancellati per i post_id presenti nella tabella cat-prod-magento<br>";
} else {
echo "Nessun post_id trovato nella tabella cat-prod-magento<br>";
}
// Query per recuperare i dati dalla tabella cat-prod-magento
$sql = "SELECT ID_Magento, Category_ID FROM `cat-prod-magento`";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$product_id_query = "SELECT post_id FROM wpcv_postmeta WHERE meta_key = '_magento_id' AND meta_value = '{$row['ID_Magento']}'";
$product_id_result = $conn->query($product_id_query);
if ($product_id_result->num_rows > 0) {
$product_id_row = $product_id_result->fetch_assoc();
$product_id = $product_id_row['post_id'];
$category_ids = explode(',', $row['Category_ID']);
foreach ($category_ids as $category_id) {
$query = "SELECT woocommerce_cat FROM `cat-magento-woocommerce` WHERE magento_cat = '$category_id'";
$woocommerce_result = $conn->query($query);
if ($woocommerce_result->num_rows > 0) {
$woocommerce_row = $woocommerce_result->fetch_assoc();
$woocommerce_category_id = $woocommerce_row['woocommerce_cat'];
$check_query = "SELECT 1 FROM wpcv_term_relationships WHERE object_id = '$product_id' AND term_taxonomy_id = '$woocommerce_category_id'";
$check_result = $conn->query($check_query);
if ($check_result->num_rows == 0) {
$insert_query = "INSERT INTO wpcv_term_relationships (object_id, term_taxonomy_id) VALUES ('$product_id', '$woocommerce_category_id')";
$conn->query($insert_query);
echo "Prodotto $product_id associato con successo alla categoria WooCommerce $woocommerce_category_id<br>";
$association_count++;
} else {
echo "Relazione già esistente tra prodotto $product_id e categoria WooCommerce $woocommerce_category_id, non inserita per evitare duplicati<br>";
}
} else {
echo "Nessuna corrispondenza trovata per il Magento category ID: $category_id<br>";
}
}
} else {
echo "Nessun post_id trovato per Magento ID: {$row['ID_Magento']}<br>";
}
$record_count++;
}
} else {
echo "0 risultati";
}
$conn->close();
// Registra il tempo alla fine dello script
$time_end = microtime(true);
$execution_time = ($time_end - $time_start);
$execution_minutes = floor($execution_time / 60);
$execution_seconds = round($execution_time % 60, 2);
echo "Numero totale di record processati: $record_count<br>";
echo "Numero di associazioni create con successo: $association_count<br>";
echo "Tempo totale di esecuzione dello script: $execution_minutes minuti e $execution_seconds secondi";
?>
-- categorie disabilitate su magento
SELECT entity_id
FROM catalog_category_entity
WHERE entity_id NOT IN (
SELECT entity_id
FROM catalog_category_entity_int
WHERE attribute_id = (
SELECT attribute_id
FROM eav_attribute
WHERE attribute_code = 'is_active'
AND entity_type_id = (
SELECT entity_type_id
FROM eav_entity_type
WHERE entity_type_code = 'catalog_category'
)
)
AND value = 1
);
CSV Attributi completi
<?php
// Connessione al database WooCommerce
$servername = "localhost";
$username = "fabio";
$password = "aaa";
$dbname = "ed_imp";
$conn = new mysqli($servername, $username, $password, $dbname);
// Verifica della connessione
if ($conn->connect_error) {
die("Connessione fallita: " . $conn->connect_error);
}
function rimuoviAccenti($stringa) {
$mappatura = array(
'à' => 'a', 'è' => 'e', 'ì' => 'i', 'ò' => 'o', 'ù' => 'u',
'À' => 'A', 'È' => 'E', 'Ì' => 'I', 'Ò' => 'O', 'Ù' => 'U',
'á' => 'a', 'é' => 'e', 'í' => 'i', 'ó' => 'o', 'ú' => 'u',
'Á' => 'A', 'É' => 'E', 'Í' => 'I', 'Ó' => 'O', 'Ú' => 'U',
// Aggiungi altre mappature se necessario
);
return strtr($stringa, $mappatura);
}
// Normalizza i nomi delle colonne per risolvere i duplicati
function normalizzaNomeColonna($nome) {
$nome = str_replace([' ', '-'], '_', $nome);
$nome = rimuoviAccenti($nome);
// Rinomina le colonne duplicate
switch ($nome) {
case 'numero_pagine':
return 'numero_pagine2';
case 'isbn':
return 'isbn2';
case 'sottotitolo':
return 'sottotitolo2';
case 'tag':
return 'tag2';
case 'codice_prodotto':
return 'codice_prodotto2';
case 'ricerca_ebook':
return 'ricerca_ebook2';
default:
return $nome;
}
}
// Modifica della prima query per includere sku_woocommerce_magento e MAGENTO_ID
$sql = "SELECT
p.ID as id_prodotto,
p.post_title as nome_prodotto,
p.post_name as slug_prodotto,
pm.meta_value as attributi_serializzati,
sku_meta.meta_value as sku_woocommerce_magento,
cpe.entity_id as MAGENTO_ID
FROM
ed2024_posts p
JOIN
ed2024_postmeta pm ON p.ID = pm.post_id
LEFT JOIN
ed2024_postmeta sku_meta ON p.ID = sku_meta.post_id AND sku_meta.meta_key = '_sku'
LEFT JOIN
catalog_product_entity cpe ON sku_meta.meta_value = cpe.sku
WHERE
p.post_type = 'product' AND pm.meta_key = '_product_attributes'";
$result = $conn->query($sql);
// Inizializza un array per tenere traccia di tutti i nomi degli attributi
$attributi_header = array('id_prodotto', 'nome_prodotto', 'slug_prodotto', 'MAGENTO_ID');
$attributi_rows = array();
// Elabora i risultati della prima query e costruisci l'array degli attributi
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$attributi = unserialize($row['attributi_serializzati']);
$attributi_row = array(
'id_prodotto' => $row['id_prodotto'],
'nome_prodotto' => $row['nome_prodotto'],
'slug_prodotto' => $row['slug_prodotto'],
'MAGENTO_ID' => $row['MAGENTO_ID'] ?? ''
);
foreach ($attributi as $nome_attributo => $dettagli_attributo) {
$nome_attributo = normalizzaNomeColonna($nome_attributo);
if (!in_array($nome_attributo, $attributi_header)) {
$attributi_header[] = $nome_attributo;
}
$attributi_row[$nome_attributo] = $dettagli_attributo['value'] ?? $dettagli_attributo['name'] ?? '';
}
$attributi_rows[$row['id_prodotto']] = $attributi_row;
}
} else {
echo "Nessun risultato trovato per la prima query";
}
// Seconda query per ottenere informazioni aggiuntive
$sql2 = "SELECT
t.name AS attribute_name,
tt.taxonomy AS attribute_taxonomy,
tr.object_id AS product_id,
p.post_title AS product_name,
p.post_name as slug_prodotto
FROM
ed2024_terms t
JOIN
ed2024_term_taxonomy tt ON t.term_id = tt.term_id
JOIN
ed2024_term_relationships tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
JOIN
ed2024_posts p ON tr.object_id = p.ID
WHERE
p.post_type = 'product'
ORDER BY
p.ID, tt.taxonomy;";
$result2 = $conn->query($sql2);
// Elabora i risultati della seconda query
if ($result2->num_rows > 0) {
while($row2 = $result2->fetch_assoc()) {
$product_id = $row2['product_id'];
$attribute_taxonomy = $row2['attribute_taxonomy'];
$attribute_name = $row2['attribute_name'];
// Aggiungi il nuovo header se non esiste
if (!in_array($attribute_taxonomy, $attributi_header)) {
$attributi_header[] = $attribute_taxonomy;
}
// Assicurati che l'array per questo prodotto esista
if (!isset($attributi_rows[$product_id])) {
$attributi_rows[$product_id] = array(
'id_prodotto' => $product_id,
'nome_prodotto' => $row2['product_name'],
'slug_prodotto' => $row2['slug_prodotto']
);
}
// Aggiorna l'array dei dati del prodotto
$attributi_rows[$product_id][$attribute_taxonomy] = $attribute_name;
}
} else {
echo "Nessun risultato trovato per la seconda query";
}
// Creazione del file CSV
$csvFileName = 'export-semi-pro-magento-id.csv';
$csvFile = fopen($csvFileName, 'w');
// Scrivi l'intestazione nel file CSV
fputcsv($csvFile, $attributi_header);
// Scrivi i valori degli attributi nel file CSV
foreach ($attributi_rows as $product_id => $attributi_row) {
$csvRow = array();
foreach ($attributi_header as $header) {
$csvRow[] = $attributi_row[$header] ?? '';
}
fputcsv($csvFile, $csvRow);
}
// Chiudi la connessione al database e il file CSV
$conn->close();
fclose($csvFile);
echo "File CSV creato con successo: " . $csvFileName;
/*
// Prepara la query di inserimento
$columns = implode(', ', array_map(function($col) { return '`' . $col . '`'; }, $attributi_header));
$placeholders = implode(', ', array_fill(0, count($attributi_header), '?'));
$insertQuery = "INSERT INTO export_table ($columns) VALUES ($placeholders)";
$stmt = $conn->prepare($insertQuery);
if (!$stmt) {
die("Errore nella preparazione della query: " . $conn->error);
}
// Divide $attributi_rows in lotti da 50 record
$lotti = array_chunk($attributi_rows, 50);
foreach ($lotti as $lotto) {
foreach ($lotto as $attributi_row) {
// Converti tutti i valori dell'array in stringa
$values = array_map('strval', array_values($attributi_row));
// Crea un array di tipi (tutti 's' per stringa)
$types = str_repeat('s', count($values));
// Lega i parametri alla query
$stmt->bind_param($types, ...$values);
// Esegui la query
if (!$stmt->execute()) {
echo "Errore durante l'inserimento dei dati: " . $stmt->error;
}
}
}
echo "Inserimento dei dati nella tabella riuscito con successo.";
// Chiudi lo statement e la connessione al database
//$stmt->close();
*/
//$conn->close();
?>
EdiSES – Mappatura Database
SELECT ea.attribute_code, ea.backend_type,
CASE ea.backend_type
WHEN 'varchar' THEN ce_varchar.value
WHEN 'int' THEN ce_int.value
WHEN 'decimal' THEN ce_decimal.value
WHEN 'datetime' THEN ce_datetime.value
WHEN 'text' THEN ce_text.value
ELSE 'Unsupported type'
END as value
FROM eav_attribute ea
LEFT JOIN catalog_product_entity_varchar ce_varchar ON ea.attribute_id = ce_varchar.attribute_id AND ce_varchar.entity_id = '4905'
LEFT JOIN catalog_product_entity_int ce_int ON ea.attribute_id = ce_int.attribute_id AND ce_int.entity_id = '4905'
LEFT JOIN catalog_product_entity_decimal ce_decimal ON ea.attribute_id = ce_decimal.attribute_id AND ce_decimal.entity_id = '4905'
LEFT JOIN catalog_product_entity_datetime ce_datetime ON ea.attribute_id = ce_datetime.attribute_id AND ce_datetime.entity_id = '4905'
LEFT JOIN catalog_product_entity_text ce_text ON ea.attribute_id = ce_text.attribute_id AND ce_text.entity_id = '4905'
WHERE ea.entity_type_id = '4';
La query che hai fornito interroga diverse tabelle per recuperare gli attributi e i loro valori per un dato prodotto in Magento. Ecco le tabelle coinvolte in questa query e una breve descrizione del loro scopo:
eav_attribute:
Questa tabella contiene informazioni sugli attributi, come l’ID dell’attributo (attribute_id), il codice dell’attributo (attribute_code), e il tipo di backend (backend_type) che indica il tipo di dato dell’attributo (varchar, int, decimal, datetime, text).
catalog_product_entity_varchar:
Questa tabella memorizza i valori degli attributi di tipo ‘varchar’ (stringhe di testo breve) per i prodotti. Viene associata alla tabella eav_attribute tramite attribute_id per ottenere i valori degli attributi di tipo varchar.
catalog_product_entity_int:
Questa tabella memorizza i valori degli attributi di tipo ‘int’ (numeri interi) per i prodotti. Come la tabella catalog_product_entity_varchar, viene associata alla tabella eav_attribute per ottenere i valori degli attributi di tipo intero.
catalog_product_entity_decimal:
Questa tabella è utilizzata per memorizzare i valori degli attributi di tipo ‘decimal’ (numeri decimali) per i prodotti. È associata a eav_attribute per ottenere i valori degli attributi di tipo decimale.
catalog_product_entity_datetime:
Questa tabella memorizza i valori degli attributi di tipo ‘datetime’ (data e ora) per i prodotti. Viene associata a eav_attribute per ottenere i valori degli attributi di tipo datetime.
catalog_product_entity_text:
Questa tabella è utilizzata per memorizzare i valori degli attributi di tipo ‘text’ (stringhe di testo lunghe) per i prodotti. Viene associata a eav_attribute per ottenere i valori degli attributi di tipo testo.
In questa query, la tabella eav_attribute viene utilizzata come tabella principale da cui vengono estratti i codici degli attributi e i tipi di backend. Le altre tabelle (catalog_product_entity_varchar, catalog_product_entity_int, catalog_product_entity_decimal, catalog_product_entity_datetime, catalog_product_entity_text) vengono poi associate a eav_attribute per recuperare i valori specifici degli attributi per un dato prodotto, identificato dall’entity_id (‘4905’ in questo caso) e filtrati per tipo di entità (entity_type_id = ‘4’, tipicamente per i prodotti).
catalog_product_entity
catalog_product_entity_varchar
entity_id ==> CHIAVE PRIMARIA
SELECT
entity.entity_id,
entity.sku,
varchar_table.attribute_id,
varchar_table.value AS attribute_value,
attribute.attribute_code AS attribute_name
FROM
catalog_product_entity AS entity
INNER JOIN
catalog_product_entity_varchar AS varchar_table ON entity.entity_id = varchar_table.entity_id
LEFT JOIN
eav_attribute AS attribute ON varchar_table.attribute_id = attribute.attribute_id
WHERE
entity.entity_id = 5305
tabella eav_attribute
Ci sono dentro tutte le label utili nella colonna attribute_code, fanno tutti riferimento al valore della colonna attribute_id
tabella catalog_product_entity_text
ulteriori informazioni prodotto: chiavi entity_id, attribute_id (recuperabile valore da eav_attribute)
tabella catalog_product_entity_varchar
tabella eav_attribute_option_value
copertina flessibile: option_id = 8
copertina rigida: option_id = 9
B/N: option_id = 4 ==> attribute_name = stampa
4 colori = option_id = 3
ebook = option_id = 10
lingua italiano = option_id = 7
lingua inglese = option_id = 6
SELECT
text_table.entity_id AS ID_PRODOTTO,
attribute.attribute_code,
text_table.value AS text_attribute_value
FROM
eav_attribute AS attribute
LEFT JOIN
catalog_product_entity_text AS text_table
ON attribute.attribute_id = text_table.attribute_id
WHERE
text_table.entity_id = 5305
La query estrae:
description
short_description
meta_keyword
indice
risorse
tagricerca (skip)
ebook_name
Prodotti Abilitati o disabilitati
SELECT
entity_id
FROM
catalog_product_entity
WHERE
entity_id IN (
SELECT entity_id
FROM catalog_product_entity_int
WHERE attribute_id = (
SELECT attribute_id
FROM eav_attribute
WHERE attribute_code = 'status'
)
AND value != 1 -- Valore che indica lo stato "Abilitato"
# AND value = 1 -- abilitato
)
SELECT
entity.entity_id AS ID_PRODOTTO,
entity.sku AS ISBN,
IFNULL(stock_table.value, 0) AS ABILITATO,
visibility_table.value AS VISIBILITA
FROM
catalog_product_entity AS entity
LEFT JOIN
catalog_product_entity_int AS stock_table
ON entity.entity_id = stock_table.entity_id
AND stock_table.attribute_id = (
SELECT attribute_id
FROM eav_attribute
WHERE attribute_code = 'status'
)
LEFT JOIN
catalog_product_entity_int AS visibility_table
ON entity.entity_id = visibility_table.entity_id
AND visibility_table.attribute_id = (
SELECT attribute_id
FROM eav_attribute
WHERE attribute_code = 'visibility'
)
WHERE
entity.entity_id IN (4693,1608,4694,1606,1610,4692)
VIBILITÀ VALORI:
1: non visibile
2: catalogo
3: ricerca
4: catalogo e ricerca
ABILITATO VALORI:
1: abilitato
2: disabilitato
Plugin Area Riservata
<?php
/**
* Plugin Name: Notifica Area Riservata
* Plugin URI: https://www.digitalfollowers.com
* Description: Invia i dettagli dell'acquisto a un sistema esterno dopo il completamento dell'ordine in WooCommerce.
* Version: 1.0.2
* Author: Staff - Digital Followers
* Author URI: https://www.digitalfollowers.com
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
add_action('woocommerce_payment_complete', 'notify_purchase_to_external_api');
function notify_purchase_to_external_api($order_id) {
$order = wc_get_order($order_id);
$products_data = [];
foreach ($order->get_items() as $item_id => $item) {
$product = $item->get_product();
$magentoBookId = $product->get_id();
$enableResources = get_post_meta($product->get_id(), 'enableResources', true);
$products_data[] = [
'magentoBookId' => $magentoBookId,
'enableResources' => filter_var($enableResources, FILTER_VALIDATE_BOOLEAN)
];
}
$payload_details = [
'customerId' => $order->get_user_id(),
'customerEmail' => $order->get_billing_email(),
'orderId' => $order->get_id(),
'products' => $products_data
];
$header = json_encode(['typ' => 'JWT', 'alg' => 'HS512']);
$payload = base64_encode(json_encode($payload_details));
$signature = hash_hmac('sha512', $header . "." . $payload, 'your_secret_key', true);
$jwt = base64_encode($header) . "." . base64_encode($payload) . "." . base64_encode($signature);
$ch = curl_init('https://areariservataedises.meetweb.dev/api/notify-purchased-products');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['data' => $jwt]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
]);
$response = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if ($error) {
// Handle error, maybe log it
error_log('Curl error: ' . $error);
} else {
$response_data = json_decode($response, true);
if (isset($response_data['error']) && $response_data['error']) {
// Handle API error, maybe log it
error_log('API error: ' . $response_data['error']);
} else {
// Handle successful response
// ...
}
}
}
?>