/**
  * Generate the module
  */
 protected function compile()
 {
     $objCart = Isotope::getCart();
     $objAddress = $objCart->getShippingAddress();
     $this->Template->showResults = false;
     $this->Template->requiresShipping = false;
     // There is no address
     if (!$objAddress->id) {
         return;
     }
     $this->Template->showResults = true;
     $arrMethods = array();
     // Get the shipping methods
     if ($objAddress->id && $objCart->requiresShipping()) {
         $this->Template->requiresShipping = true;
         $objShippingMethods = Shipping::findMultipleByIds($this->arrShippingMethods);
         /* @var Shipping $objShipping */
         foreach ($objShippingMethods as $objShipping) {
             if ($objShipping->isAvailable()) {
                 $fltPrice = $objShipping->getPrice();
                 $arrMethods[] = array('label' => $objShipping->getLabel(), 'price' => $fltPrice, 'formatted_price' => Isotope::formatPriceWithCurrency($fltPrice), 'shipping' => $objShipping);
             }
         }
         RowClass::withKey('rowClass')->addCount('row_')->addFirstLast('row_')->addEvenOdd('row_')->applyTo($arrMethods);
     }
     $this->Template->shippingMethods = $arrMethods;
 }
 public function generate(IsotopeProduct $objProduct, array $arrOptions = array())
 {
     $arrData = deserialize($objProduct->{$this->field_name});
     if (is_array($arrData) && $arrData['unit'] > 0 && $arrData['value'] != '') {
         $objBasePrice = \Isotope\Model\BasePrice::findByPk((int) $arrData['unit']);
         if (null !== $objBasePrice && null !== $objProduct->getPrice()) {
             return sprintf($objBasePrice->getLabel(), Isotope::formatPriceWithCurrency($objProduct->getPrice()->getAmount() / $arrData['value'] * $objBasePrice->amount), $arrData['value']);
         }
     }
     return '';
 }
Beispiel #3
0
 /**
  * Generate the module
  * @return void
  */
 protected function compile()
 {
     $arrOrders = array();
     $objOrders = Order::findBy(array('order_status>0', 'member=?', 'config_id IN (?)'), array(\FrontendUser::getInstance()->id, implode("','", $this->iso_config_ids)), array('order' => 'locked DESC'));
     // No orders found, just display an "empty" message
     if (null === $objOrders) {
         $this->Template = new \Isotope\Template('mod_message');
         $this->Template->type = 'empty';
         $this->Template->message = $GLOBALS['TL_LANG']['ERR']['emptyOrderHistory'];
         return;
     }
     while ($objOrders->next()) {
         Isotope::setConfig($objOrders->current()->getRelated('config_id'));
         $arrOrders[] = array('collection' => $objOrders->current(), 'raw' => $objOrders->current()->row(), 'date' => Format::date($objOrders->current()->locked), 'time' => Format::time($objOrders->current()->locked), 'datime' => Format::datim($objOrders->current()->locked), 'grandTotal' => Isotope::formatPriceWithCurrency($objOrders->current()->getTotal()), 'status' => $objOrders->current()->getStatusLabel(), 'link' => $this->jumpTo ? \Haste\Util\Url::addQueryString('uid=' . $objOrders->current()->uniqid, $this->jumpTo) : '', 'class' => $objOrders->current()->getStatusAlias());
     }
     RowClass::withKey('class')->addFirstLast()->addEvenOdd()->applyTo($arrOrders);
     $this->Template->orders = $arrOrders;
 }
Beispiel #4
0
 /**
  * Generate the order label and return it as string
  * @param   array
  * @param   string
  * @return  string
  */
 public function getOrderLabel($row, $label, \DataContainer $dc, $args)
 {
     /** @var Order $objOrder */
     $objOrder = Order::findByPk($row['id']);
     if (null === $objOrder) {
         return $args;
     }
     // Override system to correctly format currencies etc
     Isotope::setConfig($objOrder->getRelated('config_id'));
     $objAddress = $objOrder->getBillingAddress();
     if (null !== $objAddress) {
         $arrTokens = $objAddress->getTokens(Isotope::getConfig()->getBillingFieldsConfig());
         $args[2] = $arrTokens['hcard_fn'];
     }
     $args[3] = Isotope::formatPriceWithCurrency($row['grandTotal']);
     /** @var \Isotope\Model\OrderStatus $objStatus */
     if (($objStatus = $objOrder->getRelated('order_status')) !== null) {
         $args[4] = '<span style="' . $objStatus->getColorStyles() . '">' . $objOrder->getStatusLabel() . '</span>';
     } else {
         $args[4] = '<span>' . $objOrder->getStatusLabel() . '</span>';
     }
     return $args;
 }
