Exemplo n.º 1
0
 function saveForm()
 {
     $limit = new stdClass();
     $limit->limit_id = hikashop_getCID('limit_id');
     $formData = JRequest::getVar('data', array(), '', 'array');
     jimport('joomla.filter.filterinput');
     $safeHtmlFilter =& JFilterInput::getInstance(null, null, 1, 1);
     foreach ($formData['limit'] as $column => $value) {
         hikashop_secureField($column);
         if (is_array($value)) {
             $value = implode(',', $value);
         }
         $limit->{$column} = $safeHtmlFilter->clean(strip_tags($value), 'string');
     }
     if (!empty($limit->limit_start)) {
         $limit->limit_start = hikashop_getTime($limit->limit_start);
     }
     if (!empty($limit->limit_end)) {
         $limit->limit_end = hikashop_getTime($limit->limit_end);
     }
     if (empty($limit->limit_id)) {
         $limit->limit_created = time();
     }
     $limit->limit_modified = time();
     $status = $this->save($limit);
     return $status;
 }
Exemplo n.º 2
0
 function saveForm()
 {
     $discount = new stdClass();
     $discount->discount_id = hikashop_getCID('discount_id');
     $formData = JRequest::getVar('data', array(), '', 'array');
     jimport('joomla.filter.filterinput');
     $safeHtmlFilter =& JFilterInput::getInstance(null, null, 1, 1);
     $nameboxes = array('discount_product_id', 'discount_category_id', 'discount_zone_id');
     foreach ($formData['discount'] as $column => $value) {
         hikashop_secureField($column);
         if (in_array($column, $nameboxes)) {
             if ($column == 'discount_zone_id') {
                 $discount->{$column} = array();
                 foreach ($value as $i => $v) {
                     $discount->{$column}[] = $safeHtmlFilter->clean(strip_tags($v), 'string');
                 }
             } else {
                 JArrayHelper::toInteger($value);
             }
             $discount->{$column} = $value;
         } else {
             $discount->{$column} = $safeHtmlFilter->clean(strip_tags($value), 'string');
         }
     }
     foreach ($nameboxes as $namebox) {
         if (!isset($discount->{$namebox})) {
             $discount->{$namebox} = '';
         }
     }
     if (!empty($discount->discount_category_id) && !empty($discount->discount_product_id)) {
         $app = JFactory::getApplication();
         $app->enqueueMessage('If you set both categories and products in a discount/coupon, only the products will be taken into account.', 'error');
     }
     if (!empty($discount->discount_start)) {
         $discount->discount_start = hikashop_getTime($discount->discount_start);
     }
     if (!empty($discount->discount_end)) {
         $discount->discount_end = hikashop_getTime($discount->discount_end);
     }
     if (!empty($discount->discount_id) && !empty($discount->discount_code)) {
         $query = 'SELECT discount_id FROM ' . hikashop_table('discount') . ' WHERE discount_code  = ' . $this->database->Quote($discount->discount_code) . ' LIMIT 1';
         $this->database->setQuery($query);
         $res = $this->database->loadResult();
         if (!empty($res) && $res != $discount->discount_id) {
             $app = JFactory::getApplication();
             $app->enqueueMessage(JText::_('DISCOUNT_CODE_ALREADY_USED'), 'error');
             JRequest::setVar('fail', $discount);
             return false;
         }
     }
     $status = $this->save($discount);
     if (!$status) {
         JRequest::setVar('fail', $discount);
         $app = JFactory::getApplication();
         $app->enqueueMessage(JText::_('DISCOUNT_CODE_ALREADY_USED'));
     }
     return $status;
 }
Exemplo n.º 3
0
 function saveForm()
 {
     $element = new stdClass();
     $element->waitlist_id = hikashop_getCID('waitlist_id');
     $formData = JRequest::getVar('data', array(), '', 'array');
     jimport('joomla.filter.filterinput');
     $safeHtmlFilter =& JFilterInput::getInstance(null, null, 1, 1);
     foreach ($formData['waitlist'] as $column => $value) {
         hikashop_secureField($column);
         $element->{$column} = $safeHtmlFilter->clean(strip_tags($value), 'string');
     }
     if (!empty($element->date)) {
         $element->date = hikashop_getTime($element->date);
     }
     $result = $this->save($element);
     return $result;
 }
Exemplo n.º 4
0
 function saveForm()
 {
     $element = new stdClass();
     $element->badge_id = hikashop_getCID('badge_id');
     $formData = JRequest::getVar('data', array(), '', 'array');
     jimport('joomla.filter.filterinput');
     $safeHtmlFilter = JFilterInput::getInstance(null, null, 1, 1);
     $nameboxes = array('badge_discount_id', 'badge_category_id', 'badge_product_id');
     foreach ($formData['badge'] as $column => $value) {
         hikashop_secureField($column);
         if (in_array($column, $nameboxes)) {
             JArrayHelper::toInteger($value);
             $element->{$column} = ',' . implode(',', $value) . ',';
         } else {
             $element->{$column} = $safeHtmlFilter->clean(strip_tags($value), 'string');
         }
     }
     foreach ($nameboxes as $namebox) {
         if (!isset($element->{$namebox})) {
             $element->{$namebox} = '';
         }
     }
     if (!empty($element->badge_start)) {
         $element->badge_start = hikashop_getTime($element->badge_start);
     }
     if (!empty($element->badge_end)) {
         $element->badge_end = hikashop_getTime($element->badge_end);
     }
     $class = hikashop_get('class.file');
     $element->badge_image = $class->saveFile();
     if (empty($element->badge_image)) {
         unset($element->badge_image);
     }
     $status = $this->save($element);
     return $status;
 }
Exemplo n.º 5
0
 function saveForm()
 {
     $taxation = new stdClass();
     $taxation->taxation_id = hikashop_getCID('taxation_id');
     $formData = JRequest::getVar('data', array(), '', 'array');
     jimport('joomla.filter.filterinput');
     $safeHtmlFilter =& JFilterInput::getInstance(null, null, 1, 1);
     foreach ($formData['taxation'] as $column => $value) {
         hikashop_secureField($column);
         if (in_array($column, array('zone_namekey', 'taxation_type'))) {
             if (is_array($value)) {
                 $value = implode(',', $value);
                 if ($column == 'taxation_type' && !empty($value)) {
                     $value = ',' . $value . ',';
                 }
             }
         }
         $taxation->{$column} = $safeHtmlFilter->clean(strip_tags($value), 'string');
     }
     if (!isset($taxation->taxation_type)) {
         $taxation->taxation_type = '';
     }
     if (!isset($taxation->zone_namekey)) {
         $taxation->zone_namekey = '';
     }
     if (!empty($taxation->taxation_date_start)) {
         $taxation->taxation_date_start = hikashop_getTime($taxation->taxation_date_start);
     }
     if (!empty($taxation->taxation_date_end)) {
         $taxation->taxation_date_end = hikashop_getTime($taxation->taxation_date_end);
     }
     if (!empty($taxation->taxation_site_id) && $taxation->taxation_site_id == '[unselected]') {
         $taxation->taxation_site_id = '';
     }
     return $this->save($taxation);
 }
