class TestPriceResolver in Commerce Core 8.2
Test price resolver.
Hierarchy
- class \Drupal\commerce_price_test\TestPriceResolver implements PriceResolverInterface
Expanded class hierarchy of TestPriceResolver
1 string reference to 'TestPriceResolver'
- commerce_price_test.services.yml in modules/
price/ tests/ modules/ commerce_price_test/ commerce_price_test.services.yml - modules/price/tests/modules/commerce_price_test/commerce_price_test.services.yml
1 service uses TestPriceResolver
- commerce_test.test_price_resolver in modules/
price/ tests/ modules/ commerce_price_test/ commerce_price_test.services.yml - Drupal\commerce_price_test\TestPriceResolver
File
- modules/
price/ tests/ modules/ commerce_price_test/ src/ TestPriceResolver.php, line 14
Namespace
Drupal\commerce_price_testView source
class TestPriceResolver implements PriceResolverInterface {
/**
* {@inheritdoc}
*/
public function resolve(PurchasableEntityInterface $entity, $quantity, Context $context) {
if (!($entity instanceof ProductVariationInterface && strpos($entity
->getSku(), 'TEST_') !== FALSE)) {
return NULL;
}
$field_name = $context
->getData('field_name', 'price');
if ($entity
->hasField($field_name) && !$entity
->get($field_name)
->isEmpty()) {
/** @var \Drupal\commerce_price\Price $price */
$price = $entity
->get($field_name)
->first()
->toPrice();
return $price
->subtract(new Price('3', $price
->getCurrencyCode()));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TestPriceResolver:: |
public | function |
Resolves a price for the given purchasable entity. Overrides PriceResolverInterface:: |