Beispiel #5
0
 protected function formatValues($arrData, $arrCurrencies)
 {
     // Format row totals
     foreach ($arrData['rows'] as $dateGroup => $arrRow) {
         if (is_array($arrRow['columns'][4]['value'])) {
             foreach ($arrRow['columns'][4]['value'] as $currency => $varValue) {
                 Isotope::setConfig(Config::findByPk($arrCurrencies[$currency]));
                 $arrData['rows'][$dateGroup]['columns'][4]['value'][$currency] = Isotope::formatPriceWithCurrency($varValue);
             }
         }
     }
     // Format footer totals
     foreach ($arrData['footer'][4]['value'] as $currency => $varValue) {
         Isotope::setConfig(Config::findByPk($arrCurrencies[$currency]));
         $arrData['footer'][4]['value'][$currency] = Isotope::formatPriceWithCurrency($varValue);
     }
     if (empty($arrData['footer'][4]['value'])) {
         $arrData['footer'][4]['value'] = 0;
     }
     return $arrData;
 }
Beispiel #6
0
    /**
     * Generate HTML table for associative array values
     * @param   array
     * @param   IsotopeProduct
     * @return  string
     */
    protected function generateTable(array $arrValues, IsotopeProduct $objProduct)
    {
        $arrFormat = $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$this->field_name]['tableformat'];
        $last = count($arrValues[0]) - 1;
        $strBuffer = '
<table class="' . $this->field_name . '">
  <thead>
    <tr>';
        foreach (array_keys($arrValues[0]) as $i => $name) {
            if ($arrFormat[$name]['doNotShow']) {
                continue;
            }
            $label = $arrFormat[$name]['label'] ? $arrFormat[$name]['label'] : $name;
            $strBuffer .= '
      <th class="head_' . $i . ($i == 0 ? ' head_first' : '') . ($i == $last ? ' head_last' : '') . (!is_numeric($name) ? ' ' . standardize($name) : '') . '">' . $label . '</th>';
        }
        $strBuffer .= '
    </tr>
  </thead>
  <tbody>';
        foreach ($arrValues as $r => $row) {
            $strBuffer .= '
    <tr class="row_' . $r . ($r == 0 ? ' row_first' : '') . ($r == $last ? ' row_last' : '') . ' ' . ($r % 2 ? 'odd' : 'even') . '">';
            $c = -1;
            foreach ($row as $name => $value) {
                if ($arrFormat[$name]['doNotShow']) {
                    continue;
                }
                if ($arrFormat[$name]['rgxp'] == 'price') {
                    $intTax = (int) $row['tax_class'];
                    $value = Isotope::formatPriceWithCurrency(Isotope::calculatePrice($value, $objProduct, $this->field_name, $intTax));
                } else {
                    $value = $arrFormat[$name]['format'] ? sprintf($arrFormat[$name]['format'], $value) : $value;
                }
                $strBuffer .= '
      <td class="col_' . ++$c . ($c == 0 ? ' col_first' : '') . ($c == $i ? ' col_last' : '') . ' ' . standardize($name) . '">' . $value . '</td>';
            }
            $strBuffer .= '
    </tr>';
        }
        $strBuffer .= '
  </tbody>
</table>';
        return $strBuffer;
    }
 /**
  * Generate price for HTML rendering
  *
  * @param bool  $blnShowTiers
  * @param int   $intQuantity
  * @param array $arrOptions
  *
  * @return string
  */
 public function generate($blnShowTiers = false, $intQuantity = 1, array $arrOptions = array())
 {
     $blnShowFrom = false;
     $fltPrice = $this->getAmount($intQuantity, $arrOptions);
     if ($blnShowTiers) {
         $fltLowest = $this->getLowestAmount($arrOptions);
         if ($fltPrice != $fltLowest) {
             $blnShowFrom = true;
             $fltPrice = $fltLowest;
         }
     }
     $strPrice = Isotope::formatPriceWithCurrency($fltPrice);
     if ($blnShowFrom) {
         return sprintf($GLOBALS['TL_LANG']['MSC']['priceRangeLabel'], $strPrice);
     }
     $fltOriginalPrice = $this->getOriginalAmount($intQuantity, $arrOptions);
     if ($fltPrice < $fltOriginalPrice) {
         $strOriginalPrice = Isotope::formatPriceWithCurrency($fltOriginalPrice);
         // @deprecated remove <strike>, should be a CSS setting
         return '<div class="original_price"><strike>' . $strOriginalPrice . '</strike></div><div class="price">' . $strPrice . '</div>';
     }
     return $strPrice;
 }