Exemplo n.º 6
0
 function listing()
 {
     $app = JFactory::getApplication();
     $pageInfo = new stdClass();
     $pageInfo->filter = new stdClass();
     $pageInfo->filter->order = new stdClass();
     $pageInfo->limit = new stdClass();
     $pageInfo->filter->order->value = $app->getUserStateFromRequest($this->paramBase . ".filter_order", 'filter_order', 'a.taxation_id', 'cmd');
     $pageInfo->filter->order->dir = $app->getUserStateFromRequest($this->paramBase . ".filter_order_Dir", 'filter_order_Dir', 'desc', 'word');
     $pageInfo->limit->value = $app->getUserStateFromRequest($this->paramBase . '.list_limit', 'limit', $app->getCfg('list_limit'), 'int');
     $pageInfo->limit->start = $app->getUserStateFromRequest($this->paramBase . '.limitstart', 'limitstart', 0, 'int');
     $pageInfo->filter->taxation_date_start = $app->getUserStateFromRequest(HIKASHOP_COMPONENT . '.taxation_date_start', 'taxation_date_start', '', 'string');
     $pageInfo->filter->taxation_date_end = $app->getUserStateFromRequest(HIKASHOP_COMPONENT . '.taxation_date_end', 'taxation_date_end', '', 'string');
     $pageInfo->filter->tax_namekey = $app->getUserStateFromRequest(HIKASHOP_COMPONENT . '.tax_namekey', 'tax_namekey', '', 'string');
     $pageInfo->filter->taxation_type = $app->getUserStateFromRequest(HIKASHOP_COMPONENT . '.taxation_type', 'taxation_type', '', 'string');
     $pageInfo->filter->taxation_site_id = $app->getUserStateFromRequest(HIKASHOP_COMPONENT . '.taxation_site_id', 'taxation_site_id', '', 'string');
     $database = JFactory::getDBO();
     $filters = array();
     if (!empty($pageInfo->filter->taxation_date_start)) {
         $filters[] = '(' . hikashop_getTime($pageInfo->filter->taxation_date_start) . '<=a.taxation_date_start' . ' OR ' . hikashop_getTime($pageInfo->filter->taxation_date_start) . '<=a.taxation_date_end' . ' OR a.taxation_date_end=0' . ')';
     }
     if (!empty($pageInfo->filter->taxation_date_end)) {
         $filters[] = '(' . 'a.taxation_date_start<=' . hikashop_getTime($pageInfo->filter->taxation_date_end) . ' OR (a.taxation_date_start<=a.taxation_date_end AND a.taxation_date_end<=' . hikashop_getTime($pageInfo->filter->taxation_date_end) . ')' . ' OR a.taxation_date_start=0' . ')';
     }
     if (!empty($pageInfo->filter->tax_namekey)) {
         $filters[] = 'a.tax_namekey=' . $database->Quote($pageInfo->filter->tax_namekey);
     }
     if (!empty($pageInfo->filter->taxation_type)) {
         $filters[] = '(a.taxation_type=' . $database->Quote($pageInfo->filter->taxation_type) . ' OR taxation_type LIKE \'%' . hikashop_getEscaped($pageInfo->filter->taxation_type, true) . '%\')';
     }
     if (!empty($pageInfo->filter->taxation_site_id) && $pageInfo->filter->taxation_site_id != '[unselected]') {
         $filters[] = 'a.taxation_site_id=' . $database->Quote($pageInfo->filter->taxation_site_id);
     }
     JPluginHelper::importPlugin('hikashop');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onBeforeTaxationListing', array($this->paramBase, &$this->extrafilters, &$pageInfo, &$filters));
     $order = '';
     if (!empty($pageInfo->filter->order->value)) {
         $order = ' ORDER BY ' . $pageInfo->filter->order->value . ' ' . $pageInfo->filter->order->dir;
     }
     if (!empty($filters)) {
         $filters = ' WHERE (' . implode(') AND (', $filters) . ')';
     } else {
         $filters = '';
     }
     $query = ' FROM ' . hikashop_table('taxation') . ' AS a LEFT JOIN ' . hikashop_table('tax') . ' AS b ON a.tax_namekey=b.tax_namekey LEFT JOIN ' . hikashop_table('category') . ' AS c ON a.category_namekey=c.category_namekey AND a.category_namekey!=\'\' AND c.category_type=\'tax\'' . $filters . $order;
     $database->setQuery('SELECT b.*,c.*,a.*' . $query, (int) $pageInfo->limit->start, (int) $pageInfo->limit->value);
     $rows = $database->loadObjectList();
     $database->setQuery('SELECT COUNT(*)' . $query);
     $pageInfo->elements = new stdClass();
     $pageInfo->elements->total = $database->loadResult();
     $pageInfo->elements->page = count($rows);
     $config =& hikashop_config();
     $this->assignRef('config', $config);
     if ($pageInfo->elements->page) {
         $zones = array();
         foreach ($rows as $row) {
             if (empty($row->zone_namekey)) {
                 continue;
             }
             $tax_zones = explode(',', $row->zone_namekey);
             foreach ($tax_zones as $zone) {
                 if (!empty($zone)) {
                     $zones[] = $database->Quote($zone);
                 }
             }
         }
         if (count($zones)) {
             $database->setQuery('SELECT * FROM #__hikashop_zone WHERE zone_namekey IN (' . implode(',', $zones) . ');');
             $zones = $database->loadObjectList('zone_namekey');
             foreach ($rows as $k => $row) {
                 if (empty($row->zone_namekey)) {
                     continue;
                 }
                 $tax_zones = explode(',', $row->zone_namekey);
                 $rows[$k]->zone_namekey = array();
                 foreach ($tax_zones as $zone) {
                     if (empty($zone)) {
                         continue;
                     }
                     if (isset($zones[$zone])) {
                         $rows[$k]->zone_namekey[] = $zones[$zone];
                     } else {
                         $rows[$k]->zone_namekey[] = $zone;
                     }
                 }
             }
         }
         foreach ($rows as $k => $row) {
             $restrictions = array();
             if (!empty($row->zone_namekey)) {
                 $zones = array();
                 foreach ($row->zone_namekey as $zone) {
                     if (is_string($zone)) {
                         $zones[] = $zone;
                         continue;
                     }
                     if (hikashop_isAllowed($config->get('acl_zone_manage', 'all'))) {
                         $zones[] = $zone->zone_name_english . '<a href="' . hikashop_completeLink('zone&task=edit&zone_id=' . $zone->zone_id) . '"><img class="hikashop_go" src="' . HIKASHOP_IMAGES . 'go.png" alt="go" /></a>';
                     } else {
                         $zones[] = $zone->zone_name_english;
                     }
                 }
                 if (count($zones)) {
                     $restrictions['ZONE'] = implode(', ', $zones);
                 }
             }
             if (!empty($row->taxation_post_code)) {
                 $restrictions['POST_CODE'] = $row->taxation_post_code;
             }
             if (!empty($row->taxation_type)) {
                 $row->taxation_type = explode(',', strtoupper(trim($row->taxation_type, ',')));
                 $types = array();
                 foreach ($row->taxation_type as $type) {
                     $types[] = JText::_($type);
                 }
                 $restrictions['CUSTOMER_TYPE'] = implode(', ', $types);
             }
             if (!empty($row->taxation_date_start)) {
                 $restrictions['START_DATE'] = hikashop_getDate($row->taxation_date_start, '%Y-%m-%d %H:%M');
             }
             if (!empty($row->taxation_end_start)) {
                 $restrictions['END_DATE'] = hikashop_getDate($row->taxation_end_start, '%Y-%m-%d %H:%M');
             }
             $rows[$k]->restrictions = $restrictions;
         }
     }
     $toggleClass = hikashop_get('helper.toggle');
     $this->assignRef('toggleClass', $toggleClass);
     $this->assignRef('rows', $rows);
     $this->assignRef('pageInfo', $pageInfo);
     $taxType = hikashop_get('type.tax');
     $this->assignRef('taxType', $taxType);
     $ratesType = hikashop_get('type.rates');
     $this->assignRef('ratesType', $ratesType);
     hikashop_setTitle(JText::_($this->nameListing), $this->icon, $this->ctrl);
     $this->getPagination();
     $manage = hikashop_isAllowed($config->get('acl_taxation_manage', 'all'));
     $this->assignRef('manage', $manage);
     $this->toolbar = array(array('name' => 'link', 'icon' => 'edit', 'alt' => JText::_('MANAGE_TAX_CATEGORIES'), 'url' => hikashop_completeLink('category&filter_id=tax'), 'display' => $manage), array('name' => 'link', 'icon' => 'edit', 'alt' => JText::_('MANAGE_RATES'), 'url' => hikashop_completeLink('tax&return=taxation'), 'display' => $manage), array('name' => '|', 'display' => $manage), array('name' => 'addNew', 'display' => $manage), array('name' => 'editList', 'display' => $manage), array('name' => 'deleteList', 'display' => hikashop_isAllowed($config->get('acl_taxation_delete', 'all'))), '|', array('name' => 'pophelp', 'target' => $this->ctrl . '-listing'), 'dashboard');
     JHTML::_('behavior.modal');
 }
