reviewCollectorRequest = new ReviewCollectorRequest(); $this->id_lang = $id_lang; if(is_array($order) && count($order) > 0){ foreach ($order as $order_id){ $current_processed_order = new Order((int)$order_id); if (Validate::isLoadedObject($current_processed_order)) { $this->addItem($current_processed_order); } } }else{ if (Validate::isLoadedObject($order)) { $this->addItem($order); } } } private function addItem($order){ $days = Configuration::get('TRUSTED_SHOP_DAYS'); $reviewCollectorReviewItem = new ReviewCollectorReviewItem(); $review_sent_date = new DateTime(); $review_sent_date->add(new DateInterval('P'.$days.'D')); //we add days $reviewCollectorReviewItem->reminderDate = $review_sent_date->format("Y-m-d"); $reviewCollectorReviewItem->template = new ReviewCollectorReviewTemplate(self::CHOSEN_VARIANT, FALSE); $reviewCollectorReviewItem->order = new ReviewCollectorReviewOrder($order, $this->id_lang); $customer = new Customer((int)$order->id_customer); $reviewCollectorReviewItem->consumer = new ReviewCollectorReviewConsumer($customer->firstname, $customer->lastname, $customer->email); $this->reviewCollectorRequest->reviewCollectorReviewRequests[] = $reviewCollectorReviewItem; } public function generateRequest() { return json_encode($this); } } class ReviewCollectorRequest{ public $reviewCollectorReviewRequests; public function __construct() { $this->reviewCollectorReviewRequests = array(); } } class ReviewCollectorReviewItem { public $reminderDate; public $template; public $order; public $consumer; } class ReviewCollectorReviewTemplate { public $variant; //The template variant might be either 'BEST_PRACTICE', 'CREATING_TRUST' or 'CUSTOMER_SERVICE'. public $includeWidget = FALSE; public function __construct($variant, $includeWidget) { $this->variant = $variant; $this->includeWidget = $includeWidget; } } class ReviewCollectorReviewOrder { const CURRENCY_NAME = 'EUR'; public $orderDate; public $orderReference; public $products; public $currency; public $estimatedDeliveryDate; public function __construct(Order $order, $id_lang) { $days = Configuration::get('TRUSTED_SHOP_DAYS'); $order_date = new DateTime($order->date_add); $this->orderDate = $order_date->format('Y-m-d');; $this->orderReference = "".$order->id; $this->currency = self::CURRENCY_NAME; $estimated_delivery_date = new DateTime(); $estimated_delivery_date->add(new DateInterval('P'.$days.'D')); //we add 5 days $this->estimatedDeliveryDate = $estimated_delivery_date->format('Y-m-d'); $this->products = array(); foreach ($order->getProducts() as $row) { $product = new ReviewCollectorReviewOrderProduct(); $presta_product = new Product((int)$row['product_id'], FALSE, $id_lang); $link = new Link(); $product->name = $row['product_name']; $product->sku = $row['product_supplier_reference']; $product->gtin = $row['product_ean13']; $product->mpn = $row['product_reference']; $product->brand = ($presta_product->manufacturer_name ? $presta_product->manufacturer_name : ""); $product->imageUrl = $link->getImageLink(Tools::link_rewrite($presta_product->name), $presta_product->id . '-' . Product::getCover($presta_product->id)['id_image'], 'large'); $product->uuid = "".$presta_product->id; $product->url = $link->getProductLink($presta_product->id); $this->products[] = $product; } } } class ReviewCollectorReviewOrderProduct { public $sku; public $name; public $gtin; public $mpn; public $brand; public $imageUrl; public $uuid; public $url; } class ReviewCollectorReviewConsumer { public $firstname; public $lastname; public $contact; public function __construct($firstname, $lastname, $email) { $this->firstname = $firstname; $this->lastname = $lastname; $this->contact = new ReviewCollectorReviewConsumerContact($email); } } class ReviewCollectorReviewConsumerContact { public $email; public function __construct($email) { $this->email = $email; } }