Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions assets/css/admin/facebook-for-woocommerce-products-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
border-bottom: 1px solid #eee;
}

#facebook_options .google_product_catgory {
border-top: 1px solid #eee;
}

.woocommerce_variable_attributes .wp-editor-wrap label {
float: left;
Expand Down Expand Up @@ -165,4 +168,112 @@
.wp-editor-wrap {
width: 100%;
max-width: 100%;
}

.facebook-metabox {
overflow: hidden;
clear: both;
border: 1px solid #ddd;
margin: 16px 0 !important;
background: #fff;
padding: 0 !important; /* Remove the previous padding */
border-bottom: 1px solid #eee !important;
}
.facebook-metabox h3 {
margin: 0 !important;
font-size: 1em !important;
padding: 0.5em 0.75em 0.5em 1em !important;
cursor: pointer;
border-bottom: 1px solid #ddd;
}
.facebook-metabox.closed .handlediv:before {
content: "\f140" !important;
}
.facebook-metabox .handlediv:before {
content: "\f142" !important;
font: normal 20px/1 dashicons;
}
.facebook-metabox .wc-metabox-content {
padding: 1em;
background: #fff;
}
.facebook-metabox h3 strong {
line-height: 26px;
font-weight: 600;
}

.sync-indicator .sync-tooltip {
display: none;
position: absolute;
background: #32373c;
padding: 8px;
border-radius: 3px;
color: #fff;
font-size: 11px;
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
line-height: 1.4;
white-space: nowrap;
z-index: 9999;
top: 100%;
left: 50%;
transform: translateX(-50%) translateY(8px);
}

.sync-indicator .sync-tooltip:before {
content: '';
position: absolute;
border: 6px solid transparent;
border-bottom-color: #32373c;
top: -12px;
left: 50%;
transform: translateX(-50%);
}

.sync-indicator:hover .sync-tooltip {
display: block;
}

.synced-attribute {
background-color: #f0f0f1 !important;
cursor: not-allowed;
}

.sync-indicator .sync-tooltip:before {
content: '';
position: absolute;
border: 6px solid transparent;
border-bottom-color: #32373c;
top: -12px;
left: 50%;
transform: translateX(-50%);
}

.sync-indicator:hover .sync-tooltip {
display: block;
}

.wc-attributes-icon {
display: inline-block;
margin-left: 8px;
cursor: help;
vertical-align: middle;
font-size: 14px;
position: relative;
line-height: 1;
top: 2px;
}

.wc-attributes-icon:before {
font-family: Dashicons;
content: "\f175";
}

.woocommerce_options_panel {
input[type="text"],
input[type="number"],
input[type="email"],
input[type="url"],
select {
font-size: 12px !important;
}
}
100 changes: 65 additions & 35 deletions facebook-commerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ class WC_Facebookcommerce_Integration extends WC_Integration {


// TODO probably some of these meta keys need to be moved to Facebook\Products {FN 2020-01-13}.
public const FB_PRODUCT_GROUP_ID = 'fb_product_group_id';
public const FB_PRODUCT_ITEM_ID = 'fb_product_item_id';
public const FB_PRODUCT_DESCRIPTION = 'fb_product_description';
public const FB_PRODUCT_GROUP_ID = 'fb_product_group_id';
public const FB_PRODUCT_ITEM_ID = 'fb_product_item_id';
public const FB_PRODUCT_DESCRIPTION = 'fb_product_description';
public const FB_RICH_TEXT_DESCRIPTION = 'fb_rich_text_description';
/** @var string the API flag to set a product as visible in the Facebook shop */
public const FB_SHOP_PRODUCT_VISIBLE = 'published';
Expand Down Expand Up @@ -728,7 +728,7 @@ public function load_assets() {
},
feed: {
totalVisibleProducts: '<?php echo esc_js( $this->get_product_count() ); ?>',
hasClientSideFeedUpload: '<?php echo esc_js( ! ! $this->get_feed_id() ); ?>',
hasClientSideFeedUpload: '<?php echo esc_js( (bool) $this->get_feed_id() ); ?>',
enabled: true,
format: 'csv'
},
Expand Down Expand Up @@ -820,20 +820,18 @@ public function on_product_save( int $wp_id ) {
}
$this->delete_fb_product( $delete_product );
}
} else {
if ( $sync_enabled ) {
} elseif ( $sync_enabled ) {
Products::enable_sync_for_products( [ $product ] );
Products::set_product_visibility( $product, Admin::SYNC_MODE_SYNC_AND_HIDE !== $sync_mode );
$this->save_product_settings( $product );
} else {
// if previously enabled, add a notice on the next page load
if ( Products::is_sync_enabled_for_product( $product ) ) {
Admin::add_product_disabled_sync_notice();
}
Products::disable_sync_for_products( [ $product ] );
if ( in_array( $wp_id, $products_to_delete_from_facebook, true ) ) {
$this->delete_fb_product( $product );
}
} else {
// if previously enabled, add a notice on the next page load
if ( Products::is_sync_enabled_for_product( $product ) ) {
Admin::add_product_disabled_sync_notice();
}
Products::disable_sync_for_products( [ $product ] );
if ( in_array( $wp_id, $products_to_delete_from_facebook, true ) ) {
$this->delete_fb_product( $product );
}
}
if ( $sync_enabled ) {
Expand All @@ -858,16 +856,58 @@ public function on_product_save( int $wp_id ) {
}

/**
* Saves the submitted Facebook settings for a variable product.
* Saves Facebook product attributes from POST data.
*
* @param WC_Facebook_Product $woo_product The Facebook product object
*/
private function save_facebook_product_attributes( $woo_product ) {
// phpcs:disable WordPress.Security.NonceVerification.Missing
if ( isset( $_POST[ WC_Facebook_Product::FB_BRAND ] ) ) {
$woo_product->set_fb_brand( sanitize_text_field( wp_unslash( $_POST[ WC_Facebook_Product::FB_BRAND ] ) ) );
}

if ( isset( $_POST[ WC_Facebook_Product::FB_MPN ] ) ) {
$woo_product->set_fb_mpn( sanitize_text_field( wp_unslash( $_POST[ WC_Facebook_Product::FB_MPN ] ) ) );
}

if ( isset( $_POST[ WC_Facebook_Product::FB_SIZE ] ) ) {
$woo_product->set_fb_size( sanitize_text_field( wp_unslash( $_POST[ WC_Facebook_Product::FB_SIZE ] ) ) );
}

if ( isset( $_POST[ WC_Facebook_Product::FB_COLOR ] ) ) {
$woo_product->set_fb_color( sanitize_text_field( wp_unslash( $_POST[ WC_Facebook_Product::FB_COLOR ] ) ) );
}

if ( isset( $_POST[ WC_Facebook_Product::FB_MATERIAL ] ) ) {
$woo_product->set_fb_material( sanitize_text_field( wp_unslash( $_POST[ WC_Facebook_Product::FB_MATERIAL ] ) ) );
}

if ( isset( $_POST[ WC_Facebook_Product::FB_PATTERN ] ) ) {
$woo_product->set_fb_pattern( sanitize_text_field( wp_unslash( $_POST[ WC_Facebook_Product::FB_PATTERN ] ) ) );
}

if ( isset( $_POST[ WC_Facebook_Product::FB_AGE_GROUP ] ) ) {
$woo_product->set_fb_age_group( sanitize_text_field( wp_unslash( $_POST[ WC_Facebook_Product::FB_AGE_GROUP ] ) ) );
}

if ( isset( $_POST[ WC_Facebook_Product::FB_GENDER ] ) ) {
$woo_product->set_fb_gender( sanitize_text_field( wp_unslash( $_POST[ WC_Facebook_Product::FB_GENDER ] ) ) );
}

if ( isset( $_POST[ WC_Facebook_Product::FB_PRODUCT_CONDITION ] ) ) {
$woo_product->set_fb_condition( sanitize_text_field( wp_unslash( $_POST[ WC_Facebook_Product::FB_PRODUCT_CONDITION ] ) ) );
}
// phpcs:enable WordPress.Security.NonceVerification.Missing
}

/**
* Saves the submitted Facebook settings for a variable product.
*
* @param \WC_Product $product The variable product object.
*/
private function save_variable_product_settings( WC_Product $product ) {
private function save_variable_product_settings( $product ) {
$woo_product = new WC_Facebook_Product( $product->get_id() );
if ( isset( $_POST[ WC_Facebook_Product::FB_VARIABLE_BRAND ] ) ) {
$woo_product->set_fb_brand( sanitize_text_field( wp_unslash( $_POST[ WC_Facebook_Product::FB_VARIABLE_BRAND ] ) ) );
}
$this->save_facebook_product_attributes( $woo_product );
}

/**
Expand Down Expand Up @@ -905,14 +945,7 @@ private function save_product_settings( WC_Product $product ) {
$woo_product->set_product_video_urls( $attachment_ids );
}

if ( isset( $_POST[ WC_Facebook_Product::FB_BRAND ] ) ) {
$woo_product->set_fb_brand( sanitize_text_field( wp_unslash( $_POST[ WC_Facebook_Product::FB_BRAND ] ) ) );
}

if ( isset( $_POST[ WC_Facebook_Product::FB_MPN ] ) ) {
$woo_product->set_fb_mpn( sanitize_text_field( wp_unslash( $_POST[ WC_Facebook_Product::FB_MPN ] ) ) );
}
// phpcs:enable WordPress.Security.NonceVerification.Missing
$this->save_facebook_product_attributes( $woo_product );
}

/**
Expand All @@ -937,7 +970,7 @@ public function on_product_delete( int $product_id ) {
*/
// phpcs:ignore WordPress.Security.NonceVerification.Missing
if ( ( ! wp_doing_ajax() || ! isset( $_POST['action'] ) || 'ajax_delete_fb_product' !== $_POST['action'] )
&& ! Products::published_product_should_be_synced( $product ) && ! $product->is_type( 'variable' ) ) {
&& ! Products::published_product_should_be_synced( $product ) && ! $product->is_type( 'variable' ) ) {
return;
}

Expand Down Expand Up @@ -1092,7 +1125,6 @@ public function delete_draft_product( $post ) {
}

$this->on_product_delete( $post->ID );

}


Expand Down Expand Up @@ -1670,8 +1702,7 @@ public function delete_product_set_item( string $fb_product_set_id ) {
* - product_item_id : if exists, means product was created else not and don't display
* - should_sync: Don't display if the product is not supposed to be synced.
*
* @param WP_Post $post Wordpress Post
*
* @param WP_Post $post WordPress Post
* @return void
*/
public function display_batch_api_completed( $post ) {
Expand Down Expand Up @@ -2281,7 +2312,7 @@ private function sync_facebook_products_using_background_processor() {
);

$this->on_product_publish( $post_id );
$count ++;
++$count;
}
WC_Facebookcommerce_Utils::log( 'Synced ' . $count . ' products' );
$this->remove_sticky_message();
Expand Down Expand Up @@ -2736,9 +2767,9 @@ public function is_product_sync_enabled() {
* implemented, which should work well for all stores. This option will not disable
* the new improved implementation.
*
* @return bool
* @since 2.5.0
*
* @return bool
*/
public function is_legacy_feed_file_generation_enabled() {
return 'yes' === get_option( self::OPTION_LEGACY_FEED_FILE_GENERATION_ENABLED, 'yes' );
Expand Down Expand Up @@ -2996,7 +3027,6 @@ public function update_fb_visibility( $product_id, $visibility ) {
$fb_product_item_id = $this->get_product_fbid( self::FB_PRODUCT_ITEM_ID, $product->get_id() );
if ( ! $fb_product_item_id ) {
\WC_Facebookcommerce_Utils::fblog( $fb_product_item_id . " doesn't exist but underwent a visibility transform.", [], true );

return;
}
try {
Expand Down
Loading