Exemplo n.º 7
0
    function generateCoupon(&$allresults, $i, &$user)
    {
        list($minimum_order, $quota, $start, $end, $percent_amount, $flat_amount, $currency_id, $code, $product_id) = explode('|', $allresults[1][$i]);
        jimport('joomla.user.helper');
        $key = JUserHelper::genrandompassword(5);
        if (!hikashop_level(1)) {
            $minimum_order = 0;
            $quota = '';
            $product_id = '';
        }
        if ($percent_amount > 0) {
            $value = $percent_amount;
        } else {
            $value = $flat_amount;
        }
        $value = str_replace(',', '.', $value);
        if ($start) {
            $start = hikashop_getTime($start);
        }
        if ($end) {
            $end = hikashop_getTime($end);
        }
        $clean_name = strtoupper($user->name);
        $space = strpos($clean_name, ' ');
        if (!empty($space)) {
            $clean_name = substr($clean_name, 0, $space);
        }
        $code = str_replace(array('[name]', '[clean_name]', '[subid]', '[email]', '[key]', '[flat]', '[percent]', '[value]', '[prodid]'), array($user->name, $clean_name, $user->subid, $user->email, $key, $flat_amount, $percent_amount, $value, $product_id), $code);
        $this->db->setQuery('INSERT IGNORE INTO ' . acymailing_table('hikashop_discount', false) . '(
		`discount_code`,
		`discount_percent_amount`,
		`discount_flat_amount`,
		`discount_type`,
		`discount_start`,
		`discount_end`,
		`discount_minimum_order`,
		`discount_quota`,
		`discount_currency_id`,
		`discount_product_id`,
		`discount_published`
		) VALUES (' . $this->db->Quote($code) . ',' . $this->db->Quote($percent_amount) . ',' . $this->db->Quote($flat_amount) . ',\'coupon\',' . $this->db->Quote($start) . ',' . $this->db->Quote($end) . ',' . $this->db->Quote($minimum_order) . ',' . $this->db->Quote($quota) . ',' . $this->db->Quote(hikashop_getCurrency()) . ',' . $this->db->Quote($product_id) . ',
		1)');
        $this->db->query();
        return $code;
    }
Exemplo n.º 8
0
 function editionSquare($data, $data_id, $table, $column, $value, $id, $type)
 {
     hikashop_securefield($column);
     hikashop_securefield($table);
     hikashop_securefield($data);
     switch ($type) {
         case 'date':
             $value = hikashop_getTime($value);
             break;
     }
     if (!isset($this->dispatcher)) {
         JPluginHelper::importPlugin('hikashop');
         $this->dispatcher = JDispatcher::getInstance();
     }
     $this->dispatcher->trigger('onSaveEditionSquareMassAction', array($data, $data_id, $table, $column, $value, $id, $type));
 }
Exemplo n.º 9
0
 protected function checkFuturRules($timestamp, &$datepicker_options)
 {
     $phpDate = getdate($timestamp);
     $wday = $phpDate['wday'];
     $wday_cursor = $wday;
     $ret = 0;
     for ($i = $wday; $i <= 6; $i++) {
         if (!empty($datepicker_options['forbidden_' . $i]) && $i == $wday_cursor) {
             $ret++;
             $wday_cursor = ($wday_cursor + 1) % 7;
         }
     }
     for ($i = 0; $i < $wday; $i++) {
         if (!empty($datepicker_options['forbidden_' . $i]) && $i == $wday_cursor) {
             $ret++;
             $wday_cursor = ($wday_cursor + 1) % 7;
         }
     }
     if ($ret == 7) {
         return 0;
     }
     if (empty($datepicker_options['excludes'])) {
         return $ret;
     }
     $spe_day_format = 'm/d/Y';
     if (!empty($datepicker_options['exclude_days_format'])) {
         $spe_day_format = $datepicker_options['exclude_days_format'];
     }
     $dateValue = $this->getDate($timestamp + 86400 * $ret);
     $fullDayCode = $dateValue['y'] * 10000 + $dateValue['m'] * 100 + $dateValue['d'];
     $dayCode = $dateValue['m'] * 100 + $dateValue['d'];
     $excludeDays = explode('|', str_replace(array("\r\n", "\n", "\r", ' '), array('|', '|', '|', '|'), $datepicker_options['excludes']));
     foreach ($excludeDays as $day) {
         if (strpos($day, '-') === false) {
             $day = explode('/', trim($day));
             $exc_day = (int) $this->convertDay($day, null, $spe_day_format);
             if (empty($exc_day)) {
                 continue;
             }
             if (count($day) == 3 && $fullDayCode == $exc_day || count($day) == 2 && $dayCode == $exc_day) {
                 $ret++;
                 $dateValue = $this->getDate($timestamp + 86400 * $ret);
                 $fullDayCode = $dateValue['y'] * 10000 + $dateValue['m'] * 100 + $dateValue['d'];
                 $dayCode = $dateValue['m'] * 100 + $dateValue['d'];
             }
         } else {
             $days = explode('-', trim($day));
             $day1 = explode('/', trim($days[0]));
             $ret1 = (int) $this->convertDay($day1, null, $spe_day_format);
             $day2 = explode('/', trim($days[1]));
             $ret2 = (int) $this->convertDay($day2, null, $spe_day_format);
             if (!empty($ret1) && !empty($ret2) && count($day1) == count($day2) && $ret1 < $ret2) {
                 $final_date = 0;
                 if (count($day1) == 3 && $fullDayCode >= $ret1 && $fullDayCode <= $ret2) {
                     $final_date = floor($ret2 / 10000) . '/' . floor($ret2 % 10000 / 100) . '/' . $ret2 % 100;
                 } else {
                     if (count($day1) == 2 && $dayCode >= $ret1 && $dayCode <= $ret2) {
                         $final_date = $dateValue['y'] . '/' . floor($ret2 / 100) . '/' . $ret2 % 100;
                     }
                 }
                 if (!empty($final_date)) {
                     $t1 = hikashop_getTime($final_date);
                     $t2 = hikashop_getTime($dateValue['y'] . '/' . $dateValue['m'] . '/' . $dateValue['d']);
                     $ret += 1 + (int) (($t1 - $t2) / 86400);
                     $dateValue = $this->getDate($timestamp + 86400 * $ret);
                     $fullDayCode = $dateValue['y'] * 10000 + $dateValue['m'] * 100 + $dateValue['d'];
                     $dayCode = $dateValue['m'] * 100 + $dateValue['d'];
                 }
             }
         }
     }
     return $ret;
 }