Beispiel #8
0
 /**
  * Format surcharge prices
  *
  * @param ProductCollectionSurcharge[] $arrSurcharges
  *
  * @return array
  */
 public static function formatSurcharges($arrSurcharges)
 {
     $i = 0;
     $arrReturn = array();
     foreach ($arrSurcharges as $k => $objSurcharge) {
         $arrReturn[$k] = $objSurcharge->row();
         $arrReturn[$k]['price'] = Isotope::formatPriceWithCurrency($objSurcharge->price, true, null, $objSurcharge->applyRoundingIncrement);
         $arrReturn[$k]['total_price'] = Isotope::formatPriceWithCurrency($objSurcharge->total_price, true, null, $objSurcharge->applyRoundingIncrement);
         $arrReturn[$k]['tax_free_total_price'] = Isotope::formatPriceWithCurrency($objSurcharge->tax_free_total_price, true, null, $objSurcharge->applyRoundingIncrement);
         $arrReturn[$k]['rowClass'] = trim('foot_' . ++$i . ' ' . $objSurcharge->rowClass);
         $arrReturn[$k]['tax_id'] = $objSurcharge->getTaxNumbers();
         $arrReturn[$k]['raw'] = $objSurcharge->row();
         $arrReturn[$k]['surcharge'] = $objSurcharge;
     }
     return $arrReturn;
 }
Beispiel #9
0
 /**
  * Generate item array for template
  * @param   ProductCollectionItem
  * @return  array
  */
 protected function generateItem(ProductCollectionItem $objItem)
 {
     $blnHasProduct = $objItem->hasProduct();
     $objProduct = $objItem->getProduct();
     // Set the active product for insert tags replacement
     if ($blnHasProduct) {
         Product::setActive($objProduct);
     }
     $arrCSS = $blnHasProduct ? deserialize($objProduct->cssID, true) : array();
     $arrItem = array('id' => $objItem->id, 'sku' => $objItem->getSku(), 'name' => $objItem->getName(), 'options' => Isotope::formatOptions($objItem->getOptions()), 'quantity' => $objItem->quantity, 'price' => Isotope::formatPriceWithCurrency($objItem->getPrice()), 'tax_free_price' => Isotope::formatPriceWithCurrency($objItem->getTaxFreePrice()), 'total' => Isotope::formatPriceWithCurrency($objItem->getTotalPrice()), 'tax_free_total' => Isotope::formatPriceWithCurrency($objItem->getTaxFreeTotalPrice()), 'tax_id' => $objItem->tax_id, 'href' => false, 'hasProduct' => $blnHasProduct, 'product' => $objProduct, 'item' => $objItem, 'raw' => $objItem->row(), 'rowClass' => trim('product ' . ($blnHasProduct && $objProduct->isNew() ? 'new ' : '') . $arrCSS[1]));
     if (null !== $objItem->getRelated('jumpTo') && $blnHasProduct && $objProduct->isAvailableInFrontend()) {
         $arrItem['href'] = $objProduct->generateUrl($objItem->getRelated('jumpTo'));
     }
     Product::unsetActive();
     return $arrItem;
 }
