[85, 15, 30, 30, 15, 15], 'no_ecotax' => [100, 15, 30, 15, 30], 'delivery' => [120, 30, 10] ]; private function hasProductWithEcotax($products) { foreach($products as $product) { if (!empty($product['ecotax']) && $product['ecotax']>0) { return true; } } return false; } public function ProdTab($delivery = false, $tri = false) { if (!self::$orderSlip) { if (isset(self::$order->products) AND sizeof(self::$order->products)) $products = self::$order->products; else $products = self::$order->getProducts(false, false, false, $tri); } else $products = self::$orderSlip->getOrdersSlipProducts(self::$orderSlip->id, self::$order); $hasEcotax = $this->hasProductWithEcotax($products); if ($hasEcotax) { $this->ProdTabHeaderWithEcotax($delivery); } else { $this->ProdTabHeader($delivery); } if (!$delivery) { $w = &$this->cell_widths[$hasEcotax?'with_ecotax':'no_ecotax']; } else { $w = &$this->cell_widths['delivery']; } $customizedDatas = Product::getAllCustomizedDatas((int)(self::$order->id_cart)); Product::addCustomizationPrice($products, $customizedDatas); $counter = 0; $lines = 25; $lineSize = 0; $line = 0; foreach($products AS $product) if (!$delivery OR ((int)($product['product_quantity']) - (int)($product['product_quantity_refunded']) > 0)) { if ($product['sended'] == 1) { $product['product_name'] = '* '.$product['product_name']; } if ($counter >= $lines) { $this->AddPage(); $this->Ln(); self::ProdTabHeader($delivery); $lineSize = 0; $counter = 0; $lines = 40; $line++; } $counter = $counter + ($lineSize / 5) ; $i = -1; // Unit vars $unit_without_tax = $product['product_price'] + $product['ecotax']; $unit_with_tax = $product['product_price_wt']; if (self::$_priceDisplayMethod == PS_TAX_EXC) $unit_price = &$unit_without_tax; else $unit_price = &$unit_with_tax; $productQuantity = $delivery ? ((int)($product['product_quantity']) - (int)($product['product_quantity_refunded'])) : (int)($product['product_quantity']); if ($productQuantity <= 0) continue ; // Total prices $total_with_tax = $unit_with_tax * $productQuantity; $total_without_tax = $unit_without_tax * $productQuantity; // Spec if (self::$_priceDisplayMethod == PS_TAX_EXC) $final_price = &$total_without_tax; else $final_price = &$total_with_tax; // End Spec if (isset($customizedDatas[$product['product_id']][$product['product_attribute_id']])) { $custoLabel = ''; foreach($customizedDatas[$product['product_id']][$product['product_attribute_id']] as $customizedData) { $customizationGroup = $customizedData['datas']; $nb_images = 0; if (array_key_exists(_CUSTOMIZE_FILE_, $customizationGroup)) $nb_images = sizeof($customizationGroup[_CUSTOMIZE_FILE_]); if (array_key_exists(_CUSTOMIZE_TEXTFIELD_, $customizationGroup)) foreach($customizationGroup[_CUSTOMIZE_TEXTFIELD_] as $customization) if (!empty($customization['name'])) $custoLabel .= '- '.$customization['name'].': '.$customization['value']."\n"; if ($nb_images > 0) $custoLabel .= '- '.$nb_images. ' '. self::l('image(s)')."\n"; $custoLabel .= "---\n"; } $custoLabel = rtrim($custoLabel, "---\n"); $productQuantity = (int)($product['product_quantity']) - (int)($product['customizationQuantityTotal']); if ($delivery) $this->SetX(25); $before = $this->GetY(); $this->MultiCell($w[++$i], 5, Tools::iconv('utf-8', self::encoding(), $product['product_name']).' - '.self::l('Customized')." \n".Tools::iconv('utf-8', self::encoding(), $custoLabel), 'B'); $lineSize = $this->GetY() - $before; $this->SetXY($this->GetX() + $w[0] + ($delivery ? 15 : 0), $this->GetY() - $lineSize); $this->Cell($w[++$i], $lineSize, $product['product_reference'], 'B'); if (!$delivery) { $this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '').self::convertSign(Tools::displayPrice($unit_price, self::$currency, true)), 'B', 0, 'R'); if ($hasEcotax) { if (!empty($product['ecotax']) && $product['ecotax']>0) { $this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '').self::convertSign(Tools::displayPrice($product['ecotax'], self::$currency, true)), 'BT', 0, 'R'); } else { $this->Cell($w[++$i], $lineSize, '-', 'BT', 0, 'R'); } } } $this->Cell($w[++$i], $lineSize, (int)($product['customizationQuantityTotal']), 'B', 0, 'C'); if (!$delivery) { $this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '').self::convertSign(Tools::displayPrice($unit_price * (int)($product['customizationQuantityTotal']), self::$currency, true)), 'B', 0, 'R'); } $this->Ln(); $i = -1; $total_with_tax = $unit_with_tax * $productQuantity; $total_without_tax = $unit_without_tax * $productQuantity; } if ($delivery) $this->SetX(25); if ($productQuantity) { $before = $this->GetY(); $fill = FALSE; if($productQuantity > 1) { $this->SetFont(self::fontname(), 'B', 7); $this->SetFillColor(240, 240, 240); $fill = TRUE; } else { $this->SetFont(self::fontname(), '', 7); } $this->MultiCell($w[++$i], 5, Tools::iconv('utf-8', self::encoding(), $product['product_name']), 'BT', 'L', $fill); $lineSize = $this->GetY() - $before; $this->SetXY($this->GetX() + $w[0] + ($delivery ? 15 : 0), $this->GetY() - $lineSize); $this->Cell($w[++$i], $lineSize, ($product['product_reference'] ? Tools::iconv('utf-8', self::encoding(), $product['product_reference']) : '--'), 'BT'); if (!$delivery) { $this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '').self::convertSign(Tools::displayPrice($unit_price, self::$currency, true)), 'BT', 0, 'R'); if ($hasEcotax) { if (!empty($product['ecotax']) && $product['ecotax']>0) { $this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '').self::convertSign(Tools::displayPrice($product['ecotax'], self::$currency, true)), 'BT', 0, 'R'); } else { $this->Cell($w[++$i], $lineSize, '-', 'BT', 0, 'R'); } } } global $cookie; error_log("logt" . serialize($cookie)); if(method_exists($cookie, 'isLoggedBack') && $cookie->isLoggedBack()) { $this->Cell($w[++$i], $lineSize, $productQuantity.(self::$orderSlip? '': ($product['product_quantity_return'] > 0? ' (-'.$product['product_quantity_return'].')': ($product['product_quantity_refunded'] > 0? ' (-'.$product['product_quantity_refunded'].')': '' ))), 'BT', 0, 'C', $fill); } else { $this->Cell($w[++$i], $lineSize, $productQuantity, 'BT', 0, 'C', $fill); } if (!$delivery) $this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '').self::convertSign(Tools::displayPrice($final_price, self::$currency, true)), 'BT', 0, 'R'); $this->Ln(); } } if (!sizeof(self::$order->getDiscounts()) AND !$delivery) $this->Cell(array_sum($w), 0, ''); } private function ProdTabHeaderWithEcotax($delivery = false) { // label, alignment (L: left, R: right, C: center) if (!$delivery) { $header = array( array(self::l('Description'), 'L'), array(self::l('Reference'), 'L'), array(self::l('U. price'), 'R'), array(self::l('Ecotax incl.'), 'R'), array(self::l('Qty'), 'C'), array(self::l('Total'), 'R') ); $w = &$this->cell_widths['with_ecotax']; } else { $header = array( array(self::l('Description'), 'L'), array(self::l('Reference'), 'L'), array(self::l('Qty'), 'C'), ); $w = &$this->cell_widths['delivery']; } $this->SetFont(self::fontname(), 'B', 8); $this->SetFillColor(240, 240, 240); if ($delivery) $this->SetX(25); for ($i = 0; $i < sizeof($header); $i++) $this->Cell($w[$i], 5, $header[$i][0], 'T', 0, $header[$i][1], 1); $this->Ln(); $this->SetFont(self::fontname(), '', 8); } }