177 lines
6.5 KiB
PHP
177 lines
6.5 KiB
PHP
<?php
|
|
/**
|
|
* Module Partial Shipment - Main file
|
|
*
|
|
* @author My Addons <contact@myaddons.io>
|
|
* @copyright 2017 My Addons
|
|
* @license myaddons.io
|
|
* @version 1.0.0
|
|
* @since File available since Release 1.0
|
|
*/
|
|
|
|
class HTMLTemplatePartialShipment extends HTMLTemplate
|
|
{
|
|
public $order;
|
|
|
|
/**
|
|
* @param Order $order
|
|
* @param $smarty
|
|
* @throws PrestaShopException
|
|
*/
|
|
public function __construct(PartialShipment $partialShipment, $smarty)
|
|
{
|
|
$this->partialShipment = $partialShipment;
|
|
$this->order = new Order((int) $this->partialShipment->id_order);
|
|
$this->smarty = $smarty;
|
|
|
|
if (version_compare(_PS_VERSION_, '1.6.1.1', '>=')) {
|
|
$this->order->shop_address = OrderInvoice::getCurrentFormattedShopAddress((int)$this->order->id_shop);
|
|
}
|
|
|
|
// header informations
|
|
$this->date = Tools::displayDate($this->order->date_add);
|
|
$prefix = Configuration::get('PS_DELIVERY_PREFIX', Context::getContext()->language->id);
|
|
$this->title = sprintf(HTMLTemplatePartialShipment::l('%1$s%2$06d'), $prefix, $this->partialShipment->id);
|
|
|
|
// footer informations
|
|
$this->shop = new Shop((int)$this->order->id_shop);
|
|
}
|
|
|
|
/**
|
|
* Returns the template's HTML header
|
|
*
|
|
* @return string HTML header
|
|
*/
|
|
public function getHeader()
|
|
{
|
|
if (version_compare(_PS_VERSION_, '1.6.1', '>=')) {
|
|
$this->assignCommonHeaderData();
|
|
$this->smarty->assign(array('header' => HTMLTemplatePartialShipment::l('Delivery')));
|
|
|
|
return $this->smarty->fetch($this->getTemplate('header'));
|
|
} else {
|
|
return parent::getHeader();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns the template's HTML content
|
|
*
|
|
* @return string HTML content
|
|
*/
|
|
public function getContent()
|
|
{
|
|
$delivery_address = new Address((int)$this->order->id_address_delivery);
|
|
$formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' ');
|
|
$formatted_invoice_address = '';
|
|
|
|
if ($this->order->id_address_delivery != $this->order->id_address_invoice) {
|
|
$invoice_address = new Address((int)$this->order->id_address_invoice);
|
|
$formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' ');
|
|
}
|
|
|
|
$carrier = new Carrier($this->order->id_carrier);
|
|
$carrier->name = ($carrier->name == '0' ? Configuration::get('PS_SHOP_NAME') : $carrier->name);
|
|
|
|
$order_details = $this->order->getProducts();
|
|
|
|
if (Configuration::get('PS_PDF_IMG_DELIVERY')) {
|
|
foreach ($order_details as &$order_detail) {
|
|
if ($order_detail['image'] != null) {
|
|
$name = 'product_mini_'.(int)$order_detail['product_id'].(isset($order_detail['product_attribute_id']) ? '_'.(int)$order_detail['product_attribute_id'] : '').'.jpg';
|
|
$path = _PS_PROD_IMG_DIR_.$order_detail['image']->getExistingImgPath().'.jpg';
|
|
|
|
$order_detail['image_tag'] = preg_replace(
|
|
'/\.*'.preg_quote(__PS_BASE_URI__, '/').'/',
|
|
_PS_ROOT_DIR_.DIRECTORY_SEPARATOR,
|
|
ImageManager::thumbnail($path, $name, 45, 'jpg', false),
|
|
1
|
|
);
|
|
|
|
if (file_exists(_PS_TMP_IMG_DIR_.$name)) {
|
|
$order_detail['image_size'] = getimagesize(_PS_TMP_IMG_DIR_.$name);
|
|
} else {
|
|
$order_detail['image_size'] = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//We check if product in this partial delivery
|
|
//We get products by partialshipment for this order
|
|
$shippedInPartial = $this->partialShipment->getPartialShipmentDetail();
|
|
|
|
foreach ($order_details as $index => &$order_detail) {
|
|
if (version_compare(phpversion(), '5.5', '>=')) {
|
|
$key = array_search($order_detail['id_order_detail'], array_column($shippedInPartial, 'id_order_detail'));
|
|
} else {
|
|
$key = false;
|
|
foreach ($shippedInPartial as $shippedIndex => $value) {
|
|
if ($order_detail['id_order_detail'] == $value['id_order_detail']) {
|
|
$key = $shippedIndex;
|
|
}
|
|
}
|
|
}
|
|
if ($key !== false) {
|
|
$order_detail['product_quantity'] = $shippedInPartial[$key]['quantity'];
|
|
} else {
|
|
unset($order_details[$index]);
|
|
}
|
|
}
|
|
|
|
$this->smarty->assign(array(
|
|
'order' => $this->order,
|
|
'order_details' => $order_details,
|
|
'delivery_address' => $formatted_delivery_address,
|
|
'invoice_address' => $formatted_invoice_address,
|
|
'order_invoice' => $this->order,
|
|
'comments' => $this->order->getFirstMessage(),
|
|
'carrier' => $carrier,
|
|
'display_product_images' => Configuration::get('PS_PDF_IMG_DELIVERY')
|
|
));
|
|
|
|
if (version_compare(_PS_VERSION_, '1.6.1', '>=')) {
|
|
$tpls = array(
|
|
'style_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.style-tab')),
|
|
'addresses_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.addresses-tab')),
|
|
'summary_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.summary-tab')),
|
|
'product_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.product-tab')),
|
|
'payment_tab' => '',
|
|
);
|
|
$this->smarty->assign($tpls);
|
|
}
|
|
|
|
return $this->smarty->fetch($this->getTemplate('delivery-slip'));
|
|
}
|
|
|
|
/**
|
|
* Returns the template filename when using bulk rendering
|
|
*
|
|
* @return string filename
|
|
*/
|
|
public function getBulkFilename()
|
|
{
|
|
return 'deliveries.pdf';
|
|
}
|
|
|
|
/**
|
|
* Returns the template filename
|
|
*
|
|
* @return string filename
|
|
*/
|
|
public function getFilename()
|
|
{
|
|
return Configuration::get('PS_DELIVERY_PREFIX', Context::getContext()->language->id, null, $this->order->id_shop).sprintf('%06d', $this->order->delivery_number).'.pdf';
|
|
}
|
|
|
|
/**
|
|
* Returns the template filename
|
|
* Add to Specific PrestaShop version
|
|
* @return string filename
|
|
*/
|
|
public function getPagination()
|
|
{
|
|
return $this->smarty->fetch($this->getTemplate('pagination'));
|
|
}
|
|
}
|