Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildForm($form, $form_state);
     $rate = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#description' => $this->t('This name will appear to the customer when this tax is applied to an order.'), '#default_value' => $rate->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#title' => $this->t('Machine name'), '#default_value' => $rate->id(), '#machine_name' => array('exists' => array($this, 'exists'), 'replace_pattern' => '([^a-z0-9_]+)|(^custom$)', 'error' => 'The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".'));
     $form['rate'] = array('#type' => 'textfield', '#title' => $this->t('Rate'), '#description' => $this->t('The tax rate as a percent or decimal. Examples: 6%, .06'), '#size' => 15, '#default_value' => (double) $rate->getRate() * 100.0 . '%', '#required' => TRUE);
     $form['jurisdiction'] = array('#type' => 'textfield', '#title' => $this->t('Jurisdiction'), '#description' => $this->t('Administrative label for the taxing authority, used to prepare reports of collected taxes.'), '#default_value' => $rate->getJurisdiction(), '#required' => FALSE);
     $form['shippable'] = array('#type' => 'radios', '#title' => $this->t('Taxed products'), '#options' => array(0 => $this->t('Apply tax to any product regardless of its shippability.'), 1 => $this->t('Apply tax to shippable products only.')), '#default_value' => (int) $rate->isForShippable());
     // TODO: Remove the need for a special case for product kit module.
     $options = array();
     foreach (node_type_get_names() as $type => $name) {
         if ($type != 'product_kit' && uc_product_is_product($type)) {
             $options[$type] = $name;
         }
     }
     $options['blank-line'] = $this->t('"Blank line" product');
     $form['product_types'] = array('#type' => 'checkboxes', '#title' => $this->t('Taxed product types'), '#description' => $this->t('Apply taxes to the specified product types/classes.'), '#default_value' => $rate->getProductTypes(), '#options' => $options);
     $options = array();
     foreach (_uc_line_item_list() as $id => $line_item) {
         if (!in_array($id, ['subtotal', 'tax_subtotal', 'total', 'tax_display'])) {
             $options[$id] = $line_item['title'];
         }
     }
     $form['line_item_types'] = array('#type' => 'checkboxes', '#title' => $this->t('Taxed line items'), '#description' => $this->t('Adds the checked line item types to the total before applying this tax.'), '#default_value' => $rate->getLineItemTypes(), '#options' => $options);
     $form['weight'] = array('#type' => 'weight', '#title' => $this->t('Weight'), '#description' => $this->t('Taxes are sorted by weight and then applied to the order sequentially. This value is important when taxes need to include other tax line items.'), '#default_value' => $rate->getWeight());
     $form['display_include'] = array('#type' => 'checkbox', '#title' => $this->t('Include this tax when displaying product prices.'), '#default_value' => $rate->isIncludedInPrice());
     $form['inclusion_text'] = array('#type' => 'textfield', '#title' => $this->t('Tax inclusion text'), '#description' => $this->t('This text will be displayed near the price to indicate that it includes tax.'), '#default_value' => $rate->getInclusionText());
     return $form;
 }
Esempio n. 2
0
/**
 * Override or insert variables into the node template.
 */
