|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
// requere once вместо include использовать! |
|
|
|
|
// require once вместо include использовать! |
|
|
|
|
// доделать example module и component |
|
|
|
|
require_once __DIR__ . '/vendor/autoload.php'; |
|
|
|
|
|
|
|
|
@ -14,6 +14,26 @@ Timber::$dirname = [ |
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
use Timber\PostCollection; |
|
|
|
|
use Timber\Integrations\WooCommerce\Product as TimberProduct; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
add_filter( 'timber/integrations', function ( array $integrations ): array { |
|
|
|
|
$integrations[] = new \Timber\Integrations\WooCommerce\WooCommerceIntegration(); |
|
|
|
|
|
|
|
|
|
return $integrations; |
|
|
|
|
} ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
add_action('timber/init', function() { |
|
|
|
|
// Инициализируем WooCommerce интеграцию |
|
|
|
|
if (class_exists('Timber\Integrations\WooCommerce\WooCommerce')) { |
|
|
|
|
Timber\Integrations\WooCommerce\WooCommerce::init(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function theme_add_woocommerce_support() |
|
|
|
|
{ |
|
|
|
|
add_theme_support('woocommerce'); |
|
|
|
@ -398,3 +418,165 @@ require_once('modules/forms/module-ajax-controller.php'); |
|
|
|
|
include_module('forms'); |
|
|
|
|
include_module('layout'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WooProduct extends Timber\Post { |
|
|
|
|
protected $wc_product; |
|
|
|
|
|
|
|
|
|
public function __construct ($pid = null) { |
|
|
|
|
parent::__construct($pid); |
|
|
|
|
$this->wc_product = wc_get_product($this->ID); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function price() { |
|
|
|
|
return $this->wc_product->get_price(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function get_price_html() { |
|
|
|
|
return $this->wc_product->get_price_html(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function get_attr() { |
|
|
|
|
return $this->wc_product->get_attribute('pa_compound'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function get_test() { |
|
|
|
|
return 'test'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
add_filter('timber/post/classmap', function ($classmap) { |
|
|
|
|
$custom_classmap = [ |
|
|
|
|
'product' => WooProduct::class, |
|
|
|
|
]; |
|
|
|
|
return array_merge($classmap, $custom_classmap); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
//Ajax подгрузка товаров в архиве |
|
|
|
|
add_action( 'wp_ajax_nopriv_get_products', 'get_products' ); |
|
|
|
|
add_action( 'wp_ajax_get_products', 'get_products' ); |
|
|
|
|
|
|
|
|
|
function get_products() { |
|
|
|
|
global $post; |
|
|
|
|
|
|
|
|
|
if (function_exists('WC')) { |
|
|
|
|
WC(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Потом Timber |
|
|
|
|
|
|
|
|
|
$context = Timber::context(); |
|
|
|
|
$context['get_page'] = empty($_POST['get_page']) ? 1 : $_POST['get_page']; |
|
|
|
|
$context['criteria_for_new_product'] = date('Y-m-d', strtotime('-30 days')); |
|
|
|
|
$context['get_category'] = isset($_POST['get_category']) ? $_POST['get_category'] : NULL; |
|
|
|
|
$context['get_category_type'] = isset($_POST['get_category_type']) ? $_POST['get_category_type'] : NULL; |
|
|
|
|
|
|
|
|
|
// Задаем количество постов для подзагрузки Ajax |
|
|
|
|
$posts_per_page = 1; |
|
|
|
|
|
|
|
|
|
$args = array( |
|
|
|
|
'post_type' => 'product', |
|
|
|
|
'post_status' => 'publish', |
|
|
|
|
'posts_per_page' => $posts_per_page, |
|
|
|
|
'paged' => $context['get_page'], |
|
|
|
|
'has_password' => FALSE |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$count_args = array( |
|
|
|
|
'post_type' => 'product', |
|
|
|
|
'post_status' => 'publish', |
|
|
|
|
'posts_per_page' => -1, |
|
|
|
|
'has_password' => FALSE |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if ($context['get_category'] != NULL) { |
|
|
|
|
$categories = [ |
|
|
|
|
'tax_query' => array( |
|
|
|
|
array( |
|
|
|
|
'taxonomy' => $context['get_category_type'], |
|
|
|
|
'field' => 'term_id', |
|
|
|
|
'terms' => array($context['get_category']), |
|
|
|
|
'operator' => 'IN' |
|
|
|
|
), |
|
|
|
|
array( |
|
|
|
|
'taxonomy' => 'product_visibility', |
|
|
|
|
'field' => 'slug', |
|
|
|
|
'terms' => 'exclude-from-catalog', |
|
|
|
|
'operator' => 'NOT IN' |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
]; |
|
|
|
|
$args = array_merge($args, $categories); |
|
|
|
|
$count_args = array_merge($count_args, $categories); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$products = new WP_Query($args); |
|
|
|
|
$products = new Timber\PostQuery($products, 'Timber\Integrations\WooCommerce\Product'); |
|
|
|
|
|
|
|
|
|
$context['posts'] = $products; |
|
|
|
|
|
|
|
|
|
$context['count'] = count(Timber::get_posts($count_args)); |
|
|
|
|
|
|
|
|
|
if ($context['count'] <= $context['get_page'] * 1) $context['ended'] = true; |
|
|
|
|
|
|
|
|
|
Timber::render( 'woocommerce/archive-product/archive-product-ajaxload.twig', $context ); |
|
|
|
|
|
|
|
|
|
die(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function get_product_info ($id, $type) { |
|
|
|
|
$product = wc_get_product( $id ); |
|
|
|
|
if ($type == 'price') { |
|
|
|
|
return $product->get_price(); |
|
|
|
|
} elseif ($type == 'weight') { |
|
|
|
|
return $product->get_weight() . ' кг'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function get_add_to_cart_button ($id) { |
|
|
|
|
$product = wc_get_product( $id ); |
|
|
|
|
return '<a href="'. $product->add_to_cart_url(). '" value="'. esc_attr( $product->get_id() ) .'" |
|
|
|
|
class="ajax_add_to_cart add_to_cart_button button button--gradient button--base button--100-perc" data-product_id="'. $id .'">'. pll__('Добавить в корзину') .'</a>'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function get_collection_siblings ($term) { |
|
|
|
|
$args = array( |
|
|
|
|
'posts_per_page' => -1, |
|
|
|
|
'post_type' => 'product', |
|
|
|
|
'order' => 'ASC', |
|
|
|
|
'order_by' => 'name', |
|
|
|
|
'tax_query' => [ |
|
|
|
|
[ |
|
|
|
|
'taxonomy' => 'pa_collection', |
|
|
|
|
'terms' => $term, |
|
|
|
|
'field' => 'id', |
|
|
|
|
] |
|
|
|
|
], |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$siblings = get_posts($args); |
|
|
|
|
|
|
|
|
|
$sibl_arr = []; |
|
|
|
|
|
|
|
|
|
foreach( $siblings as $sibling ) { |
|
|
|
|
$sibl_arr [] = $sibling; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $sibl_arr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
register_sidebar( array( |
|
|
|
|
'name' => 'Сайдбар для фильтров товаров', |
|
|
|
|
'id' => 'sidebar_filters', |
|
|
|
|
'before_widget' => '<div id="%1$s" class="widget %2$s">', |
|
|
|
|
'after_widget' => '</div>', |
|
|
|
|
'before_title' => '<h3 class="widget-title">', |
|
|
|
|
'after_title' => '</h3>', |
|
|
|
|
) ); |