/** * This function will create recurring order and entity programmatically. * @param $product_ids * @return \entity */ public static function createProgrammatically($product_ids) { global $user; global $entities; $product = array(); $quantity = 1; $uid = $user->uid; $add_shipping = FALSE; // $subscription_products = Utils::getSubscriptionProductsList()->verify(get_class()); foreach ($product_ids as $product_id) { if ($product = commerce_product_load($product_id)) { if ($product->type == 'product') { $add_shipping = TRUE; } if (in_array($product->sku, $subscription_products)) { $product->commerce_price[LANGUAGE_NONE][0]['amount'] = 0; $line_item = commerce_product_line_item_new($product, $quantity); } else { $line_item = commerce_product_line_item_new($product, $quantity); } commerce_cart_product_add($uid, $line_item); } } // if no product loaded then need to return null if (empty($product)) { return NULL; } $order = commerce_cart_order_load($uid); $order = commerce_order_status_update($order, "pending", TRUE); if ($add_shipping) { // Save and add the line item to the order. $line_item = new Shipping(NULL, $order->order_id); $line_item = $line_item->createShippingLineItemProgrammatically($order); $new_line_item = commerce_shipping_add_shipping_line_item($line_item, $order, TRUE); } commerce_avatax_calculate_sales_tax($order); commerce_order_save($order); drupal_static_reset('commerce_recurring_order_load_recurring_line_items'); commerce_checkout_complete($order); $order_object = new CommerceOrder($order->order_id); $entities['commerce_order'][$order_object->getId()] = $order_object; $order_object->reload(); return new Response(TRUE, $order_object, ""); }
/** * Default constructor for the Commerce Product object. Do not call this * class directly. Create a separate class for each product type and use its * constructor. * * @param int $product_id * Product id if an existing product is to be loaded. */ public function __construct($product_id = NULL) { $class = new \ReflectionClass(get_called_class()); $type = Utils::makeSnakeCase($class->getShortName()); if (!is_null($product_id)) { $product = NULL; if (is_numeric($product_id)) { $product = commerce_product_load($product_id); } if ($product && $product->type == $type) { parent::__construct($product); return; } // SKU might have been passed instead. $product = commerce_product_load_by_sku($product_id); if ($product && $product->type == $type) { parent::__construct($product); return; } if (!$product) { $this->setErrors("Product with id or sku {$product_id} and type {$type} does not exist."); $this->setInitialized(FALSE); return; } } else { $product = commerce_product_new($type); parent::__construct($product); } }
public function generatePaymentToken($order, $payment_method) { global $user; $config = array(); $shippingAddressConfig = null; $order_wrapper = entity_metadata_wrapper('commerce_order', $order); $billing_address = $order_wrapper->commerce_customer_billing->commerce_customer_address->value(); $order_array = $order_wrapper->commerce_order_total->value(); $product_line_items = $order->commerce_line_items[LANGUAGE_NONE]; if (isset($order)) { $orderId = $order->order_id; $default_currency = commerce_default_currency(); $amountCents = number_format(commerce_currency_convert($order->commerce_order_total['und'][0]['amount'], $order_array['currency_code'], $default_currency), 0, '', ''); $scretKey = $payment_method['settings']['private_key']; $mode = $payment_method['settings']['mode']; $timeout = $payment_method['settings']['timeout']; $config['authorization'] = $scretKey; $config['mode'] = $mode; $config['timeout'] = $timeout; if ($payment_method['settings']['payment_action'] == 'authorize') { $config = array_merge($config, $this->_authorizeConfig()); } else { $config = array_merge($config, $this->_captureConfig($payment_method)); } $products = array(); if (!empty($product_line_items)) { foreach ($product_line_items as $key => $item) { $line_item[$key] = commerce_line_item_load($item['line_item_id']); $product_id = $line_item[$key]->commerce_product['und'][0]['product_id']; $product = commerce_product_load($product_id); $price = commerce_product_calculate_sell_price($product); $sell_price = number_format(commerce_currency_amount_to_decimal($price['amount'], $price['currency_code']), 2, '.', ''); $products[$key] = array('name' => commerce_line_item_title($line_item[$key]), 'sku' => $line_item[$key]->line_item_label, 'price' => $sell_price, 'quantity' => (int) $line_item[$key]->quantity); } } $billingAddressConfig = array('addressLine1' => $billing_address['thoroughfare'], 'addressLine2' => $billing_address['premise'], 'postcode' => $billing_address['postal_code'], 'country' => $billing_address['country'], 'city' => $billing_address['locality']); if (module_exists('commerce_shipping') && !empty($order_wrapper->commerce_customer_shipping->commerce_customer_address)) { $shipping_address = $order_wrapper->commerce_customer_shipping->commerce_customer_address->value(); // Add the shipping address parameters to the request. $shippingAddressConfig = array('addressLine1' => $shipping_address['thoroughfare'], 'addressLine2' => $shipping_address['premise'], 'postcode' => $shipping_address['postal_code'], 'country' => $shipping_address['country'], 'city' => $shipping_address['locality']); } $config['postedParam'] = array_merge($config['postedParam'], array('email' => $order->mail, 'value' => $amountCents, 'trackId' => $orderId, 'currency' => $default_currency, 'description' => 'Order number::' . $orderId, 'shippingDetails' => $shippingAddressConfig, 'products' => $products, 'card' => array('billingDetails' => $billingAddressConfig))); $Api = CheckoutApi_Api::getApi(array('mode' => $mode)); $paymentTokenCharge = $Api->getPaymentToken($config); $paymentTokenArray = array('message' => '', 'success' => '', 'eventId' => '', 'token' => ''); if ($paymentTokenCharge->isValid()) { $paymentTokenArray['token'] = $paymentTokenCharge->getId(); $paymentTokenArray['success'] = true; } else { $paymentTokenArray['message'] = $paymentTokenCharge->getExceptionState()->getErrorMessage(); $paymentTokenArray['success'] = false; $paymentTokenArray['eventId'] = $paymentTokenCharge->getEventId(); } } return $paymentTokenArray; }
/** * This function is for get reference product from recurring entity * @return bool|Recurring */ public function getCommerceRecurringRefProductValues() { $recurring_entity = $this->getEntity(); $ref_product = field_get_items('commerce_recurring', $recurring_entity, 'commerce_recurring_ref_product'); if (!empty($ref_product) && isset($ref_product[0]['target_id'])) { $product_id = $ref_product[0]['target_id']; $product = commerce_product_load($product_id); $product_class = Utils::makeTitleCase($product->type); $field_class = "RedTest\\entities\\CommerceProduct\\" . $product_class; $product_obj = new $field_class($product_id); return new Response(TRUE, $product_obj, ""); } else { return new Response(FALSE, NULL, 'Reference product not available.'); } }
public function submitFormCharge($payment_method, $pane_form, $pane_values, $order, $charge) { $config = array(); $shipping_array = array(); $order_wrapper = entity_metadata_wrapper('commerce_order', $order); $billing_address = $order_wrapper->commerce_customer_billing->commerce_customer_address->value(); $order_array = $order_wrapper->commerce_order_total->value(); $default_currency = commerce_default_currency(); $amountCents = number_format(commerce_currency_convert($charge['amount'], $order_array['currency_code'], $default_currency), 0, '', ''); $config['authorization'] = $payment_method['settings']['private_key']; $config['mode'] = $payment_method['settings']['mode']; $currency_code = $order_array['currency_code']; $i = 0; $config['postedParam'] = array('email' => $order->mail, 'value' => $amountCents, 'currency' => $default_currency, 'trackId' => $order->order_id, 'card' => array('name' => "{$billing_address['first_name']} {$billing_address['last_name']}", 'billingDetails' => array('addressLine1' => $billing_address['thoroughfare'], 'addressLine2' => $billing_address['premise'], 'postcode' => $billing_address['postal_code'], 'country' => $billing_address['country'], 'city' => $billing_address['locality']))); $products = null; foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) { $product_id = $line_item_wrapper->commerce_product->raw(); $product = commerce_product_load($product_id); $price = commerce_product_calculate_sell_price($product); $sell_price = number_format(commerce_currency_amount_to_decimal($price['amount'], $price['currency_code']), 2, '.', ''); // Add the line item to the return array. $products[$i] = array('productName' => commerce_line_item_title($line_item_wrapper->value()), 'price' => $sell_price, 'quantity' => round($line_item_wrapper->quantity->value()), 'sku' => ''); // If it was a product line item, add the SKU. if (in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) { $products[$i]['sku'] = $line_item_wrapper->line_item_label->value(); } $i++; } if ($products && !empty($products)) { $config['postedParam']['products'] = $products; } if (module_exists('commerce_shipping') && !empty($order_wrapper->commerce_customer_shipping->commerce_customer_address)) { $shipping_address = $order_wrapper->commerce_customer_shipping->commerce_customer_address->value(); // Add the shipping address parameters to the request. $shipping_array = array('addressLine1' => $shipping_address['thoroughfare'], 'addressLine2' => $shipping_address['premise'], 'postcode' => $shipping_address['postal_code'], 'country' => $shipping_address['country'], 'city' => $shipping_address['locality']); $config['postedParam']['shippingDetails'] = $shipping_array; } if ($payment_method['settings']['payment_action'] == COMMERCE_CREDIT_AUTH_CAPTURE) { $config = array_merge_recursive($this->_captureConfig($payment_method), $config); } else { $config = array_merge_recursive($this->_authorizeConfig($payment_method), $config); } return $config; }
// $theNode = $wrapper->getIdentifier(); // $theReference = node_load($theNode); // print $theNode; // print $wrapper->label(); // print $wrapper->field_description->value(); //print drupal_render($wrapper->propertyInfo['bundles']['product']['properties']); //required paths for loading wrapper require_once drupal_get_path('module', 'commerce_product') . '/includes/commerce_product.forms.inc'; require_once drupal_get_path('module', 'commerce_product') . '/includes/commerce_product_ui.products.inc'; //$passwordForm = drupal_get_form('commerce_product_ui_product_form', 'product'); //$form = commerce_product_ui_product_form_wrapper(commerce_product_load(119000)); //$form = entity_metadata_wrapper(commerce_product_new('product')); // $form['#ajax_processed'] = TRUE; //$productId = 119000; //commerce product new creates a new product and load brings in it for the form to edit. $form = commerce_product_ui_product_form_wrapper(commerce_product_load(1)); //kpr($form); //$form = (commerce_product_load(1)); $date = getdate(); //$form_state = array(); //$form_state['values']['title'] = "Course Draft Started on " . $date['mon'] . "." . $date['mday'] . "." . $date['year']; //$renderedForm = render($newForm); // commerce_product_ui_product_form_submit($newForm, &$form_state); // drupal_form_submit('commerce_product_ui_product_form', &$form_state); //$editForm = commerce_product_ui_product_form_wrapper(commerce_product_load($productId)); //$passwordForm = drupal_get_form('user_pass'); // print render($form['field_course_upload']); // print $newForm->get_value($newForm, 'product_id'); print render($form); // print render($form['uploads']); // print render($form['basics']);
foreach ($rows as $row_count => $row) { ?> <tr <?php if ($row_classes[$row_count]) { print 'class="' . implode(' ', $row_classes[$row_count]) . '"'; } ?> > <?php foreach ($row as $field => $content) { ?> <?php if ($field != 'product_id') { ?> <?php $product = commerce_product_load((int) $row['product_id']); $query = new EntityFieldQuery(); $result = $query->entityCondition('entity_type', 'node', '=')->propertyCondition('type', 'product')->fieldCondition('field_product_ref', 'product_id', (int) $row['product_id'], '=')->range(0, 1)->execute(); $nids = array(); foreach ($result['node'] as $node) { $nids[] = $node->nid; } $node = node_load((int) $nids[0]); ?> <?php if ($field == 'line_item_title') { ?> <td <?php if ($field_classes[$field][$row_count]) { print 'class="td-item ' . $field_classes[$field][$row_count] . '" '; }
} } $f = fopen('files/' . $_GET['filename'], 'w+'); fwrite($f, file_get_contents('php://input')); fclose($f); print "success\n"; include_once '../../../../includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE); $file = $_SERVER["DOCUMENT_ROOT"] . '/sites/all/modules/import1c/files/offers.xml'; $xml = simplexml_load_file($file); foreach ($xml->ПакетПредложений->Предложения as $product) { foreach ($product as $item) { $product_id = db_select('commerce_product', 'c')->fields('c')->condition('c.sku', $item->Ид)->execute()->fetchObject(); if (!empty($product_id->product_id)) { //обновляем товар если он есть $tovar = commerce_product_load($product_id->product_id); $form_state = array(); $form_state['values'] = array(); $form = array(); $form['#parents'] = array(); $price = array(LANGUAGE_NONE => array(0 => array('amount' => $item->Цены->Цена->ЦенаЗаЕдиницу * 100, 'currency_code' => 'RUB'))); $form_state['values']['commerce_price'] = $price; field_attach_submit('product', $tovar, $form, $form_state); commerce_product_save($tovar); } else { //добавляем товар если его нет $form_state = array(); $form_state['values'] = ''; $form = array(); $form['#parents'] = array(); $new_product = commerce_product_new('product');
<?php $product = commerce_product_load((int) $row->commerce_product_field_data_commerce_product_product_id); $query = new EntityFieldQuery(); $result = $query->entityCondition('entity_type', 'node', '=')->propertyCondition('type', 'product')->fieldCondition('field_product_ref', 'product_id', (int) $row->commerce_product_field_data_commerce_product_product_id, '=')->range(0, 1)->execute(); $nids = array(); foreach ($result['node'] as $node) { $nids[] = $node->nid; } $node = node_load((int) $nids[0]); ?> <li> <a href="#" class="img"> <img src="<?php print image_style_url('product_thumbnail_60x79', $node->field_product_thumbnail['und'][0]['uri']); ?> " alt=""> </a> <div class="text"> <div class="name"> <?php print $node->title; ?> </div> <span class="price"><?php print $fields['commerce_total']->content; ?> </span> <a class="delete"><?php print $fields['edit_delete']->content; ?>
<div class="views-field-field-product-image"><?php print $fields['field_product_image']->content; ?> </div> <div class="views-field-title"><?php print $fields['title']->content; ?> </div> <?php $nid = strip_tags($fields['nid']->content); $node = node_load($nid); $product = commerce_product_load($node->field_product[LANGUAGE_NONE][0]['product_id']); ?> <div class="views-field-field-sell-price"><?php print commerce_currency_format($product->commerce_price[LANGUAGE_NONE][0]['amount'], 'VND'); ?> </div> <div class="views-field-field-old-price"><?php print $fields['field_old_price']->content; ?> </div> <?php $line_item = commerce_line_item_new($product->type, $order_id = 0); $line_item->data['context']['product_ids'] = array($product->product_id); $line_item->quantity = 1; $qty = 1; $form_id = commerce_cart_add_to_cart_form_id(array($product->product_id), $qty); $addtocart_form = drupal_get_form($form_id, $line_item); ?>
->commerce_price ->value(); $commerce_price = commerce_currency_format( $commerce_price_data['amount'], $commerce_price_data['currency_code'] );*/ $uid = arg(1); if (empty($uid)) { global $user; $uid = $user->uid; } $product_id = $row->product_id; $product_nid = fck_get_node_id($product_id); $jersey_print = fck_jp_get_wishlist_data($product_id, $uid, TRUE); $autograph = $jersey_print['field_autograph']; $badge = $jersey_print['field_superliga_badge']; $player = is_object($jersey_print['field_players']) ? $jersey_print['field_players']->tid : 0; $label = $jersey_print['field_text_label']; $number = $jersey_print['field_text_number']; $url = fck_generate_product_url($product_nid, $product_id, $autograph, $badge, $player, $label, $number); $title = l($output, $url); $jersey_print_output = ''; if (!empty($jersey_print)) { // $product = commerce_product_load($product_id); $jersey_print_data = $product->field_jersey_print['und'][0]['set_details']; $jersey_print_values = $jersey_print; $jersey_print_output = theme('fck_jp_attributes', array('jersey_print_values' => $jersey_print_values, 'jersey_print_data' => $jersey_print_data)); } print $title; print $jersey_print_output;
<?php $product = commerce_product_load((int) $form['product_id']['#value']); $query = new EntityFieldQuery(); $result = $query->entityCondition('entity_type', 'node', '=')->propertyCondition('type', 'product')->fieldCondition('field_product_ref', 'product_id', (int) $form['product_id']['#value'], '=')->range(0, 1)->execute(); $nids = array(); foreach ($result['node'] as $node) { $nids[] = $node->nid; } $node = node_load((int) $nids[0]); if (isset($form['#is_product_page']) && $form['#is_product_page'] && isset($form['attributes'])) { ?> <div id="attribute" class="attribute clearfix"> <?php if (isset($form['attributes'])) { ?> <fieldset class="attribute_fieldset"> <label class="attribute_label"><?php print t('Color'); ?> :</label> <div class="attribute_list"> <ul class="attribute_color"> <?php foreach ($form['attributes']['field_product_colors']['#options'] as $id => $color) { ?> <?php $color = md_orenmode_get_color($id); ?> <?php if ($id == $form['attributes']['field_product_colors']['#default_value']) {
?> </span> <?php } ?> <span class="product_sku"><?php print render($content['product:sku']); ?> </span></span> <div class="hr _1"></div> <div class="price-box"> <?php for ($i = 0; $i < count($node->field_product_ref['und']); $i++) { ?> <?php $product = commerce_product_load((int) $node->field_product_ref['und'][$i]['product_id']); ?> <div class="product-price product-price-<?php print $product->field_product_colors['und'][0]['tid']; ?> -<?php print $product->field_product_size['und'][0]['tid']; ?> " <?php if ($i > 0) { print 'style="display:none"'; } ?> > <p class="special-price"> <span class="price">