protected function completeCSVertical()
 {
     $order_line = field_get_items('commerce_order', $this->datasources["order"], 'commerce_line_items');
     $line_item_ids[] = $order_line[0]['line_item_id'];
     $line_item = commerce_line_item_load_multiple($line_item_ids);
     $product_ids = array();
     $tmp = field_get_items('commerce_line_item', $line_item[0], 'commerce_product');
     $product_ids[] = $tmp[0]['product_id'];
     $products = commerce_product_load_multiple($product_ids);
     $item = $products[0];
     if (property_exists($item, "csmdd32")) {
         $datosCS["CSMDD32"] = $item->csmdd32[LANGUAGE_NONE][0]["value"];
     }
     return array_merge($this->getMultipleProductsInfo(), $datosCS);
 }
 protected function getMultipleProductsInfo()
 {
     $order_lines = field_get_items('commerce_order', $this->datasources["order"], 'commerce_line_items');
     $line_item_ids = array();
     foreach ($order_lines as $order_line) {
         $line_item_ids[] = $order_line['line_item_id'];
     }
     $line_items = commerce_line_item_load_multiple($line_item_ids);
     $product_ids = array();
     $cant_prod = array();
     foreach ($line_items as $line_item) {
         $tmp = field_get_items('commerce_line_item', $line_item, 'commerce_product');
         $cant_prod[$tmp[0]['product_id']] = round($line_item->quantity);
         $product_ids[] = $tmp[0]['product_id'];
     }
     $products = commerce_product_load_multiple($product_ids);
     $code = array();
     $description = array();
     $name = array();
     $sku = array();
     $total = array();
     $quantity = array();
     $unit = array();
     foreach ($products as $item) {
         $code[] = $this->getCategoryArray($item);
         if (!empty($item->description)) {
             $desc = $item->description;
         } else {
             $desc = $item->title;
         }
         $desc = strip_tags($desc);
         $desc = TodoPago\Sdk::sanitizeValue($desc);
         $desc = substr($desc, 0, 50);
         $description[] = $desc;
         $name[] = substr($item->title, 0, 250);
         $sku[] = substr(empty($item->sku) ? $item->product_id : $item->sku, 0, 250);
         $total[] = number_format(commerce_currency_amount_to_decimal($item->commerce_price[LANGUAGE_NONE][0]["amount"], $item->commerce_price[LANGUAGE_NONE][0]["currency_code"]) * $cant_prod[$item->product_id], 2, ".", "");
         $quantity[] = $cant_prod[$item->product_id];
         $unit[] = number_format(commerce_currency_amount_to_decimal($item->commerce_price[LANGUAGE_NONE][0]["amount"], $item->commerce_price[LANGUAGE_NONE][0]["currency_code"]), 2, ".", "");
     }
     $productsData = array('CSITPRODUCTCODE' => join("#", $code), 'CSITPRODUCTDESCRIPTION' => join("#", $description), 'CSITPRODUCTNAME' => join("#", $name), 'CSITPRODUCTSKU' => join("#", $sku), 'CSITTOTALAMOUNT' => join("#", $total), 'CSITQUANTITY' => join("#", $quantity), 'CSITUNITPRICE' => join("#", $unit));
     return $productsData;
 }
Example #3
0
/**
 * Override or insert variables into the node templates.
 */
function joost_preprocess_node(&$vars)
{
    switch ($vars['type']) {
        case 'ready_made_':
            foreach ($vars['node']->field_ready_made_ref[LANGUAGE_NONE] as $product_id) {
                $product_ids[] = $product_id['product_id'];
                // dsm($product_id);
                //dsm($product_ids);
            }
            $products = commerce_product_load_multiple($product_ids);
            $product_prices = array();
            foreach ($products as $product_id => $product) {
                $product_wrapper = entity_metadata_wrapper('commerce_product', $product);
                $product_prices[] = $product_wrapper->commerce_price->amount->value();
                $count_prices = count($product_prices);
                // dsm($count_prices);
            }
            sort($product_prices, SORT_NUMERIC);
            $lower = commerce_currency_format(reset($product_prices), 'GBP');
            $upper = commerce_currency_format(end($product_prices), 'GBP');
            $price_range = "{$lower} - {$upper}";
            $price_lower = "{$lower}";
            if ($count_prices == 1) {
                $vars['content']['product:commerce_price'][0]['#markup'] = $price_lower;
            } else {
                $vars['content']['product:commerce_price'][0]['#markup'] = $price_range;
            }
            break;
    }
}
 /**
  * Constructor for the Add to cart form. Provide $nid as the id of the
  * product display node. Other optional arguments are product reference field
  * name, view mode of the product display node and language of the product
  * display node. If optional arguments are not provided, their default values
  * are assumed, which are "field_product", "default" and "en" respectively.
  *
  * @param int $nid
  *   Product display node id.
  */
 public function __construct($nid)
 {
     $args = func_get_args();
     array_shift($args);
     $field_name = array_shift($args);
     $view_mode = array_shift($args);
     $language = array_shift($args);
     if (is_null($field_name)) {
         $field_name = 'field_product';
     }
     if (is_null($view_mode)) {
         $view_mode = 'default';
     }
     if (is_null($language)) {
         $language = 'en';
     }
     $node = node_load($nid);
     $instance = field_info_instance('node', $field_name, $node->type);
     $display = field_get_display($instance, $view_mode, $node);
     $settings = array_merge(field_info_formatter_settings($display['type']), $display['settings']);
     $field_product = field_get_items('node', $node, $field_name);
     $product_id = $field_product[0]['product_id'];
     $products = commerce_product_load_multiple(array($product_id));
     $type = !empty($settings['line_item_type']) ? $settings['line_item_type'] : 'product';
     $line_item = commerce_product_line_item_new(commerce_product_reference_default_product($products), $settings['default_quantity'], 0, array(), $type);
     $line_item->data['context']['product_ids'] = array_keys($products);
     $line_item->data['context']['add_to_cart_combine'] = !empty($settings['combine']);
     $line_item->data['context']['show_single_product_attributes'] = !empty($settings['show_single_product_attributes']);
     $cart_context = array('entity_type' => 'node', 'entity_id' => $nid, 'display' => 'default', 'language' => $language);
     $cart_context['class_prefix'] = $cart_context['entity_type'] . '-' . $nid;
     $cart_context['view_mode'] = $cart_context['entity_type'] . '_' . $view_mode;
     $entity_uri = entity_uri($cart_context['entity_type'], $node);
     $arguments = array('form_id' => commerce_cart_add_to_cart_form_id(array($product_id)), 'line_item' => $line_item, 'show_quantity' => $settings['show_quantity']);
     // Add the display path and referencing entity data to the line item.
     if (!empty($entity_uri['path'])) {
         $arguments['line_item']->data['context']['display_path'] = $entity_uri['path'];
     }
     $arguments['line_item']->data['context']['entity'] = array('entity_type' => $cart_context['entity_type'], 'entity_id' => $cart_context['entity_id'], 'product_reference_field_name' => $field_name);
     // Update the product_ids variable to point to the entity data if we're
     // referencing multiple products.
     if (count($arguments['line_item']->data['context']['product_ids']) > 1) {
         $arguments['line_item']->data['context']['product_ids'] = 'entity';
     }
     parent::__construct($arguments['form_id'], $arguments['line_item'], $arguments['show_quantity'], $cart_context);
     $this->cart_context = $cart_context;
     $this->arguments = $arguments;
 }
