Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for Black Friday 2024 #4197

Merged
merged 7 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions assets/apps/customizer-controls/src/@types/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
type EventResponse = {
error?: string;
success?: boolean;
response?: any;

Check warning on line 122 in assets/apps/customizer-controls/src/@types/utils.d.ts

View workflow job for this annotation

GitHub Actions / npm (14.x)

Unexpected any. Specify a different type
};

type EventOptions = {
Expand Down Expand Up @@ -167,9 +167,9 @@
remaningTime?: string;
bannerUrl?: string;
customizerBannerUrl?: string;
linkDashboard?: string;
bannerStoreUrl?: string;
linkGlobal?: string;
linkCustomizer?: string;
customizerBannerStoreUrl?: string;
customizerBannerAlt?: string;
bannerAlt?: string;
};
Expand Down
11 changes: 9 additions & 2 deletions assets/apps/customizer-controls/src/builder-upsell/Upsells.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ const Upsells: React.FC<Props> = ({ control }) => {
const { params } = control;
const { title, url } = params;

if (window?.NeveReactCustomize?.deal?.active) {
if (
window?.NeveReactCustomize?.deal?.active &&
window?.NeveReactCustomize?.deal?.customizerBannerStoreUrl &&
window?.NeveReactCustomize?.deal?.customizerBannerUrl
) {
return (
<div className="upsell-inner">
<a
href={window?.NeveReactCustomize?.deal?.linkCustomizer}
href={
window?.NeveReactCustomize?.deal
?.customizerBannerStoreUrl
}
target="_blank"
rel="external noreferrer noopener"
style={{ width: '100%', lineHeight: '0' }}
Expand Down
8 changes: 6 additions & 2 deletions assets/apps/dashboard/src/Components/Deal.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
/* global neveDash */

const Deal = () => {
if (!Boolean(window.neveDash?.deal?.active)) {
if (
!Boolean(window.neveDash?.deal?.active) ||
!Boolean(neveDash?.deal?.bannerUrl) ||
!Boolean(neveDash?.deal?.bannerStoreUrl)
) {
return <></>;
}

return (
<div className="nv-deal">
<a
href={neveDash?.deal?.linkDashboard}
href={neveDash?.deal?.bannerStoreUrl}
target="_blank"
rel="external noreferrer noopener"
>
Expand Down
Binary file modified assets/img/dashboard/black-friday-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/img/dashboard/black-friday-customizer-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 0 additions & 8 deletions inc/core/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@ function () {

add_action( 'rest_api_init', [ $this, 'register_rest_routes' ] );
add_filter( 'neve_pro_react_controls_localization', [ $this, 'adapt_conditional_headers' ] );


if ( ! defined( 'NEVE_PRO_VERSION' ) ) {
$offer = new Limited_Offers();
if ( $offer->can_show_dashboard_banner() && $offer->is_active() ) {
$offer->load_dashboard_hooks();
}
}
}

/**
Expand Down
146 changes: 45 additions & 101 deletions inc/core/limited_offers.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

namespace Neve\Core;

use DateTime;
use DateTimeZone;
use Exception;

/**
Expand All @@ -38,27 +36,41 @@ class Limited_Offers {
*
* @var array<string>
*/
public $offer_metadata = array();
public $assets = array();

/**
* Timeline for the offers.
*
* @var array[]
*/
public $timelines = array(
'bf' => array(
'start' => '2023-11-20 00:00:00',
'end' => '2023-11-27 23:59:00',
),
);
public $announcements = array();
Soare-Robert-Daniel marked this conversation as resolved.
Show resolved Hide resolved

/**
* LimitedOffers constructor.
*/
public function __construct() {
$this->announcements = apply_filters( 'themeisle_sdk_announcements', array() );

if ( empty( $this->announcements ) || ! is_array( $this->announcements ) ) {
return;
}

try {
if ( $this->is_deal_active( 'bf' ) ) {
$this->activate_bff();
foreach ( $this->announcements as $announcement => $event_data ) {
if ( false !== strpos( $announcement, 'black_friday' ) ) {
if (
empty( $event_data ) ||
! is_array( $event_data ) ||
empty( $event_data['active'] ) ||
empty( $event_data['neve_dashboard_url'] ) ||
! isset( $event_data['urgency_text'] )
) {
continue;
}

$this->active = $announcement;
$this->prepare_black_friday_assets( $event_data );
}
}
} catch ( Exception $e ) {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
Expand All @@ -73,6 +85,11 @@ public function __construct() {
* @return void
*/
public function load_dashboard_hooks() {

if ( empty( $this->assets['globalNoticeUrl'] ) ) {
return;
}

add_filter( 'themeisle_products_deal_priority', array( $this, 'add_priority' ) );
add_action( 'admin_notices', array( $this, 'render_notice' ) );
add_action( 'wp_ajax_dismiss_themeisle_event_notice_neve', array( $this, 'disable_notification_ajax' ) );
Expand All @@ -87,22 +104,23 @@ public function is_active() {
return ! empty( $this->active );
}


/**
* Activate the Black Friday deal.
*
* @param array $data Event data.
*
* @return void
*/
public function activate_bff() {
$this->active = 'bf';

$this->offer_metadata = array(
'bannerUrl' => get_template_directory_uri() . '/assets/img/dashboard/black-friday-banner.png',
'bannerAlt' => 'Neve Black Friday Sale',
'customizerBannerUrl' => get_template_directory_uri() . '/assets/img/dashboard/black-friday-customizer-banner.png',
'customizerBannerAlt' => 'Neve Black Friday Sale',
'linkDashboard' => tsdk_utmify( 'https://themeisle.com/themes/neve/blackfriday/', 'blackfridayltd23', 'dashboard' ),
'linkGlobal' => tsdk_utmify( 'https://themeisle.com/themes/neve/blackfriday/', 'blackfridayltd23', 'globalnotice' ),
'linkCustomizer' => tsdk_utmify( 'https://themeisle.com/themes/neve/upgrade', 'blackfriday23', 'customizer' ),
public function prepare_black_friday_assets( $data ) {
$this->assets = array(
'bannerUrl' => get_template_directory_uri() . '/assets/img/dashboard/black-friday-banner.png',
'bannerAlt' => 'Neve Black Friday Sale',
'bannerStoreUrl' => esc_url_raw( $data['neve_dashboard_url'] ),
'customizerBannerUrl' => get_template_directory_uri() . '/assets/img/dashboard/black-friday-customizer-banner.png',
'customizerBannerAlt' => 'Neve Black Friday Sale',
'customizerBannerStoreUrl' => esc_url_raw( $data['neve_customizer_url'] ),
'urgencyText' => $data['urgency_text'],
);
}

Expand All @@ -115,77 +133,6 @@ public function get_active_deal() {
return $this->active;
}

/**
* Check if the deal is active with the given slug.
*
* @param string $slug Slug of the deal.
*
* @throws Exception When date is invalid.
*/
public function is_deal_active( $slug ) {

if ( empty( $slug ) || ! array_key_exists( $slug, $this->timelines ) ) {
return false;
}

return $this->check_date_range( $this->timelines[ $slug ]['start'], $this->timelines[ $slug ]['end'] );
}

/**
* Get the remaining time for the deal in a human readable format.
*
* @param string $slug Slug of the deal.
* @return string Remaining time for the deal.
*/
public function get_remaining_time_for_deal( $slug ) {
if ( empty( $slug ) || ! array_key_exists( $slug, $this->timelines ) ) {
return '';
}

try {
$end_date = new DateTime( $this->timelines[ $slug ]['end'], new DateTimeZone( 'GMT' ) );
$current_date = new DateTime( 'now', new DateTimeZone( 'GMT' ) );
$diff = $end_date->diff( $current_date );

if ( $diff->days > 0 ) {
return $diff->days === 1 ? $diff->format( '%a day' ) : $diff->format( '%a days' );
}

if ( $diff->h > 0 ) {
return $diff->h === 1 ? $diff->format( '%h hour' ) : $diff->format( '%h hours' );
}

if ( $diff->i > 0 ) {
return $diff->i === 1 ? $diff->format( '%i minute' ) : $diff->format( '%i minutes' );
}

return $diff->s === 1 ? $diff->format( '%s second' ) : $diff->format( '%s seconds' );
} catch ( Exception $e ) {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
error_log( $e->getMessage() ); // phpcs:ignore
}
}

return '';
}

/**
* Check if the current date is in the range of the offer.
*
* @param string $start Start date.
* @param string $end End date.
*
* @throws Exception When date is invalid.
*/
public function check_date_range( $start, $end ) {

$start_date = new DateTime( $start, new DateTimeZone( 'GMT' ) );
$end_date = new DateTime( $end, new DateTimeZone( 'GMT' ) );
$current_date = new DateTime( 'now', new DateTimeZone( 'GMT' ) );

return $start_date <= $current_date && $current_date <= $end_date;
}

/**
* Get the localized data for the plugin.
*
Expand All @@ -194,12 +141,10 @@ public function check_date_range( $start, $end ) {
public function get_localized_data() {
return array_merge(
array(
'active' => $this->is_active(),
'dealSlug' => $this->get_active_deal(),
'remainingTime' => $this->get_remaining_time_for_deal( $this->get_active_deal() ),
'urgencyText' => 'Hurry Up! Only ' . $this->get_remaining_time_for_deal( $this->get_active_deal() ) . ' left',
'active' => $this->is_active(),
'dealSlug' => $this->get_active_deal(),
),
$this->offer_metadata
$this->assets
);
}

Expand Down Expand Up @@ -246,8 +191,7 @@ public function render_notice() {
margin-right: 15px;
min-width: 24px;
}
.themeisle-sale a {
}

.themeisle-sale-error {
color: red;
}
Expand All @@ -266,7 +210,7 @@ public function render_notice() {

<span>
<?php echo wp_kses_post( $message ); ?>
<a href="<?php echo esc_url( ! empty( $this->offer_metadata['linkGlobal'] ) ? $this->offer_metadata['linkGlobal'] : '' ); ?>" target="_blank" rel="external noreferrer noopener">
<a href="<?php echo esc_url( ! empty( $this->assets['globalNoticeUrl'] ) ? $this->assets['globalNoticeUrl'] : '' ); ?>" target="_blank" rel="external noreferrer noopener">
Learn more
</a>
</span>
Expand Down
Loading