Exemplo n.º 10
0
 function listing()
 {
     $app = JFactory::getApplication();
     $pageInfo = new stdClass();
     $pageInfo->filter = new stdClass();
     $pageInfo->filter->order = new stdClass();
     $pageInfo->limit = new stdClass();
     $pageInfo->search = $app->getUserStateFromRequest($this->paramBase . ".search", 'search', '', 'string');
     $pageInfo->search = JString::strtolower(trim($pageInfo->search));
     $pageInfo->filter->order->value = $app->getUserStateFromRequest($this->paramBase . ".filter_order", 'filter_order', '', 'cmd');
     $pageInfo->filter->order->dir = $app->getUserStateFromRequest($this->paramBase . ".filter_order_Dir", 'filter_order_Dir', 'desc', 'word');
     $pageInfo->limit->value = $app->getUserStateFromRequest($this->paramBase . '.list_limit', 'limit', $app->getCfg('list_limit'), 'int');
     $pageInfo->limit->start = $app->getUserStateFromRequest($this->paramBase . '.limitstart', 'limitstart', 0, 'int');
     $pageInfo->filter->filter_status = $app->getUserStateFromRequest($this->paramBase . ".filter_status", 'filter_status', '', 'array');
     $pageInfo->filter->filter_end = $app->getUserStateFromRequest($this->paramBase . ".filter_end", 'filter_end', '', 'string');
     $pageInfo->filter->filter_start = $app->getUserStateFromRequest($this->paramBase . ".filter_start", 'filter_start', '', 'string');
     $database = JFactory::getDBO();
     $searchMap = array('a.tax_namekey', 'a.tax_rate');
     $filters = array();
     if (!empty($pageInfo->search)) {
         $searchVal = '\'%' . hikashop_getEscaped($pageInfo->search, true) . '%\'';
         $filters[] = implode(" LIKE {$searchVal} OR ", $searchMap) . " LIKE {$searchVal}";
     }
     $order = '';
     if (!empty($pageInfo->filter->order->value)) {
         $order = ' ORDER BY ' . $pageInfo->filter->order->value . ' ' . $pageInfo->filter->order->dir;
     }
     JPluginHelper::importPlugin('hikashop');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onBeforeTaxListing', array($this->paramBase, &$this->extrafilters, &$pageInfo, &$filters));
     if (!empty($filters)) {
         $filters = ' WHERE (' . implode(') AND (', $filters) . ')';
     } else {
         $filters = '';
     }
     $query = ' FROM ' . hikashop_table('tax') . ' AS a ' . $filters . $order;
     $database->setQuery('SELECT a.*' . $query, (int) $pageInfo->limit->start, (int) $pageInfo->limit->value);
     $rows = $database->loadObjectList('tax_namekey');
     if (!empty($pageInfo->search)) {
         $rows = hikashop_search($pageInfo->search, $rows);
     }
     $database->setQuery('SELECT COUNT(*)' . $query);
     $pageInfo->elements = new stdClass();
     $pageInfo->elements->total = $database->loadResult();
     $pageInfo->elements->page = count($rows);
     $filters = array('order_type=\'sale\'');
     if (is_array($pageInfo->filter->filter_status) && count($pageInfo->filter->filter_status) == 1) {
         $pageInfo->filter->filter_status = reset($pageInfo->filter->filter_status);
     }
     switch ($pageInfo->filter->filter_status) {
         case '':
             break;
         default:
             if (!is_array($pageInfo->filter->filter_status)) {
                 $filters[] = 'order_status = ' . $database->Quote($pageInfo->filter->filter_status);
                 break;
             }
             if (!count($pageInfo->filter->filter_status) || in_array('', $pageInfo->filter->filter_status)) {
                 break;
             }
             $statuses = array();
             foreach ($pageInfo->filter->filter_status as $status) {
                 $statuses[] = $database->Quote($status);
             }
             $filters[] = 'order_status IN (' . implode(',', $statuses) . ')';
             break;
     }
     switch ($pageInfo->filter->filter_start) {
         case '':
             switch ($pageInfo->filter->filter_end) {
                 case '':
                     break;
                 default:
                     $filter_end = explode('-', $pageInfo->filter->filter_end);
                     $noHourDay = explode(' ', $filter_end[2]);
                     $filter_end[2] = $noHourDay[0];
                     $filter_end = hikashop_getTime(mktime(23, 59, 59, $filter_end[1], $filter_end[2], $filter_end[0]));
                     $filters[] = 'order_created <= ' . (int) $filter_end;
                     $pageInfo->filter->filter_end = (int) $filter_end;
                     break;
             }
             break;
         default:
             $filter_start = explode('-', $pageInfo->filter->filter_start);
             $noHourDay = explode(' ', $filter_start[2]);
             $filter_start[2] = $noHourDay[0];
             $filter_start = hikashop_getTime(mktime(0, 0, 0, $filter_start[1], $filter_start[2], $filter_start[0]));
             switch ($pageInfo->filter->filter_end) {
                 case '':
                     $filters[] = 'order_created >= ' . hikashop_getTime((int) $filter_start);
                     $pageInfo->filter->filter_start = (int) $filter_start;
                     break;
                 default:
                     $filter_end = explode('-', $pageInfo->filter->filter_end);
                     $noHourDay = explode(' ', $filter_end[2]);
                     $filter_end[2] = $noHourDay[0];
                     $filter_end = hikashop_getTime(mktime(23, 59, 59, $filter_end[1], $filter_end[2], $filter_end[0]));
                     $filters[] = 'order_created >= ' . (int) $filter_start . ' AND order_created <= ' . (int) $filter_end;
                     $pageInfo->filter->filter_start = (int) $filter_start;
                     $pageInfo->filter->filter_end = (int) $filter_end;
                     break;
             }
             break;
     }
     if (!empty($filters)) {
         $filters = ' WHERE (' . implode(') AND (', $filters) . ')';
     } else {
         $filters = '';
     }
     $database->setQuery('SELECT order_tax_info, order_currency_id FROM ' . hikashop_table('order') . $filters);
     $orders_taxes = $database->loadObjectList();
     $config = hikashop_config();
     $main_currency = $config->get('main_currency');
     $currencyClass = hikashop_get('class.currency');
     $currency_ids = array($main_currency => $main_currency);
     $currencies = array();
     if (count($orders_taxes)) {
         foreach ($orders_taxes as $k => $v) {
             $currency_ids[$v->order_currency_id] = $v->order_currency_id;
         }
     }
     $null = null;
     $currencies = $currencyClass->getCurrencies($currency_ids, $null);
     if (count($orders_taxes)) {
         foreach ($orders_taxes as $k => $v) {
             $orders_taxes[$k]->order_tax_info = unserialize($v->order_tax_info);
             $info =& $orders_taxes[$k]->order_tax_info;
             if (!$info) {
                 continue;
             }
             foreach ($info as $k2 => $taxes_info) {
                 $tax_amount = $taxes_info->tax_amount + @$taxes_info->tax_amount_for_shipping + @$taxes_info->tax_amount_for_payment - @$taxes_info->tax_amount_for_coupon;
                 if (!isset($taxes_info->tax_rate)) {
                     $taxes_info->tax_rate = $rows[$taxes_info->tax_namekey]->tax_rate;
                 }
                 if ($taxes_info->tax_rate != 0) {
                     $info[$k2]->amount = round($tax_amount / $taxes_info->tax_rate, $currencyClass->getRounding($v->order_currency_id));
                 } else {
                     $info[$k2]->amount = 0;
                 }
                 $info[$k2]->tax_amount = round($tax_amount, $currencyClass->getRounding($v->order_currency_id));
                 if ($main_currency != $v->order_currency_id) {
                     $info[$k2]->tax_amount_main_currency = $currencyClass->convertUniquePrice($info[$k2]->tax_amount, $v->order_currency_id, $main_currency);
                     $info[$k2]->amount_main_currency = $currencyClass->convertUniquePrice($info[$k2]->amount, $v->order_currency_id, $main_currency);
                 } else {
                     $info[$k2]->tax_amount_main_currency = $info[$k2]->tax_amount;
                     $info[$k2]->amount_main_currency = $info[$k2]->amount;
                 }
             }
         }
     }
     if ($pageInfo->elements->page) {
         foreach ($rows as $k => $tax) {
             $tax_amounts = array();
             $amounts = array();
             foreach ($currencies as $currency_id => $currency) {
                 $tax_amount = 0;
                 $amount = 0;
                 if (count($orders_taxes)) {
                     foreach ($orders_taxes as $order_taxes) {
                         if ($order_taxes->order_currency_id != $currency_id || !$order_taxes->order_tax_info) {
                             continue;
                         }
                         foreach ($order_taxes->order_tax_info as $order_tax) {
                             if ($order_tax->tax_namekey != $tax->tax_namekey) {
                                 continue;
                             }
                             $tax_amount += $order_tax->tax_amount;
                             $amount += $order_tax->amount;
                         }
                     }
                 }
                 $tax_amounts[$currency_id] = $tax_amount;
                 $amounts[$currency_id] = $amount;
             }
             $rows[$k]->tax_amounts = $tax_amounts;
             $rows[$k]->amounts = $amounts;
             $tax_amount_main_currency = 0;
             $amount_main_currency = 0;
             if (count($orders_taxes)) {
                 foreach ($orders_taxes as $order_taxes) {
                     if (!$order_taxes->order_tax_info) {
                         continue;
                     }
                     foreach ($order_taxes->order_tax_info as $order_tax) {
                         if ($order_tax->tax_namekey != $tax->tax_namekey) {
                             continue;
                         }
                         $tax_amount_main_currency += $order_tax->tax_amount_main_currency;
                         $amount_main_currency += $order_tax->amount_main_currency;
                     }
                 }
             }
             $rows[$k]->tax_amount = $tax_amount_main_currency;
             $rows[$k]->amount = $amount_main_currency;
         }
     }
     $this->assignRef('rows', $rows);
     $this->assignRef('pageInfo', $pageInfo);
     $this->assignRef('currencies', $currencies);
     $this->assignRef('main_currency', $main_currency);
     $this->assignRef('currencyHelper', $currencyClass);
     $category = hikashop_get('type.categorysub');
     $category->type = 'status';
     $this->assignRef('category', $category);
     hikashop_setTitle(JText::_($this->nameListing), $this->icon, $this->ctrl);
     $this->getPagination();
     $this->toolbar = array('addNew', 'editList', 'deleteList');
     $return = JRequest::getString('return', '');
     if (!empty($return)) {
         $this->toolbar[] = 'cancel';
     }
     $this->assignRef('return', $return);
     $this->toolbar[] = '|';
     $this->toolbar[] = array('name' => 'pophelp', 'target' => $this->ctrl . '-listing');
     $this->toolbar[] = 'dashboard';
 }
