1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
<?php // phpcs:ignoreFile
namespace AutomateWoo;
/** * @class Logic_Helper */ class Logic_Helper {
/** * Check if two products are the same, complexity aries when considering variations * * @param \WC_Product $actual_product * @param \WC_Product $expected_product * @return bool */ static function match_products( $actual_product, $expected_product ) {
if ( ! $actual_product ) { return false; }
$match = false;
if ( $expected_product->is_type( 'variation' ) ) { // match a specific variation if ( $expected_product->get_id() == $actual_product->get_id() ) { $match = true; } } else { // match the main product or any of its variations $actual_main_product_id = $actual_product->is_type( 'variation' ) ? $actual_product->get_parent_id() : $actual_product->get_id();
if ( $expected_product->get_id() == $actual_main_product_id ) { $match = true; } }
return $match; }
}
|