function fusion_prosper_preprocess_node(&$vars)
{
    // Render Ubercart fields into separate variables for node--product.tpl.php
    if (module_exists('uc_product') && uc_product_is_product($vars)) {
        $vars['fusion_uc_image'] = drupal_render($vars['content']['uc_product_image']);
        $vars['fusion_uc_body'] = drupal_render($vars['content']['body']);
        $vars['fusion_uc_display_price'] = drupal_render($vars['content']['display_price']);
        $vars['fusion_uc_add_to_cart'] = drupal_render($vars['content']['add_to_cart']);
        $vars['fusion_uc_sell_price'] = drupal_render($vars['content']['sell_price']);
        $vars['fusion_uc_cost'] = drupal_render($vars['content']['cost']);
        $vars['fusion_uc_sku'] = drupal_render($vars['content']['sku']);
        $vars['fusion_uc_weight'] = !empty($vars['content']['weight']) ? drupal_render($vars['content']['weight']) : '';
        // Hide weight if empty
        if ($vars['fusion_uc_weight'] == '') {
            unset($vars['content']['weight']);
        }
        $dimensions = !empty($vars['content']['height']) && !empty($vars['content']['width']) && !empty($vars['content']['length']);
        // Hide dimensions if empty
        $vars['fusion_uc_dimensions'] = $dimensions ? drupal_render($vars['content']['dimensions']) : '';
        if ($vars['fusion_uc_dimensions'] == '') {
            unset($vars['content']['dimensions']);
        }
        $list_price = !empty($vars['content']['list_price']) && $vars['content']['list_price'] > 0;
        // Hide list price if empty or zero
        $vars['fusion_uc_list_price'] = $list_price ? drupal_render($vars['content']['list_price']) : '';
        if ($vars['fusion_uc_list_price'] == '') {
            unset($vars['content']['list_price']);
        }
        $vars['fusion_uc_additional'] = drupal_render($vars['content']);
        // Render remaining fields
    }
}
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     $nid = $this->getValue($values);
     $node = node_load($nid);
     if (uc_product_is_product($node)) {
         $form = \Drupal::formBuilder()->getForm('\\Drupal\\uc_product\\Form\\AddToCartForm', $node);
         return drupal_render($form);
     }
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     $nid = $this->getValue($values);
     $node = node_load($nid);
     if (uc_product_is_product($node)) {
         $form_object = new \Drupal\uc_product\Form\BuyItNowForm($node->id());
         $form = \Drupal::formBuilder()->getForm($form_object, $node);
         return drupal_render($form);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function access(Route $route, Request $request)
 {
     if ($request->attributes->has('node')) {
         $entity = $request->attributes->get('node');
         if ($entity instanceof NodeInterface && uc_product_is_product($node)) {
             return static::ALLOW;
         }
     }
     return static::DENY;
 }
 public function addItemKitToCart($nodeID, $qty = 1, $data = array())
 {
     $node = node_load($nodeID);
     if (!is_object($node) || !uc_product_is_product($node)) {
         throw new NoProductException();
     }
     if ($this->checkKitToCart($node, $data)) {
         uc_product_kit_add_to_cart($node->nid, $qty, $data);
         drupal_set_message(t('Add !product to cart.', array('!product' => $node->title)));
     }
 }
 /**
  * Checks access for the feature routes.
  */
 public function checkAccess(Request $request)
 {
     $node = $request->get('node');
     if (uc_product_is_product($node) && $node->getType() != 'product_kit') {
         if ($this->currentUser()->hasPermission('administer product features')) {
             return AccessInterface::ALLOW;
         }
         if ($this->currentUser()->hasPermission('administer own product features') && $this->currentUser()->id() == $node->getAuthorId()) {
             return AccessInterface::ALLOW;
         }
     }
     return AccessInterface::DENY;
 }
Esempio n. 8
0
/**
 * @param $variables
 */
function webshopchartage_preprocess_node(&$variables)
{
    $variables['details'] = '<div class="details">';
    $variables['details'] .= '<i class="fa fa-info"></i> ';
    $variables['details'] .= t('Details');
    $variables['details'] .= '</div>';
    if (module_exists('uc_product') && uc_product_is_product($variables)) {
        $variables['uc_image'] = drupal_render($variables['content']['uc_product_image']);
        $variables['uc_sellPrice'] = drupal_render($variables['content']['sell_price']);
        $variables['uc_body'] = drupal_render($variables['content']['body']);
        $variables['uc_addCart'] = drupal_render($variables['content']['add_to_cart']);
    }
}
Esempio n. 9
0
/**
 * Node preprocessing
 */
function fusion_core_preprocess_node(&$vars)
{
    // Build array of handy node classes
    $node_classes = array();
    $node_classes[] = $vars['zebra'];
    // Node is odd or even
    $node_classes[] = !$vars['node']->status ? 'node-unpublished' : '';
    // Node is unpublished
    $node_classes[] = $vars['sticky'] ? 'sticky' : '';
    // Node is sticky
    $node_classes[] = $vars['teaser'] ? 'teaser' : 'full-node';
    // Node is teaser or full-node
    $node_classes[] = 'node-type-' . $vars['node']->type;
    // Node is type-x, e.g., node-type-page
    $node_classes[] = isset($vars['skinr']) ? $vars['skinr'] : '';
    // Add Skinr classes if present
    $node_classes = array_filter($node_classes);
    // Remove empty elements
    $vars['node_classes'] = implode(' ', $node_classes);
    // Implode class list with spaces
    // Add node_top and node_bottom region content
    $vars['node_top'] = theme('blocks', 'node_top');
    $vars['node_bottom'] = theme('blocks', 'node_bottom');
    // Render Ubercart fields into separate variables for node-product.tpl.php
    if (module_exists('uc_product') && uc_product_is_product($vars) && $vars['template_files'][0] == 'node-product') {
        $node = node_build_content(node_load($vars['nid']), $vars['teaser'], $vars['page']);
        $vars['fusion_uc_image'] = drupal_render($node->content['image']);
        $vars['fusion_uc_body'] = drupal_render($node->content['body']);
        $vars['fusion_uc_display_price'] = drupal_render($node->content['display_price']);
        $vars['fusion_uc_add_to_cart'] = drupal_render($node->content['add_to_cart']);
        $vars['fusion_uc_sell_price'] = drupal_render($node->content['sell_price']);
        $vars['fusion_uc_cost'] = drupal_render($node->content['cost']);
        $vars['fusion_uc_weight'] = !empty($node->weight) ? drupal_render($node->content['weight']) : '';
        // Hide weight if empty
        if ($vars['fusion_uc_weight'] == '') {
            unset($node->content['weight']);
        }
        $dimensions = !empty($node->height) && !empty($node->width) && !empty($node->length);
        // Hide dimensions if empty
        $vars['fusion_uc_dimensions'] = $dimensions ? drupal_render($node->content['dimensions']) : '';
        if ($vars['fusion_uc_dimensions'] == '') {
            unset($node->content['dimensions']);
        }
        $list_price = !empty($node->list_price) && $node->list_price > 0;
        // Hide list price if empty or zero
        $vars['fusion_uc_list_price'] = $list_price ? drupal_render($node->content['list_price']) : '';
        if ($vars['fusion_uc_list_price'] == '') {
            unset($node->content['list_price']);
        }
        $vars['fusion_uc_additional'] = drupal_render($node->content);
        // Render remaining fields
    }
}
Esempio n. 10
0
function zeropoint_preprocess_node(&$vars)
{
    $vars['template_files'][] = 'node-' . $vars['nid'];
    //print_r($vars);
    if ($vars['user']->uid) {
        $vars['content'] = preg_replace('~<foranonym>.*</foranonym>~s', '', $vars['content']);
    }
    $vars['content'] = preg_replace('~"http://baza-voprosov.ru/~', '"/', $vars['content']);
    // Build array of handy node classes
    $node_classes = array();
    $node_classes[] = $vars['zebra'];
    // Node is odd or even
    $node_classes[] = !$vars['node']->status ? 'node-unpublished' : '';
    // Node is unpublished
    $node_classes[] = $vars['sticky'] ? 'sticky' : '';
    // Node is sticky
    $node_classes[] = isset($vars['node']->teaser) ? 'teaser' : 'full-node';
    // Node is teaser or full-node
    $node_classes[] = 'node-type-' . $vars['node']->type;
    // Node is type-x, e.g., node-type-page
    // Add any taxonomy terms for node teasers
    if ($vars['teaser'] && isset($vars['taxonomy'])) {
        foreach ($vars['taxonomy'] as $taxonomy_id_string => $term_info) {
            $taxonomy_id = array_pop(explode('_', $taxonomy_id_string));
            $node_classes[] = 'tag-' . $taxonomy_id;
            // Node teaser has terms (tag-x)
            //      $taxonomy_name = id_safe($term_info['title']);
            //      if ($taxonomy_name) {
            //        $node_classes[] = 'tag-'. $taxonomy_name;                              // Node teaser has terms (tag-name)
            //      }
        }
    }
    $node_classes = array_filter($node_classes);
    // Remove empty elements
    $vars['node_classes'] = implode(' ', $node_classes);
    // Implode class list with spaces
    // Add node regions
    $vars['node_middle'] = theme('blocks', 'node_middle');
    $vars['node_bottom'] = theme('blocks', 'node_bottom');
    // Render Ubercart fields into separate variables for node-product.tpl.php
    if (module_exists('uc_product') && uc_product_is_product($vars) && $vars['template_files'][0] == 'node-product') {
        $node = node_build_content(node_load($vars['nid']));
        $vars['uc_image'] = drupal_render($node->content['image']);
        $vars['uc_body'] = drupal_render($node->content['body']);
        $vars['uc_display_price'] = drupal_render($node->content['display_price']);
        $vars['uc_add_to_cart'] = drupal_render($node->content['add_to_cart']);
        $vars['uc_weight'] = drupal_render($node->content['weight']);
        $vars['uc_dimensions'] = drupal_render($node->content['dimensions']);
        $vars['uc_model'] = drupal_render($node->content['model']);
        $vars['uc_list_price'] = drupal_render($node->content['list_price']);
        $vars['uc_sell_price'] = drupal_render($node->content['sell_price']);
        $vars['uc_cost'] = drupal_render($node->content['cost']);
        $vars['uc_additional'] = drupal_render($node->content);
    }
    // Node Theme Settings
    // Date & author
    if (!module_exists('submitted_by')) {
        $date = t('') . format_date($vars['node']->created, 'medium');
        // Format date as small, medium, or large
        $author = theme('username', $vars['node']);
        $author_only_separator = t('');
        $author_date_separator = t(' &#151; ');
        $submitted_by_content_type = theme_get_setting('submitted_by_enable_content_type') == 1 ? $vars['node']->type : 'default';
        $date_setting = theme_get_setting('submitted_by_date_' . $submitted_by_content_type) == 1;
        $author_setting = theme_get_setting('submitted_by_author_' . $submitted_by_content_type) == 1;
        $author_separator = $date_setting ? $author_date_separator : $author_only_separator;
        $date_author = $date_setting ? $date : '';
        $date_author .= $author_setting ? $author_separator . $author : '';
        $vars['submitted'] = $date_author;
    }
    // Taxonomy
    $taxonomy_content_type = theme_get_setting('taxonomy_enable_content_type') == 1 ? $vars['node']->type : 'default';
    $taxonomy_display = theme_get_setting('taxonomy_display_' . $taxonomy_content_type);
    $taxonomy_format = theme_get_setting('taxonomy_format_' . $taxonomy_content_type);
    if (module_exists('taxonomy') && ($taxonomy_display == 'all' || $taxonomy_display == 'only' && $vars['page'])) {
        $vocabularies = taxonomy_get_vocabularies($vars['node']->type);
        $output = '';
        $term_delimiter = ' | ';
        foreach ($vocabularies as $vocabulary) {
            if (theme_get_setting('taxonomy_vocab_hide_' . $taxonomy_content_type . '_' . $vocabulary->vid) != 1) {
                $terms = taxonomy_node_get_terms_by_vocabulary($vars['node'], $vocabulary->vid);
                if ($terms) {
                    $term_items = '';
                    foreach ($terms as $term) {
                        // Build vocabulary term items
                        $term_link = l($term->name, taxonomy_term_path($term), array('attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description))));
                        $term_items .= '<li class="vocab-term">' . $term_link . $term_delimiter . '</li>';
                    }
                    if ($taxonomy_format == 'vocab') {
                        // Add vocabulary labels if separate
                        $output .= '<li class="vocab vocab-' . $vocabulary->vid . '"><span class="vocab-name">' . check_plain($vocabulary->name) . ':</span> <ul class="vocab-list">';
                        //$output .= '<li class="vocab vocab-'. $vocabulary->vid .'"> <ul class="vocab-list">';
                        $output .= substr_replace($term_items, '</li>', -(strlen($term_delimiter) + 5)) . '</ul></li>';
                    } else {
                        $output .= $term_items;
                    }
                }
            }
        }
        if ($output != '') {
            $output = $taxonomy_format == 'list' ? substr_replace($output, '</li>', -(strlen($term_delimiter) + 5)) : $output;
            $output = '<ul class="taxonomy">' . $output . '</ul>';
        }
        $vars['terms'] = $output;
    } else {
        $vars['terms'] = '';
    }
}
Esempio n. 11
0
 public function testProductClassForm()
 {
     // Try making a new product class.
     $class = strtolower($this->randomMachineName(12));
     $edit = array('type' => $class, 'name' => $class, 'description' => $this->randomMachineName(32), 'uc_product[product]' => 1);
     $this->drupalPostForm('admin/structure/types/add', $edit, 'Save content type');
     $this->assertTrue(uc_product_is_product($class), 'The new content type is a product class.');
     // Make an existing node type a product class.
     $type = $this->drupalCreateContentType(array('description' => $this->randomMachineName()));
     $edit = array('uc_product[product]' => 1);
     $this->drupalPostForm('admin/structure/types/manage/' . $type->getOriginalId(), $edit, 'Save content type');
     $this->assertTrue(uc_product_is_product($type->getOriginalId()), 'The updated content type is a product class.');
     // Check the product classes page
     $this->drupalGet('admin/store/products/classes');
     $this->assertText($type->getOriginalId(), 'Product class is listed.');
     $this->assertText($type->getDescription(), 'Product class description is listed.');
     $this->assertLinkByHref('admin/structure/types/manage/' . $type->getOriginalId(), 0, 'Product class edit link is shown.');
     $this->assertLinkByHref('admin/structure/types/manage/' . $type->getOriginalId() . '/delete', 0, 'Product class delete link is shown.');
     // Remove the product class again.
     $edit = array('uc_product[product]' => 0);
     $this->drupalPostForm('admin/structure/types/manage/' . $class, $edit, 'Save content type');
     $this->assertTrue(uc_product_is_product($class), 'The updated content type is no longer a product class.');
 }