135 lines
3.9 KiB
PHP
135 lines
3.9 KiB
PHP
<?php
|
|
/**
|
|
* یکپارچهسازی افزونهٔ شبکه تأمین با قالب hesabix2.
|
|
*
|
|
* @package Hesabix2
|
|
*/
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
/**
|
|
* آیا افزونه فعال است؟
|
|
*/
|
|
function hesabix2_shabake_tamin_active() {
|
|
return class_exists( 'Shabake_Tamin_Public_Catalog', false );
|
|
}
|
|
|
|
/**
|
|
* نانراه کاتالوگ و محصول تکی.
|
|
*
|
|
* @param array<int, array{label: string, url?: string}> $items آیتمها.
|
|
* @return array<int, array{label: string, url?: string}>
|
|
*/
|
|
function hesabix2_shabake_tamin_breadcrumb( $items ) {
|
|
if ( ! hesabix2_shabake_tamin_active() ) {
|
|
return $items;
|
|
}
|
|
|
|
if ( Shabake_Tamin_Public_Catalog::is_product_request() ) {
|
|
$row = Shabake_Tamin_SEO::current_product_row();
|
|
$name = __( 'جزئیات کالا', 'shabake-tamin' );
|
|
if ( is_array( $row ) && ! empty( $row['product']['name'] ) ) {
|
|
$name = (string) $row['product']['name'];
|
|
}
|
|
return array(
|
|
array(
|
|
'label' => __( 'خانه', 'hesabix2' ),
|
|
'url' => home_url( '/' ),
|
|
),
|
|
array(
|
|
'label' => hesabix2_shabake_tamin_catalog_label(),
|
|
'url' => Shabake_Tamin_Public_Catalog::catalog_url(),
|
|
),
|
|
array(
|
|
'label' => $name,
|
|
),
|
|
);
|
|
}
|
|
|
|
if ( Shabake_Tamin_Public_Catalog::is_request() && ! Shabake_Tamin_Public_Catalog::is_product_request() ) {
|
|
return array(
|
|
array(
|
|
'label' => __( 'خانه', 'hesabix2' ),
|
|
'url' => home_url( '/' ),
|
|
),
|
|
array(
|
|
'label' => hesabix2_shabake_tamin_catalog_label(),
|
|
),
|
|
);
|
|
}
|
|
|
|
return $items;
|
|
}
|
|
add_filter( 'hesabix2_seo_breadcrumb_items', 'hesabix2_shabake_tamin_breadcrumb', 15 );
|
|
|
|
/**
|
|
* عنوان نمایشی کاتالوگ.
|
|
*
|
|
* @return string
|
|
*/
|
|
function hesabix2_shabake_tamin_catalog_label() {
|
|
$title = trim( (string) get_option( 'st_public_catalog_title', '' ) );
|
|
if ( '' === $title ) {
|
|
$title = __( 'شبکه تأمین', 'shabake-tamin' );
|
|
}
|
|
return $title;
|
|
}
|
|
|
|
/**
|
|
* افزودن شبکهٔ تأمین به بخش «بازار» در منوی هدر.
|
|
*
|
|
* @param array<int, array<string, mixed>> $tree درخت ناوبری.
|
|
* @return array<int, array<string, mixed>>
|
|
*/
|
|
function hesabix2_shabake_tamin_nav_tree( $tree ) {
|
|
if ( ! hesabix2_shabake_tamin_active() || ! (int) get_option( 'st_public_catalog_enabled', 0 ) ) {
|
|
return $tree;
|
|
}
|
|
|
|
foreach ( $tree as $index => $node ) {
|
|
if ( ! is_array( $node ) || empty( $node['id'] ) || 'market' !== $node['id'] ) {
|
|
continue;
|
|
}
|
|
if ( empty( $tree[ $index ]['items'] ) || ! is_array( $tree[ $index ]['items'] ) ) {
|
|
$tree[ $index ]['items'] = array();
|
|
}
|
|
$tree[ $index ]['items'][] = array(
|
|
'label' => hesabix2_shabake_tamin_catalog_label(),
|
|
'description' => __( 'کاتالوگ عمومی تأمینکنندگان و کالا', 'hesabix2' ),
|
|
'url' => Shabake_Tamin_Public_Catalog::catalog_url(),
|
|
'icon' => 'supply',
|
|
);
|
|
break;
|
|
}
|
|
|
|
return $tree;
|
|
}
|
|
add_filter( 'hesabix2_header_nav_tree', 'hesabix2_shabake_tamin_nav_tree', 15 );
|
|
|
|
/**
|
|
* بارگذاری استایل/اسکریپت در صفحهٔ محصول تکی (بدون ریشه کاتالوگ).
|
|
*/
|
|
function hesabix2_shabake_tamin_product_assets() {
|
|
if ( ! hesabix2_shabake_tamin_active() || ! Shabake_Tamin_Public_Catalog::is_product_request() ) {
|
|
return;
|
|
}
|
|
Shabake_Tamin_Frontend::enqueue_assets_once();
|
|
}
|
|
add_action( 'wp_enqueue_scripts', 'hesabix2_shabake_tamin_product_assets', 15 );
|
|
|
|
/**
|
|
* فونت کاتالوگ همراستا با قالب.
|
|
*
|
|
* @param string $class کلاس ریشه.
|
|
* @return string
|
|
*/
|
|
function hesabix2_shabake_tamin_root_class( $class ) {
|
|
return $class . ' st-hesabix2-compat';
|
|
}
|
|
add_filter( 'shabake_tamin_catalog_root_class', 'hesabix2_shabake_tamin_root_class' );
|
|
|
|
/** دیالوگ راهنمای ثبت کالا برای تأمینکنندگان */
|
|
$hesabix2_st_supplier = get_template_directory() . '/inc/shabake-tamin-supplier-dialog.php';
|
|
if ( is_readable( $hesabix2_st_supplier ) ) {
|
|
require_once $hesabix2_st_supplier;
|
|
}
|