Beispiel #10
0
 /**
  * Retrieve the array of notification data for parsing simple tokens
  *
  * @param int $intNotification
  *
  * @return array
  */
 public function getNotificationTokens($intNotification)
 {
     /** @type \Isotope\Model\Config $objConfig */
     $objConfig = $this->getRelated('config_id');
     $arrTokens = deserialize($this->email_data, true);
     $arrTokens['uniqid'] = $this->uniqid;
     $arrTokens['order_status_id'] = $this->order_status;
     $arrTokens['order_status'] = $this->getStatusLabel();
     $arrTokens['recipient_email'] = $this->getEmailRecipient();
     $arrTokens['order_id'] = $this->id;
     $arrTokens['order_items'] = $this->sumItemsQuantity();
     $arrTokens['order_products'] = $this->countItems();
     $arrTokens['order_subtotal'] = Isotope::formatPriceWithCurrency($this->getSubtotal(), false);
     $arrTokens['order_total'] = Isotope::formatPriceWithCurrency($this->getTotal(), false);
     $arrTokens['document_number'] = $this->document_number;
     $arrTokens['cart_html'] = '';
     $arrTokens['cart_text'] = '';
     $arrTokens['document'] = '';
     // Add all the collection fields
     foreach ($this->row() as $k => $v) {
         $arrTokens['collection_' . $k] = $v;
     }
     // Add billing/customer address fields
     if (($objAddress = $this->getBillingAddress()) !== null) {
         foreach ($objAddress->row() as $k => $v) {
             $arrTokens['billing_address_' . $k] = Format::dcaValue($objAddress->getTable(), $k, $v);
             // @deprecated (use ##billing_address_*##)
             $arrTokens['billing_' . $k] = $arrTokens['billing_address_' . $k];
         }
         $arrTokens['billing_address'] = $objAddress->generate($objConfig->getBillingFieldsConfig());
         // @deprecated (use ##billing_address##)
         $arrTokens['billing_address_text'] = $arrTokens['billing_address'];
     }
     // Add shipping address fields
     if (($objAddress = $this->getShippingAddress()) !== null) {
         foreach ($objAddress->row() as $k => $v) {
             $arrTokens['shipping_address_' . $k] = Format::dcaValue($objAddress->getTable(), $k, $v);
             // @deprecated (use ##billing_address_*##)
             $arrTokens['shipping_' . $k] = $arrTokens['shipping_address_' . $k];
         }
         $arrTokens['shipping_address'] = $objAddress->generate($objConfig->getShippingFieldsConfig());
         // Shipping address equals billing address
         // @deprecated (use ##shipping_address##)
         if ($objAddress->id == $this->getBillingAddress()->id) {
             $arrTokens['shipping_address_text'] = $this->requiresPayment() ? $GLOBALS['TL_LANG']['MSC']['useBillingAddress'] : $GLOBALS['TL_LANG']['MSC']['useCustomerAddress'];
         } else {
             $arrTokens['shipping_address_text'] = $arrTokens['shipping_address'];
         }
     }
     // Add payment method info
     if ($this->hasPayment() && ($objPayment = $this->getPaymentMethod()) !== null) {
         $arrTokens['payment_id'] = $objPayment->id;
         $arrTokens['payment_label'] = $objPayment->getLabel();
         $arrTokens['payment_note'] = $objPayment->note;
     }
     // Add shipping method info
     if ($this->hasShipping() && ($objShipping = $this->getShippingMethod()) !== null) {
         $arrTokens['shipping_id'] = $objShipping->id;
         $arrTokens['shipping_label'] = $objShipping->getLabel();
         $arrTokens['shipping_note'] = $objShipping->note;
     }
     // Add config fields
     if ($this->getRelated('config_id') !== null) {
         foreach ($this->getRelated('config_id')->row() as $k => $v) {
             $arrTokens['config_' . $k] = Format::dcaValue($this->getRelated('config_id')->getTable(), $k, $v);
         }
     }
     // Add member fields
     if ($this->member > 0 && $this->getRelated('member') !== null) {
         foreach ($this->getRelated('member')->row() as $k => $v) {
             $arrTokens['member_' . $k] = Format::dcaValue($this->getRelated('member')->getTable(), $k, $v);
         }
     }
     if ($intNotification > 0 && ($objNotification = Notification::findByPk($intNotification)) !== null) {
         $objTemplate = new \Isotope\Template($objNotification->iso_collectionTpl);
         $objTemplate->isNotification = true;
         $this->addToTemplate($objTemplate, array('gallery' => $objNotification->iso_gallery, 'sorting' => $this->getItemsSortingCallable($objNotification->iso_orderCollectionBy)));
         $arrTokens['cart_html'] = Haste::getInstance()->call('replaceInsertTags', array($objTemplate->parse(), false));
         $objTemplate->textOnly = true;
         $arrTokens['cart_text'] = strip_tags(Haste::getInstance()->call('replaceInsertTags', array($objTemplate->parse(), true)));
         // Generate and "attach" document
         /** @var \Isotope\Interfaces\IsotopeDocument $objDocument */
         if ($objNotification->iso_document > 0 && ($objDocument = Document::findByPk($objNotification->iso_document)) !== null) {
             $strFilePath = $objDocument->outputToFile($this, TL_ROOT . '/system/tmp');
             $arrTokens['document'] = str_replace(TL_ROOT . '/', '', $strFilePath);
         }
     }
     // !HOOK: add custom email tokens
     if (isset($GLOBALS['ISO_HOOKS']['getOrderNotificationTokens']) && is_array($GLOBALS['ISO_HOOKS']['getOrderNotificationTokens'])) {
         foreach ($GLOBALS['ISO_HOOKS']['getOrderNotificationTokens'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $arrTokens = $objCallback->{$callback}[1]($this, $arrTokens);
         }
     }
     return $arrTokens;
 }
Beispiel #11
0
 /**
  * Get error messages for the cart
  * @return  array
  */
 public function getErrors()
 {
     $arrErrors = parent::getErrors();
     if (Isotope::getConfig()->cartMinSubtotal > 0 && Isotope::getConfig()->cartMinSubtotal > $this->getSubtotal()) {
         $arrErrors[] = sprintf($GLOBALS['TL_LANG']['ERR']['cartMinSubtotal'], Isotope::formatPriceWithCurrency(Isotope::getConfig()->cartMinSubtotal));
     }
     return $arrErrors;
 }
 /**
  * Get formatted label for the attribute option
  *
  * @param IsotopeProduct $objProduct
  *
  * @return string
  */
 public function getLabel(IsotopeProduct $objProduct = null)
 {
     $strLabel = $this->label;
     /** @type Attribute $objAttribute */
     $objAttribute = null;
     switch ($this->ptable) {
         case 'tl_iso_product':
             $objAttribute = Attribute::findByFieldName($this->field_name);
             break;
         case 'tl_iso_attribute':
             $objAttribute = Attribute::findByPk($this->pid);
             break;
     }
     if (null !== $objAttribute && !$objAttribute->isVariantOption() && $this->price != '') {
         $strLabel .= ' (';
         if (!$this->isPercentage() || null !== $objProduct) {
             $strPrice = Isotope::formatPriceWithCurrency($this->getPrice($objProduct), false);
         } else {
             $strPrice = $this->price;
         }
         $strLabel .= $this->isFromPrice($objProduct) ? sprintf($GLOBALS['TL_LANG']['MSC']['priceRangeLabel'], $strPrice) : $strPrice;
         $strLabel .= ')';
     }
     return $strLabel;
 }
Beispiel #13
0
 /**
  * Replace insert tag for a product collection.
  *
  * @param IsotopeProductCollection $collection
  * @param array                    $tokens
  *
  * @return string
  */
 private function getValueForCollectionTag(IsotopeProductCollection $collection, array $tokens)
 {
     switch ($tokens[1]) {
         case 'items':
             return $collection->countItems();
         case 'quantity':
             return $collection->sumItemsQuantity();
         case 'items_label':
             $intCount = $collection->countItems();
             if (!$intCount) {
                 return '';
             }
             if ($intCount == 1) {
                 return '(' . $GLOBALS['TL_LANG']['MSC']['productSingle'] . ')';
             } else {
                 return sprintf('(' . $GLOBALS['TL_LANG']['MSC']['productMultiple'] . ')', $intCount);
             }
             break;
         case 'quantity_label':
             $intCount = $collection->sumItemsQuantity();
             if (!$intCount) {
                 return '';
             }
             if ($intCount == 1) {
                 return '(' . $GLOBALS['TL_LANG']['MSC']['productSingle'] . ')';
             } else {
                 return sprintf('(' . $GLOBALS['TL_LANG']['MSC']['productMultiple'] . ')', $intCount);
             }
             break;
         case 'subtotal':
             return Isotope::formatPriceWithCurrency($collection->getSubtotal());
         case 'taxfree_subtotal':
             return Isotope::formatPriceWithCurrency($collection->getTaxFreeSubtotal());
         case 'total':
             return Isotope::formatPriceWithCurrency($collection->getTotal());
         case 'taxfree_total':
             return Isotope::formatPriceWithCurrency($collection->getTaxFreeTotal());
         case 'billing_address':
             if (!$collection instanceof IsotopeOrderableCollection || ($address = $collection->getBillingAddress()) === null) {
                 return '';
             }
             return $this->getValueForAddressTag($address, $tokens[2]);
         case 'shipping_address':
             if (!$collection instanceof IsotopeOrderableCollection || !$collection->hasShipping() || ($address = $collection->getShippingAddress()) === null) {
                 return '';
             }
             return $this->getValueForAddressTag($address, $tokens[2]);
         default:
             return $collection->{$tokens[1]};
     }
 }
 /**
  * Generate price for HTML rendering
  *
  * @param bool  $blnShowTiers
  * @param int   $intQuantity
  * @param array $arrOptions
  *
  * @return string
  */
 public function generate($blnShowTiers = false, $intQuantity = 1, array $arrOptions = array())
 {
     if (count($this->arrModels) > 1) {
         $fltPrice = null;
         $fltOriginalPrice = null;
         $arrPrices = array();
         /** @var \Isotope\Model\ProductPrice $objPrice */
         foreach ($this->arrModels as $objPrice) {
             $fltNew = $blnShowTiers ? $objPrice->getLowestAmount($arrOptions) : $objPrice->getAmount($intQuantity, $arrOptions);
             $arrPrices[] = $fltNew;
             if (null === $fltPrice || $fltNew < $fltPrice) {
                 $fltPrice = $fltNew;
                 $fltOriginalPrice = $objPrice->getOriginalAmount($intQuantity, $arrOptions);
             }
         }
         $arrPrices = array_unique($arrPrices);
         $blnShowFrom = count($arrPrices) > 1;
         if ($blnShowFrom) {
             return sprintf($GLOBALS['TL_LANG']['MSC']['priceRangeLabel'], Isotope::formatPriceWithCurrency($fltPrice));
         } elseif ($fltPrice < $fltOriginalPrice) {
             $strPrice = Isotope::formatPriceWithCurrency($fltPrice);
             $strOriginalPrice = Isotope::formatPriceWithCurrency($fltOriginalPrice);
             return '<div class="original_price"><strike>' . $strOriginalPrice . '</strike></div><div class="price">' . $strPrice . '</div>';
         } else {
             return Isotope::formatPriceWithCurrency($fltPrice);
         }
     } else {
         return $this->current()->generate($blnShowTiers, $intQuantity, $arrOptions);
     }
 }
Beispiel #15
0
 /**
  * Generate price for HTML rendering
  * @param   bool
  * @return  string
  */
 public function generate($blnShowTiers = false)
 {
     $blnShowFrom = false;
     $fltPrice = $this->getAmount();
     if ($blnShowTiers) {
         $fltLowest = $this->getLowestAmount();
         if ($fltPrice != $fltLowest) {
             $blnShowFrom = true;
             $fltPrice = $fltLowest;
         }
     }
     $strPrice = Isotope::formatPriceWithCurrency($fltPrice);
     if ($blnShowFrom) {
         return sprintf($GLOBALS['TL_LANG']['MSC']['priceRangeLabel'], $strPrice);
     }
     $fltOriginalPrice = $this->getOriginalAmount();
     if ($fltPrice < $fltOriginalPrice) {
         $strOriginalPrice = Isotope::formatPriceWithCurrency($fltOriginalPrice);
         return '<div class="original_price"><strike>' . $strOriginalPrice . '</strike></div><div class="price">' . $strPrice . '</div>';
     }
     return $strPrice;
 }
Beispiel #16
0
 protected function compile()
 {
     $periodFactory = new PeriodFactory();
     $arrSession = \Session::getInstance()->get('iso_reports');
     $strPeriod = (string) $arrSession[$this->name]['period'];
     $intColumns = (int) $arrSession[$this->name]['columns'];
     $blnVariants = (bool) $arrSession[$this->name]['variants'];
     $intStatus = (int) $arrSession[$this->name]['iso_status'];
     if ($arrSession[$this->name]['from'] == '') {
         $intStart = strtotime('-' . ($intColumns - 1) . ' ' . $strPeriod);
     } else {
         $intStart = (int) $arrSession[$this->name]['from'];
     }
     $period = $periodFactory->create($strPeriod);
     $intStart = $period->getPeriodStart($intStart);
     $dateFrom = $period->getKey($intStart);
     $dateTo = $period->getKey(strtotime('+ ' . ($intColumns - 1) . ' ' . $strPeriod, $intStart));
     $arrData = array('rows' => array());
     $arrData['header'] = $this->getHeader($period, $intStart, $intColumns);
     $groupVariants = $blnVariants ? 'p1.id' : 'IF(p1.pid=0, p1.id, p1.pid)';
     $objProducts = \Database::getInstance()->query("\n            SELECT\n                IFNULL({$groupVariants}, i.product_id) AS product_id,\n                IFNULL(p1.name, i.name) AS variant_name,\n                IFNULL(p2.name, i.name) AS product_name,\n                p1.sku AS product_sku,\n                p2.sku AS variant_sku,\n                IF(p1.pid=0, p1.type, p2.type) AS type,\n                i.configuration AS product_configuration,\n                SUM(i.quantity) AS quantity,\n                SUM(i.tax_free_price * i.quantity) AS total,\n                " . $period->getSqlField($this->strDateField) . " AS dateGroup\n            FROM " . ProductCollectionItem::getTable() . " i\n            LEFT JOIN " . ProductCollection::getTable() . " o ON i.pid=o.id\n            LEFT JOIN " . OrderStatus::getTable() . " os ON os.id=o.order_status\n            LEFT OUTER JOIN " . Product::getTable() . " p1 ON i.product_id=p1.id\n            LEFT OUTER JOIN " . Product::getTable() . " p2 ON p1.pid=p2.id\n            WHERE o.type='order' AND o.order_status>0 AND o.locked!=''\n                " . ($intStatus > 0 ? " AND o.order_status=" . $intStatus : '') . "\n                " . $this->getProductProcedure('p1') . "\n                " . $this->getConfigProcedure('o', 'config_id') . "\n            GROUP BY dateGroup, product_id\n            HAVING dateGroup>={$dateFrom} AND dateGroup<={$dateTo}\n        ");
     // Cache product types so call to findByPk() will trigger the registry
     ProductType::findMultipleByIds($objProducts->fetchEach('type'));
     $arrRaw = array();
     $objProducts->reset();
     // Prepare product data
     while ($objProducts->next()) {
         $arrAttributes = array();
         $arrVariantAttributes = array();
         $blnHasVariants = false;
         // Can't use it without a type
         if ($objProducts->type > 0 && ($objType = ProductType::findByPk($objProducts->type)) !== null) {
             /** @type ProductType $objType */
             $arrAttributes = $objType->getAttributes();
             $arrVariantAttributes = $objType->getVariantAttributes();
             $blnHasVariants = $objType->hasVariants();
             $product_type_name = $objType->name;
         }
         $arrOptions = array('name' => $objProducts->variant_name);
         // Use product title if name is not a variant attribute
         if ($blnHasVariants && !in_array('name', $arrVariantAttributes)) {
             $arrOptions['name'] = $objProducts->product_name;
         }
         $strSku = $blnHasVariants ? $objProducts->variant_sku : $objProducts->product_sku;
         if (in_array('sku', $arrAttributes) && $strSku != '') {
             $arrOptions['name'] = sprintf('%s <span style="color:#b3b3b3; padding-left:3px;">[%s]</span>', $arrOptions['name'], $strSku);
         }
         if ($blnVariants && $blnHasVariants) {
             if (in_array('sku', $arrVariantAttributes) && $objProducts->product_sku != '') {
                 $arrOptions['name'] = sprintf('%s <span style="color:#b3b3b3; padding-left:3px;">[%s]</span>', $arrOptions['name'], $objProducts->product_sku);
             }
             foreach (deserialize($objProducts->product_configuration, true) as $strName => $strValue) {
                 if (isset($GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strName])) {
                     $strValue = $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strName]['options'][$strValue] ? $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strName]['options'][$strValue] : $strValue;
                     $strName = $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strName]['label'][0] ? $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strName]['label'][0] : $strName;
                 }
                 $arrOptions[] = '<span class="variant">' . $strName . ': ' . $strValue . '</span>';
             }
         }
         $arrOptions['name'] = '<span class="product">' . $arrOptions['name'] . '</span>';
         $arrRaw[$objProducts->product_id]['name'] = implode('<br>', $arrOptions);
         $arrRaw[$objProducts->product_id]['product_type_name'] = $product_type_name;
         $arrRaw[$objProducts->product_id][$objProducts->dateGroup] = (double) $arrRaw[$objProducts->product_id][$objProducts->dateGroup] + (double) $objProducts->total;
         $arrRaw[$objProducts->product_id][$objProducts->dateGroup . '_quantity'] = (int) $arrRaw[$objProducts->product_id][$objProducts->dateGroup . '_quantity'] + (int) $objProducts->quantity;
         $arrRaw[$objProducts->product_id]['total'] = (double) $arrRaw[$objProducts->product_id]['total'] + (double) $objProducts->total;
         $arrRaw[$objProducts->product_id]['quantity'] = (int) $arrRaw[$objProducts->product_id]['quantity'] + (int) $objProducts->quantity;
     }
     // Prepare columns
     $arrColumns = array();
     for ($i = 0; $i < $intColumns; $i++) {
         $arrColumns[] = $period->getKey($intStart);
         $intStart = $period->getNext($intStart);
     }
     $arrFooter = array();
     // Sort the data
     if ($arrSession[$this->name]['tl_sort'] == 'product_name') {
         usort($arrRaw, function ($a, $b) {
             return strcasecmp($a['name'], $b['name']);
         });
     } else {
         usort($arrRaw, function ($a, $b) {
             return $a['total'] == $b['total'] ? 0 : ($a['total'] < $b['total'] ? 1 : -1);
         });
     }
     // Generate data
     foreach ($arrRaw as $arrProduct) {
         $arrRow = array(array('value' => array($arrProduct['name'], sprintf('<span style="color:#b3b3b3;">[%s]</span>', $arrProduct['product_type_name']))));
         $arrFooter[0] = array('value' => $GLOBALS['TL_LANG']['ISO_REPORT']['sums']);
         foreach ($arrColumns as $i => $column) {
             $arrRow[$i + 1] = array('value' => Isotope::formatPriceWithCurrency($arrProduct[$column]) . ($arrProduct[$column . '_quantity'] !== null ? '<br><span class="variant">' . Isotope::formatItemsString($arrProduct[$column . '_quantity']) . '</span>' : ''));
             $arrFooter[$i + 1] = array('total' => $arrFooter[$i + 1]['total'] + $arrProduct[$column], 'quantity' => $arrFooter[$i + 1]['quantity'] + $arrProduct[$column . '_quantity']);
         }
         $arrRow[$i + 2] = array('value' => Isotope::formatPriceWithCurrency($arrProduct['total']) . ($arrProduct['quantity'] !== null ? '<br><span class="variant">' . Isotope::formatItemsString($arrProduct['quantity']) . '</span>' : ''));
         $arrFooter[$i + 2] = array('total' => $arrFooter[$i + 2]['total'] + $arrProduct['total'], 'quantity' => $arrFooter[$i + 2]['quantity'] + $arrProduct['quantity']);
         $arrData['rows'][] = array('columns' => $arrRow);
     }
     for ($i = 1; $i < count($arrFooter); $i++) {
         $arrFooter[$i]['value'] = Isotope::formatPriceWithCurrency($arrFooter[$i]['total']) . '<br><span class="variant">' . Isotope::formatItemsString($arrFooter[$i]['quantity']) . '</span>';
         unset($arrFooter[$i]['total']);
     }
     $arrData['footer'] = $arrFooter;
     $this->Template->data = $arrData;
 }
 /**
  * Generate the checkout step
  * @return  string
  */
 public function generate()
 {
     $arrModules = array();
     $arrOptions = array();
     $arrIds = deserialize($this->objModule->iso_payment_modules);
     if (!empty($arrIds) && is_array($arrIds)) {
         $arrColumns = array('id IN (' . implode(',', $arrIds) . ')');
         if (BE_USER_LOGGED_IN !== true) {
             $arrColumns[] = "enabled='1'";
         }
         /** @type Payment[] $objModules */
         $objModules = Payment::findBy($arrColumns, null, array('order' => \Database::getInstance()->findInSet('id', $arrIds)));
         if (null !== $objModules) {
             foreach ($objModules as $objModule) {
                 if (!$objModule->isAvailable()) {
                     continue;
                 }
                 $strLabel = $objModule->getLabel();
                 $fltPrice = $objModule->getPrice();
                 if ($fltPrice != 0) {
                     if ($objModule->isPercentage()) {
                         $strLabel .= ' (' . $objModule->getPercentageLabel() . ')';
                     }
                     $strLabel .= ': ' . Isotope::formatPriceWithCurrency($fltPrice);
                 }
                 if ($objModule->note != '') {
                     $strLabel .= '<span class="note">' . $objModule->note . '</span>';
                 }
                 $arrOptions[] = array('value' => $objModule->id, 'label' => $strLabel);
                 $arrModules[$objModule->id] = $objModule;
             }
         }
     }
     if (empty($arrModules)) {
         $this->blnError = true;
         \System::log('No payment methods available for cart ID ' . Isotope::getCart()->id, __METHOD__, TL_ERROR);
         $objTemplate = new \Isotope\Template('mod_message');
         $objTemplate->class = 'payment_method';
         $objTemplate->hl = 'h2';
         $objTemplate->headline = $GLOBALS['TL_LANG']['MSC']['payment_method'];
         $objTemplate->type = 'error';
         $objTemplate->message = $GLOBALS['TL_LANG']['MSC']['noPaymentModules'];
         return $objTemplate->parse();
     }
     $strClass = $GLOBALS['TL_FFL']['radio'];
     /** @type \Widget $objWidget */
     $objWidget = new $strClass(array('id' => $this->getStepClass(), 'name' => $this->getStepClass(), 'mandatory' => true, 'options' => $arrOptions, 'value' => Isotope::getCart()->payment_id, 'storeValues' => true, 'tableless' => true));
     // If there is only one payment method, mark it as selected by default
     if (count($arrModules) == 1) {
         $objModule = reset($arrModules);
         $objWidget->value = $objModule->id;
         Isotope::getCart()->setPaymentMethod($objModule);
     }
     if (\Input::post('FORM_SUBMIT') == $this->objModule->getFormId()) {
         $objWidget->validate();
         if (!$objWidget->hasErrors()) {
             Isotope::getCart()->setPaymentMethod($arrModules[$objWidget->value]);
         }
     }
     $objTemplate = new \Isotope\Template('iso_checkout_payment_method');
     if (!Isotope::getCart()->hasPayment() || !isset($arrModules[Isotope::getCart()->payment_id])) {
         $this->blnError = true;
     }
     $objTemplate->headline = $GLOBALS['TL_LANG']['MSC']['payment_method'];
     $objTemplate->message = $GLOBALS['TL_LANG']['MSC']['payment_method_message'];
     $objTemplate->options = $objWidget->parse();
     $objTemplate->paymentMethods = $arrModules;
     return $objTemplate->parse();
 }
Beispiel #18
0
 /**
  * List all records with formatted currency
  * @param array
  * @return string
  */
 public function listRow($row)
 {
     $arrRate = deserialize($row['rate']);
     if ($row['config'] && !$arrRate['unit']) {
         Isotope::setConfig(Config::findByPk($row['config']));
         $strRate = Isotope::formatPriceWithCurrency($arrRate['value'], false);
     } else {
         $strRate = $arrRate['value'] . '%';
     }
     return sprintf('%s <span style="color:#b3b3b3; padding-left:3px;">[%s]</span>', $row['name'], $strRate);
 }