Exemplo n.º 11
0
 public function backSaveVariantForm()
 {
     $app = JFactory::getApplication();
     $config = hikashop_config();
     if (empty($this->db)) {
         $this->db = JFactory::getDBO();
     }
     $product_id = hikashop_getCID('variant_id');
     $parent_product_id = JRequest::getInt('product_id', 0);
     $fieldsClass = hikashop_get('class.field');
     $formData = JRequest::getVar('data', array(), '', 'array');
     $formVariant = array();
     if (!empty($formData['variant'])) {
         $formVariant = $formData['variant'];
     }
     if (!empty($formData['product'])) {
         $product_id = (int) $formVariant['product_id'];
     }
     if (!hikashop_acl('product/variant')) {
         return false;
     }
     $new = false;
     $oldProduct = null;
     $productParent = null;
     if (empty($product_id)) {
         $new = true;
     }
     if (!$new) {
         $oldProduct = $this->get($product_id);
         if ($oldProduct->product_type != 'variant') {
             return false;
         }
         if ((int) $oldProduct->product_parent_id != $parent_product_id && $parent_product_id > 0) {
             return false;
         }
         if (empty($parent_product_id)) {
             $parent_product_id = (int) $oldProduct->product_parent_id;
         }
     } else {
         if (!hikashop_acl('product/add')) {
             return false;
         }
         if (empty($parent_product_id)) {
             return false;
         }
         $productParent = $this->get($parent_product_id);
         if ($productParent->product_type != 'main') {
             return false;
         }
     }
     $product = $fieldsClass->getInput('variant', $oldProduct);
     if (empty($product)) {
         return false;
     }
     $this->db->setQuery('SELECT field.* FROM ' . hikashop_table('field') . ' as field WHERE field.field_table = ' . $this->db->Quote('product') . ' ORDER BY field.`field_ordering` ASC');
     $all_fields = $this->db->loadObjectList('field_namekey');
     $edit_fields = hikashop_acl('product/variant/customfields');
     foreach ($all_fields as $fieldname => $field) {
         if (!$edit_fields || empty($field->field_published) || empty($field->field_backend)) {
             unset($product->{$fieldname});
         }
     }
     $product->product_id = $product_id;
     $product->product_type = 'variant';
     $product->product_parent_id = $parent_product_id;
     // TODO
     if (hikashop_acl('product/variant/characteristics')) {
         $product->characteristics = array();
         unset($product->characteristic);
         $query = 'SELECT v.*, c.* FROM ' . hikashop_table('variant') . ' AS v ' . ' INNER JOIN ' . hikashop_table('characteristic') . ' as c ON v.variant_characteristic_id = c.characteristic_id ' . ' WHERE variant_product_id = ' . (int) $parent_product_id;
         $this->db->setQuery($query);
         $characteristics = $this->db->loadObjectList('characteristic_id');
         $characteristic_ids = array();
         foreach ($characteristics as $characteristic) {
             if ((int) $characteristic->characteristic_parent_id == 0) {
                 $characteristic_ids[(int) $characteristic->characteristic_id] = (int) $characteristic->characteristic_id;
             } else {
                 $characteristics[(int) $characteristic->characteristic_parent_id]->default = (int) $characteristic->characteristic_id;
             }
         }
         if (count($characteristic_ids)) {
             $query = 'SELECT c.* FROM ' . hikashop_table('characteristic') . ' AS c ' . ' WHERE c.characteristic_parent_id IN (' . implode(',', $characteristic_ids) . ')';
             $this->db->setQuery($query);
             $characteristics_values = $this->db->loadObjectList('characteristic_id');
         }
         foreach ($characteristics as $characteristic) {
             if ((int) $characteristic->characteristic_parent_id == 0) {
                 $i = (int) $characteristic->characteristic_id;
                 $v = (int) @$formVariant['characteristic'][$i];
                 if (isset($characteristics_values[$v]) && ($characteristics_values[$v]->characteristic_parent_id = $i)) {
                     $product->characteristics[$v] = $i;
                 } else {
                     $product->characteristics[$characteristic->default] = $i;
                 }
             }
         }
     } else {
         unset($product->characteristics);
         unset($product->characteristic);
     }
     if (!hikashop_acl('product/variant/name')) {
         unset($product->product_name);
     }
     if (!hikashop_acl('product/variant/code')) {
         unset($product->product_code);
     }
     if (!hikashop_acl('product/variant/weight')) {
         unset($product->product_weight);
     }
     if (!hikashop_acl('product/variant/volume')) {
         unset($product->product_volume);
     }
     if (!hikashop_acl('product/variant/published')) {
         unset($product->product_published);
     }
     if (!hikashop_acl('product/variant/acl')) {
         unset($product->product_access);
     }
     if (hikashop_acl('product/variant/qtyperorder')) {
         if (isset($product->product_max_per_order)) {
             $product->product_max_per_order = (int) $product->product_max_per_order;
         }
         if (isset($product->product_min_per_order)) {
             $product->product_min_per_order = (int) $product->product_min_per_order;
         }
     } else {
         unset($product->product_max_per_order);
         unset($product->product_min_per_order);
     }
     $removeFields = array('manufacturer_id', 'page_title', 'url', 'meta_description', 'keywords', 'alias', 'msrp', 'canonical', 'contact', 'delay_id', 'tax_id', 'waitlist', 'display_quantity_field', 'status', 'hit', 'created', 'modified', 'last_seen_date', 'sales', 'layout', 'average_score', 'total_vote', 'warehouse_id');
     foreach ($removeFields as $rf) {
         $rf = 'product_' . $rf;
         unset($product->{$rf});
     }
     unset($product->categories);
     unset($product->related);
     unset($product->options);
     if (hikashop_acl('product/variant/description')) {
         $product->product_description = JRequest::getVar('product_variant_description', '', '', 'string', JREQUEST_ALLOWRAW);
         $safeHtmlFilter = JFilterInput::getInstance(null, null, 1, 1);
         $product->product_description = $safeHtmlFilter->clean($product->product_description, 'string');
     }
     if (hikashop_acl('product/variant/price')) {
         $acls = array('value' => hikashop_acl('product/variant/price/value'), 'tax' => hikashop_acl('product/variant/price/tax'), 'currency' => hikashop_acl('product/variant/price/currency'), 'quantity' => hikashop_acl('product/variant/price/quantity'), 'acl' => hikashop_level(2) && hikashop_acl('product/variant/price/acl'));
         if (!empty($oldProduct)) {
             $query = 'SELECT * FROM ' . hikashop_table('price') . ' WHERE price_product_id = ' . (int) $oldProduct->product_id;
             $this->db->setQuery($query);
             $oldProduct->prices = $this->db->loadObjectList();
         }
         $priceData = JRequest::getVar('variantprice', array(), '', 'array');
         $product->prices = array();
         foreach ($priceData as $k => $value) {
             if ((int) $k == 0 && $k !== 0 && $k !== '0') {
                 continue;
             }
             $price_id = (int) @$value['price_id'];
             if (!empty($oldProduct) && !empty($price_id) && !empty($oldProduct->prices)) {
                 foreach ($oldProduct->prices as $p) {
                     if ($p->price_id == $price_id) {
                         $product->prices[$k] = $p;
                         break;
                     }
                 }
             }
             if (empty($product->prices[$k])) {
                 $product->prices[$k] = new stdClass();
             }
             if (($acls['value'] || $acls['tax']) && isset($value['price_value'])) {
                 $product->prices[$k]->price_value = hikashop_toFloat($value['price_value']);
             }
             if ($acls['acl'] && isset($value['price_access'])) {
                 $product->prices[$k]->price_access = preg_replace('#[^a-z0-9,]#i', '', $value['price_access']);
             }
             if ($acls['currency'] && isset($value['price_currency_id'])) {
                 $product->prices[$k]->price_currency_id = (int) $value['price_currency_id'];
             }
             if (empty($product->prices[$k]->price_currency_id)) {
                 $product->prices[$k]->price_currency_id = $config->get('main_currency', 1);
             }
             if ($acls['quantity'] && isset($value['price_min_quantity'])) {
                 $product->prices[$k]->price_min_quantity = (int) $value['price_min_quantity'];
                 if ($product->prices[$k]->price_min_quantity == 1) {
                     $product->prices[$k]->price_min_quantity = 0;
                 }
             }
             if (empty($product->prices[$k]->price_min_quantity)) {
                 $product->prices[$k]->price_min_quantity = 0;
             }
         }
     } else {
         unset($product->prices);
     }
     if (hikashop_acl('product/variant/images')) {
         $product->images = @$formVariant['product_images'];
         JArrayHelper::toInteger($product->images);
         $product->imagesorder = array();
         foreach ($product->images as $k => $v) {
             $product->imagesorder[$v] = $k;
         }
     } else {
         unset($product->imagesorder);
     }
     unset($product->product_images);
     if (hikashop_acl('product/variant/files')) {
         $product->files = @$formVariant['product_files'];
         JArrayHelper::toInteger($product->files);
     } else {
         unset($product->files);
     }
     unset($product->product_files);
     if (hikashop_acl('product/variant/saledates')) {
         if (!empty($product->product_sale_start)) {
             $product->product_sale_start = hikashop_getTime($product->product_sale_start);
         }
         if (!empty($product->product_sale_end)) {
             $product->product_sale_end = hikashop_getTime($product->product_sale_end);
         }
     } else {
         unset($product->product_sale_start);
         unset($product->product_sale_end);
     }
     $status = $this->save($product);
     if ($status) {
         if (hikashop_acl('product/variant/price')) {
             $this->updatePrices($product, $status);
         }
         if (hikashop_acl('product/variant/files')) {
             $this->updateFiles($product, $status, 'files');
         }
         if (hikashop_acl('product/variant/images')) {
             $this->updateFiles($product, $status, 'images', $product->imagesorder);
         }
         if (hikashop_acl('product/variant/characteristics')) {
             $this->updateCharacteristics($product, $status);
         }
     } else {
         JRequest::setVar('fail', $product);
         if (empty($product->product_id) && empty($product->product_code) && empty($product->product_name)) {
             $app->enqueueMessage(JText::_('SPECIFY_NAME_AND_CODE'), 'error');
         } else {
             $query = 'SELECT product_id FROM ' . hikashop_table('product') . ' WHERE product_code  = ' . $this->db->Quote($product->product_code) . ' AND NOT (product_id = ' . (int) @$product->product_id . ')';
             $this->db->setQuery($query, 0, 1);
             if ($this->db->loadResult()) {
                 $app->enqueueMessage(JText::_('DUPLICATE_PRODUCT'), 'error');
             } else {
                 $app->enqueueMessage(JText::_('PRODUCT_SAVE_UNKNOWN_ERROR'), 'error');
             }
         }
     }
     return $product_id;
 }
