* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ class OrderCarrierCore extends ObjectModel { /** @var int */ public $id_order_carrier; /** @var int */ public $id_order; /** @var int */ public $id_carrier; /** @var int */ public $id_order_invoice; /** @var float */ public $weight; /** @var float */ public $shipping_cost_tax_excl; /** @var float */ public $shipping_cost_tax_incl; /** @var string */ public $tracking_number; /** @var string Object creation date */ public $date_add; /** * @see ObjectModel::$definition */ public static $definition = [ 'table' => 'order_carrier', 'primary' => 'id_order_carrier', 'fields' => [ 'id_order' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true], 'id_carrier' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true], 'id_order_invoice' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId'], 'weight' => ['type' => self::TYPE_FLOAT, 'validate' => 'isFloat'], 'shipping_cost_tax_excl' => ['type' => self::TYPE_FLOAT, 'validate' => 'isFloat'], 'shipping_cost_tax_incl' => ['type' => self::TYPE_FLOAT, 'validate' => 'isFloat'], 'tracking_number' => ['type' => self::TYPE_STRING, 'validate' => 'isTrackingNumber'], 'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'], ], ]; protected $webserviceParameters = [ 'objectMethods' => ['update' => 'updateWs'], 'fields' => [ 'id_order' => ['xlink_resource' => 'orders'], 'id_carrier' => ['xlink_resource' => 'carriers'], ], ]; /** * @param Order $order Required * * @return bool */ public function sendInTransitEmail($order) { $orderLanguageId = (int) $order->getAssociatedLanguage()->getId(); $customer = new Customer((int) $order->id_customer); $carrier = new Carrier((int) $order->id_carrier, $orderLanguageId); $address = new Address((int) $order->id_address_delivery); if (!Validate::isLoadedObject($customer)) { throw new PrestaShopException('Can\'t load Customer object'); } if (!Validate::isLoadedObject($carrier)) { throw new PrestaShopException('Can\'t load Carrier object'); } if (!Validate::isLoadedObject($address)) { throw new PrestaShopException('Can\'t load Address object'); } if (!$carrier->url) { // the url field of the carrier is empty therefore the e-mail must not be sent return true; } $products = $order->getCartProducts(); $link = Context::getContext()->link; $metadata = ''; foreach ($products as $product) { $prod_obj = new Product((int) $product['product_id']); //try to get the first image for the purchased combination $img = $prod_obj->getCombinationImages($orderLanguageId); $link_rewrite = $prod_obj->link_rewrite[$orderLanguageId]; $combination_img = $img[$product['product_attribute_id']][0]['id_image'] ?? null; if ($combination_img != null) { $img_url = $link->getImageLink($link_rewrite, $combination_img, 'large_default'); } else { //if there is no combination image, then get the product cover instead $img = $prod_obj->getCover($prod_obj->id); $img_url = !empty($img['id_image']) ? $link->getImageLink($link_rewrite, $img['id_image']) : ''; } $prod_url = $prod_obj->getLink(); $metadata .= "\n" . '