From 09cdacd1db7b77a6fa7aacad4a514f4cda7406e7 Mon Sep 17 00:00:00 2001 From: biologeek Date: Mon, 13 Dec 2021 18:31:11 +0100 Subject: [PATCH 1/4] Changed task comment with Woocommerce order data --- wordpress/coopcycle.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wordpress/coopcycle.php b/wordpress/coopcycle.php index c72c12a..a3493e4 100644 --- a/wordpress/coopcycle.php +++ b/wordpress/coopcycle.php @@ -183,6 +183,12 @@ function coopcycle_woocommerce_order_status_changed($order_id, $old_status, $new $wp_name = get_bloginfo('name'); $wp_url = get_bloginfo('url'); + $items = ""; + + foreach ($order->get_items() as &$it) { + $items .= sprintf("%sx %s \n", $it->get_quantity(), $it->get_name()); + } + $task_comments = /* translators: order number, website, url. */ sprintf(__('Order #%1$s from %2$s (%3$s)', 'coopcycle'), $order->get_order_number(), $wp_name, $wp_url); @@ -192,6 +198,8 @@ function coopcycle_woocommerce_order_status_changed($order_id, $old_status, $new $task_comments .= "\n\n".$customer_note; } + $task_comments.= "\n******\nItems : \n".$items; + $data = array( // We only specify the dropoff data // Pickup is fully implicit From b94bdd994768947cb0488df94e9faf08828e7166 Mon Sep 17 00:00:00 2001 From: Biologeek Date: Mon, 4 Sep 2023 08:59:33 +0200 Subject: [PATCH 2/4] Using store-defined interval to display time slots --- wordpress/src/CoopCycle.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wordpress/src/CoopCycle.php b/wordpress/src/CoopCycle.php index a44b79e..8e50f9f 100644 --- a/wordpress/src/CoopCycle.php +++ b/wordpress/src/CoopCycle.php @@ -77,10 +77,12 @@ public static function time_slot_to_date_periods($time_slot, \DateTime $now = nu { if (null === $now) { $now = new \DateTime(); + $endDate = new \DateTime(); } + $endDate->modify("+{$time_slot['interval']}"); $number_of_days = 0; - $expected_number_of_days = 2; + $expected_number_of_days = $endDate->diff($now)->days; $cursor = clone $now; From 98deff22f3563ae5c672357e1cbf169d2c2e69e5 Mon Sep 17 00:00:00 2001 From: Alexandre Segura Date: Thu, 14 Sep 2023 14:33:03 +0200 Subject: [PATCH 3/4] Make sure var is defined, clone passed time for now. --- wordpress/src/CoopCycle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wordpress/src/CoopCycle.php b/wordpress/src/CoopCycle.php index 8e50f9f..a49b163 100644 --- a/wordpress/src/CoopCycle.php +++ b/wordpress/src/CoopCycle.php @@ -77,9 +77,9 @@ public static function time_slot_to_date_periods($time_slot, \DateTime $now = nu { if (null === $now) { $now = new \DateTime(); - $endDate = new \DateTime(); } + $endDate = clone $now; $endDate->modify("+{$time_slot['interval']}"); $number_of_days = 0; $expected_number_of_days = $endDate->diff($now)->days; From 9994aa17ca2548aa169b44fc5d34c459d8502cf8 Mon Sep 17 00:00:00 2001 From: Alexandre Segura Date: Thu, 14 Sep 2023 14:34:04 +0200 Subject: [PATCH 4/4] Add test with different interval. --- wordpress/tests/ShippingDatesTest.php | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/wordpress/tests/ShippingDatesTest.php b/wordpress/tests/ShippingDatesTest.php index 3ff8618..6031ea9 100644 --- a/wordpress/tests/ShippingDatesTest.php +++ b/wordpress/tests/ShippingDatesTest.php @@ -96,4 +96,37 @@ public function testTimeSlotToDatePeriodsWithPriorNotice2() $this->assertCount(12, $ranges); $this->assertEquals($this->makeDatePeriod('2021-03-17 18:00', '2021-03-17 18:30'), $ranges[0]); } + + public function testTimeSlotToDatePeriodsWithInterval() + { + require_once __DIR__ . '/../src/CoopCycle.php'; + + $ohs = [ + [ + "@type" => "OpeningHoursSpecification", + "dayOfWeek" => [ "Tuesday", "Thursday" ], + "opens" => "18:00:00", + "closes" => "19:00:00" + ], + [ + "@type" => "OpeningHoursSpecification", + "dayOfWeek" => [ "Tuesday", "Thursday" ], + "opens" => "19:00:00", + "closes" => "20:30:00" + ], + ]; + + $time_slot = [ + 'interval' => '7 days', + 'openingHoursSpecification' => $ohs, + ]; + + $ranges = \CoopCycle::time_slot_to_date_periods($time_slot, new \DateTime('2019-12-18 12:00:00')); + + $this->assertCount(14, $ranges); + $this->assertEquals($this->makeDatePeriod('2019-12-19 18:00', '2019-12-19 19:00'), $ranges[0]); + $this->assertEquals($this->makeDatePeriod('2019-12-19 19:00', '2019-12-19 20:30'), $ranges[1]); + $this->assertEquals($this->makeDatePeriod('2019-12-24 18:00', '2019-12-24 19:00'), $ranges[2]); + $this->assertEquals($this->makeDatePeriod('2019-12-24 19:00', '2019-12-24 20:30'), $ranges[3]); + } }