Example #5
0
/**
 * Find the prices for a given legal status based on the products.
 */
function devis_get_prices_from_legal_status($legal_status)
{
    $product_key = trois_devis_get_product_from_status($legal_status);
    $products = commerce_product_load_multiple(array(), array('type' => 'devis'));
    $keep = $temp = $order = array();
    foreach ($products as $key => $product) {
        if (substr($product->sku, 0, -5) == $product_key) {
            $price = commerce_product_calculate_sell_price($product);
            $price_display = commerce_currency_format($price['amount'], $price['currency_code'], $product);
            $temp[$key] = $price_display;
            $order[$key] = $price['amount'];
        }
    }
    asort($order, SORT_NUMERIC);
    foreach ($order as $key => $price) {
        $keep[$key] = $temp[$key];
    }
    return $keep;
}
/**
 * Alter a field value, just before building a rules condition from it.
 * Specifically: if the structure of the 'condition_settings' array as saved in
 * the field does not exactly match the parameters expected by the corresponding
 * rules condition, this hook allows transforming the former into the latter.
 *
 * @param array $value
 *   A single field value from an "inline_conditions" type field. This means
 *   it typically contains two keys:
 *   - 'condition_name': the condition name as defined in
 *     hook_inline_conditions_info() and hook_rules_condition_info().
 *   - 'condition_settings': an array containing all configured settings;
 *     typically this will match the values of the form elements defined in the
 *     'configure' callback. It should be transformed into an array of parameter
 *     values as the rules condition needs them. (Not including the line item.)
 *     Your 'build' callback will be passed the same parameter values.
 *
 * @see inline_conditions_build().
 */
function hook_inline_conditions_build_alter(&$value)
{
    if ($value['condition_name'] == 'commerce_order_contains_products') {
        // 'products' is a text field in the configure form: comma-separated SKUs.
        // It has a #validate function that turns submitted input into form value:
        //     array( array('product_id' => P1), array('product_id' => P2), ...)
        // so that's how it gets stored into 'condition_settings'.
        // Load the products...
        $entity_ids = array();
        foreach ($value['condition_settings']['products'] as $delta) {
            $entity_ids[] = reset($delta);
        }
        $products = commerce_product_load_multiple($entity_ids);
        // ...so we can turn it back into a comma-separated string of SKUs.
        $value['condition_settings']['products'] = '';
        foreach ($products as $product) {
            $value['condition_settings']['products'] .= $product->sku;
            if ($product !== end($products)) {
                $value['condition_settings']['products'] .= ', ';
            }
        }
    }
}
 /**
  * Returns an associative array of number of items present in the line item
  * keyed by the SKU.
  *
  * @return array
  *   Associative array of number of items present in the line item keyed by
  *   the SKU
  */
 public function getProductSKUQuantityMap()
 {
     $output = array();
     $products = $this->getFieldItems('commerce_product');
     $quantity = $this->getEntity()->quantity;
     $product_ids = array();
     foreach ($products as $product) {
         $product_ids[] = $product['product_id'];
     }
     $commerce_products = commerce_product_load_multiple($product_ids);
     foreach ($commerce_products as $product_id => $product) {
         $sku = $product->sku;
         if (array_key_exists($sku, $output)) {
             $output[$sku] += $quantity;
         } else {
             $output[$sku] = $quantity;
         }
     }
     return $output;
 }