This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// In folder `src/Form/`. | |
namespace Drupal\modulename\Form; | |
use Drupal\commerce\Context; | |
use Drupal\commerce_cart\Form\AddToCartForm; | |
use Drupal\commerce_product\Entity\ProductVariation; | |
use Drupal\Core\Form\FormStateInterface; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"mfacenet/hello-world": "v1.*" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$order_type = "default"; | |
$store_id = 1; | |
$uid = 0; | |
$entity_type_manager = \Drupal::service('entity_type.manager'); | |
$order_storage = $entity_type_manager->getStorage('commerce_order'); | |
$new_order = $orderStorage->create([ | |
'type' => $order_type, | |
'store_id' => $store_id, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_form_FORM_ID_alter(). | |
* | |
* This will work on all cart forms without running the global hook_form_alter(). | |
*/ | |
function MODULE_form_commerce_cart_add_to_cart_form_alter(&$form, &$form_state, $form_id) { | |
$product = $form_state['default_product']; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Only meant for quick development issues where the current order | |
// is somehow borked. | |
global $user; | |
$order_id = commerce_cart_order_id($user->uid); | |
db_query("UPDATE commerce_order SET uid = 0 WHERE order_id=".$order_id)->execute(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Clones blocks from one theme to another. | |
* | |
* @param $original | |
* The machine name of the original theme. | |
* | |
* @param $new | |
* The machine name of the new theme. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_form_alter() | |
*/ | |
function MODULE_form_alter(&$form, &$form_state, $form_id) { | |
// Avoid bundle cart forms and other forms | |
if (strpos($form_id, 'commerce_cart_add_to_cart_form_') === 0) { | |
// Use the price calculation system | |
$price = commerce_product_calculate_sell_price($form_state['default_product']); | |
// Some products don't have a price, like bundles. In this case we get "NULL". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = View Price Permissions | |
description = Add a permission to view prices. Allows you to hide the price for anonymous or other roles. | |
core = 7.x | |
dependencies[] = commerce_product |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements theme_field() | |
*/ | |
function THEMENAME_field__commerce_price($variables) { | |
if ($variables['items'][0]['#markup'] == '$0.00') { | |
return '<div class="commerce-product-field field-commerce-price sr-only">Call for pricing.</div>'; | |
} else { | |
return; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_form_alter() | |
*/ | |
function THEMENAME_form_alter(&$form, &$form_state, $form_id) { | |
if (strpos($form_id,"cart_add_to_cart")) { | |
// load the node that is rendering the cart form | |
$node = node_load(array_pop(explode('_',$form_id))); | |
// hide the form | |
$form['#access'] = false; |
NewerOlder