Skip to content

Commit

Permalink
Merge pull request #26 from biologeek/slots-interval-fix
Browse files Browse the repository at this point in the history
Slots interval fix and order items as comment
  • Loading branch information
alexsegura authored Sep 14, 2023
2 parents 602ae24 + 9994aa1 commit a68dee7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
8 changes: 8 additions & 0 deletions wordpress/coopcycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion wordpress/src/CoopCycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ public static function time_slot_to_date_periods($time_slot, \DateTime $now = nu
$now = new \DateTime();
}

$endDate = clone $now;
$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;

Expand Down
33 changes: 33 additions & 0 deletions wordpress/tests/ShippingDatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}

0 comments on commit a68dee7

Please sign in to comment.