Exemplo n.º 12
0
 function saveForm()
 {
     $widget = new stdClass();
     $table = new stdClass();
     $formData = JRequest::getVar('data', array(), '', 'array');
     $deleteRow = JRequest::getVar('delete_row');
     $widget->widget_id = hikashop_getCID('widget_id');
     jimport('joomla.filter.filterinput');
     $safeHtmlFilter =& JFilterInput::getInstance(null, null, 1, 1);
     if (!empty($formData)) {
         if (isset($formData['edit_row'])) {
             $widget_id = $formData['widget']['widget_id'];
             $class = hikashop_get('class.widget');
             if (!empty($widget_id)) {
                 $widget = $class->get($widget_id);
             }
             $widget->widget_name = $safeHtmlFilter->clean(strip_tags($formData['widget']['widget_name']), 'string');
             $widget->widget_published = (int) $formData['widget']['widget_published'];
             $widget->widget_access = $safeHtmlFilter->clean(strip_tags($formData['widget']['widget_access']), 'string');
             if (!isset($widget->widget_params)) {
                 $widget->widget_params = new stdClass();
             }
             $widget->widget_params->display = 'table';
             foreach ($formData['widget']['widget_params']['table'] as $key => $tab) {
                 $theKey = $key;
             }
             foreach ($formData['widget']['widget_params']['table'][$theKey] as $column => $value) {
                 hikashop_secureField($column);
                 if (is_array($value)) {
                     $table->{$column} = new stdClass();
                     foreach ($value as $k2 => $v2) {
                         hikashop_secureField($k2);
                         if ($k2 == 'start' || $k2 == 'end') {
                             $v2 = hikashop_getTime($v2);
                         }
                         if (is_array($v2)) {
                             if ($k2 == 'filters' || $k2 == "compares") {
                                 $v2 = serialize($v2);
                             } else {
                                 $v2 = implode(',', $v2);
                             }
                         }
                         $table->{$column}->{$k2} = $safeHtmlFilter->clean(strip_tags($v2), 'string');
                     }
                 } else {
                     $table->{$column} = $safeHtmlFilter->clean(strip_tags($value), 'string');
                 }
             }
             $categories = JRequest::getVar('row_category', array(), '', 'array');
             JArrayHelper::toInteger($categories);
             $cat = array();
             foreach ($categories as $category) {
                 $cat[] = $category;
             }
             if (empty($cat)) {
                 $cat = 'all';
             } else {
                 $cat = implode(',', $cat);
             }
             $widget->widget_params->categories = $cat;
             $coupons = JRequest::getVar('row_coupon', array(), '', 'array');
             JArrayHelper::toInteger($coupons);
             $coupons = serialize($coupons);
             $widget->widget_params->coupons = $coupons;
             $widget->widget_params->table[$theKey] = $table;
         } else {
             if ($formData['widget']['widget_params']['display'] == 'table') {
                 $class = hikashop_get('class.widget');
                 if (!empty($widget->widget_id)) {
                     $widget = $class->get($widget->widget_id);
                 }
                 if ($deleteRow >= 0) {
                     unset($widget->widget_params->table[$deleteRow]);
                 } else {
                     $widget->widget_name = $safeHtmlFilter->clean(strip_tags($formData['widget']['widget_name']), 'string');
                     $widget->widget_published = (int) $formData['widget']['widget_published'];
                     $widget->widget_access = $safeHtmlFilter->clean(strip_tags($formData['widget']['widget_access']), 'string');
                 }
             } else {
                 if ($formData['widget']['widget_params']['periodType'] && isset($formData['widget']['widget_params']['proposedPeriod']) && $formData['widget']['widget_params']['proposedPeriod'] == 'all') {
                     $formData['widget']['widget_params']['period_compare'] = 'none';
                 }
                 foreach ($formData['widget'] as $column => $value) {
                     hikashop_secureField($column);
                     if (is_array($value)) {
                         $widget->{$column} = new stdClass();
                         foreach ($value as $k2 => $v2) {
                             hikashop_secureField($k2);
                             if (is_array($v2)) {
                                 if ($k2 == 'filters' || $k2 == "compares") {
                                     $v2 = serialize($v2);
                                 } else {
                                     $v2 = implode(',', $v2);
                                 }
                             }
                             $widget->{$column}->{$k2} = $safeHtmlFilter->clean(strip_tags($v2), 'string');
                         }
                     } else {
                         $widget->{$column} = $safeHtmlFilter->clean(strip_tags($value), 'string');
                     }
                 }
             }
         }
     }
     if (!empty($widget->widget_params->start)) {
         $widget->widget_params->start = hikashop_getTime($widget->widget_params->start);
     }
     if (!empty($widget->widget_params->end)) {
         $widget->widget_params->end = hikashop_getTime($widget->widget_params->end);
     }
     if (isset($widget->widget_params->compare_with)) {
         if ($widget->widget_params->compare_with == 'periods') {
             $widget->widget_params->compares = null;
         }
     }
     $categories = JRequest::getVar('category', array(), '', 'array');
     JArrayHelper::toInteger($categories);
     $cat = array();
     foreach ($categories as $category) {
         $cat[] = $category;
     }
     if (empty($cat)) {
         $cat = 'all';
     } else {
         $cat = implode(',', $cat);
     }
     $products = JRequest::getVar('widget', array(), '', 'array');
     JArrayHelper::toInteger($products);
     $prods = serialize($products);
     $coupons = JRequest::getVar('coupon', array(), '', 'array');
     JArrayHelper::toInteger($coupons);
     $coupons = serialize($coupons);
     if (isset($formData['edit_row'])) {
         $widget->widget_params->table[$theKey]->widget_params->categories = $cat;
         $widget->widget_params->table[$theKey]->widget_params->products = $prods;
         $widget->widget_params->table[$theKey]->widget_params->coupons = $coupons;
     } else {
         $widget->widget_params->categories = $cat;
         $widget->widget_params->products = $prods;
         $widget->widget_params->coupons = $coupons;
     }
     $status = $this->save($widget);
     if ($status) {
         $orderClass = hikashop_get('helper.order');
         $orderClass->pkey = 'widget_id';
         $orderClass->table = 'widget';
         $orderClass->orderingMap = 'widget_ordering';
         $orderClass->reOrder();
     }
     return $status;
 }
Exemplo n.º 13
0
 function export()
 {
     $ids = JRequest::getVar('cid', array(), '', 'array');
     $database = JFactory::getDBO();
     $fieldsClass = hikashop_get('class.field');
     $fields = $fieldsClass->getData('all', 'order', false);
     $filters = array();
     JPluginHelper::importPlugin('hikashop');
     $dispatcher = JDispatcher::getInstance();
     if (empty($ids)) {
         $filters['order_type'] = 'hk_order.order_type = \'sale\'';
         $app = JFactory::getApplication();
         $search = $app->getUserStateFromRequest($this->paramBase . ".search", 'search', '', 'string');
         $filter_status = $app->getUserStateFromRequest($this->paramBase . ".filter_status", 'filter_status', '', 'array');
         $filter_payment = $app->getUserStateFromRequest($this->paramBase . ".filter_payment", 'filter_payment', '', 'string');
         $filter_partner = $app->getUserStateFromRequest($this->paramBase . ".filter_partner", 'filter_partner', '', 'int');
         $filter_end = $app->getUserStateFromRequest($this->paramBase . ".filter_end", 'filter_end', '', 'string');
         $filter_start = $app->getUserStateFromRequest($this->paramBase . ".filter_start", 'filter_start', '', 'string');
         switch ($filter_start) {
             case '':
                 switch ($filter_end) {
                     case '':
                         break;
                     default:
                         $filter_end = explode('-', $filter_end);
                         $noHourDay = explode(' ', $filter_end[2]);
                         $filter_end[2] = $noHourDay[0];
                         $filter_end = hikashop_getTime(mktime(23, 59, 59, $filter_end[1], $filter_end[2], $filter_end[0]));
                         $filters['order_created'] = 'hk_order.order_created < ' . (int) $filter_end;
                         break;
                 }
                 break;
             default:
                 $filter_start = explode('-', $filter_start);
                 $noHourDay = explode(' ', $filter_start[2]);
                 $filter_start[2] = $noHourDay[0];
                 $filter_start = hikashop_getTime(mktime(0, 0, 0, $filter_start[1], $filter_start[2], $filter_start[0]));
                 switch ($filter_end) {
                     case '':
                         $filters['order_created'] = 'hk_order.order_created > ' . (int) $filter_start;
                         break;
                     default:
                         $filter_end = explode('-', $filter_end);
                         $noHourDay = explode(' ', $filter_end[2]);
                         $filter_end[2] = $noHourDay[0];
                         $filter_end = hikashop_getTime(mktime(23, 59, 59, $filter_end[1], $filter_end[2], $filter_end[0]));
                         $filters['order_created'] = 'hk_order.order_created > ' . (int) $filter_start . ' AND hk_order.order_created < ' . (int) $filter_end;
                         break;
                 }
                 break;
         }
         if (!empty($filter_partner)) {
             $filters['order_partner_id'] = $filter_partner == 1 ? 'hk_order.order_partner_id != 0' : 'hk_order.order_partner_id = 0';
         }
         switch ($filter_status) {
             case '':
                 break;
             default:
                 if (!is_array($filter_status) || !count($filter_status) || in_array('', $filter_status)) {
                     break;
                 }
                 $statuses = array();
                 foreach ($filter_status as $status) {
                     $statuses[] = $database->Quote($status);
                 }
                 $filters['order_status'] = 'hk_order.order_status IN (' . implode(',', $statuses) . ')';
                 break;
         }
         switch ($filter_payment) {
             case '':
                 break;
             default:
                 $filters['order_payment_method'] = 'hk_order.order_payment_method = ' . $database->Quote($filter_payment);
                 break;
         }
         $searchMap = array('j_user.id', 'j_user.username', 'j_user.name', 'hk_user.user_email', 'hk_order.order_user_id', 'hk_order.order_id', 'hk_order.order_full_price');
         foreach ($fields as $field) {
             $searchMap[] = 'hk_order.' . $field->field_namekey;
         }
         if (!empty($search)) {
             $searchVal = '\'%' . hikashop_getEscaped(JString::strtolower(trim($search)), true) . '%\'';
             $id = hikashop_decode($pageInfo->search);
             $filter = implode(' LIKE ' . $searchVal . ' OR ', $searchMap) . ' LIKE ' . $searchVal;
             if (!empty($id)) {
                 $filter .= ' OR hk_order.order_id LIKE \'%' . hikashop_getEscaped($id, true) . '%\'';
             }
             $filters['search'] = $filter;
         }
         $dispatcher->trigger('onBeforeOrderExportQuery', array(&$filters, $this->paramBase));
     } else {
         JArrayHelper::toInteger($ids, 0);
         $filters['order_id'] = 'hk_order.order_id IN (' . implode(',', $ids) . ')';
     }
     $filters = '(' . implode(') AND (', $filters) . ')';
     $query = ' FROM ' . hikashop_table('order') . ' AS hk_order ' . ' LEFT JOIN ' . hikashop_table('user') . ' AS hk_user ON hk_order.order_user_id = hk_user.user_id ' . ' LEFT JOIN ' . hikashop_table('users', false) . ' AS j_user ON hk_user.user_cms_id = j_user.id ' . ' WHERE ' . $filters;
     $database->setQuery('SELECT hk_user.*, hk_order.*, j_user.*' . $query);
     $rows = $database->loadObjectList('order_id');
     if (!empty($rows)) {
         $addressIds = array();
         foreach ($rows as $k => $row) {
             $rows[$k]->products = array();
             $addressIds[$row->order_shipping_address_id] = $row->order_shipping_address_id;
             $addressIds[$row->order_billing_address_id] = $row->order_billing_address_id;
         }
         if (!empty($addressIds)) {
             $database->setQuery('SELECT * FROM ' . hikashop_table('address') . ' WHERE address_id IN (' . implode(',', $addressIds) . ')');
             $addresses = $database->loadObjectList('address_id');
             if (!empty($addresses)) {
                 $zoneNamekeys = array();
                 foreach ($addresses as $address) {
                     $zoneNamekeys[$address->address_country] = $database->Quote($address->address_country);
                     $zoneNamekeys[$address->address_state] = $database->Quote($address->address_state);
                 }
                 if (!empty($zoneNamekeys)) {
                     $database->setQuery('SELECT zone_namekey,zone_name FROM ' . hikashop_table('zone') . ' WHERE zone_namekey IN (' . implode(',', $zoneNamekeys) . ')');
                     $zones = $database->loadObjectList('zone_namekey');
                     if (!empty($zones)) {
                         foreach ($addresses as $i => $address) {
                             if (!empty($zones[$address->address_country])) {
                                 $addresses[$i]->address_country = $zones[$address->address_country]->zone_name;
                             }
                             if (!empty($zones[$address->address_state])) {
                                 $addresses[$i]->address_state = $zones[$address->address_state]->zone_name;
                             }
                         }
                     }
                 }
                 $fields = array_keys(get_object_vars(reset($addresses)));
                 foreach ($rows as $k => $row) {
                     if (!empty($addresses[$row->order_shipping_address_id])) {
                         foreach ($addresses[$row->order_shipping_address_id] as $key => $val) {
                             $key = 'shipping_' . $key;
                             $rows[$k]->{$key} = $val;
                         }
                     } else {
                         foreach ($fields as $field) {
                             $key = 'shipping_' . $field;
                             $rows[$k]->{$key} = '';
                         }
                     }
                     if (!empty($addresses[$row->order_billing_address_id])) {
                         foreach ($addresses[$row->order_billing_address_id] as $key => $val) {
                             $key = 'billing_' . $key;
                             $rows[$k]->{$key} = $val;
                         }
                     } else {
                         foreach ($fields as $field) {
                             $key = 'billing_' . $field;
                             $rows[$k]->{$key} = '';
                         }
                     }
                 }
             }
         }
         $orderIds = array_keys($rows);
         $database->setQuery('SELECT * FROM ' . hikashop_table('order_product') . ' WHERE order_id IN (' . implode(',', $orderIds) . ')');
         $products = $database->loadObjectList();
         foreach ($products as $product) {
             $order =& $rows[$product->order_id];
             $order->products[] = $product;
             if (!isset($order->order_full_tax)) {
                 $order->order_full_tax = 0;
             }
             $order->order_full_tax += round($product->order_product_quantity * $product->order_product_tax, 2);
         }
         foreach ($rows as $k => $row) {
             $rows[$k]->order_full_tax += $row->order_shipping_tax + $row->order_payment_tax - $row->order_discount_tax;
         }
     }
     $dispatcher->trigger('onBeforeOrderExport', array(&$rows, &$this));
     $this->assignRef('orders', $rows);
 }