auctions-1.0.x-dev/modules/auctions_commerce/auctions_commerce.module

modules/auctions_commerce/auctions_commerce.module
<?php

/**
 * @file
 * Contains custom hooks and functions related to auction workflow and orders.
 */

use Drupal\auctions_core\Entity\AuctionBid;
use Drupal\auctions_core\Entity\AuctionItem;
use Drupal\commerce_order\Entity\OrderItem;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements of hook_help().
 */
function auctions_commerce_help($route_name, RouteMatchInterface $route_match) {

  switch ($route_name) {
    case 'help.page.auctions_commerce':
      $modPath = Drupal::service('extension.path.resolver')->getPath('module', 'auctions_commerce');
      $readmePath = $modPath . '/README.md';
      if (is_file($readmePath)) {
        $text = \file_get_contents($readmePath, false);
        if (!\Drupal::moduleHandler()->moduleExists('markdown')) {
          return '<pre>' . $text . '</pre>';
        }
        else {
          // Use the Markdown filter to render the README.
          $filter_manager = \Drupal::service('plugin.manager.filter');
          $settings = \Drupal::configFactory()->get('markdown.settings')->getRawData();
          $config = ['settings' => $settings];
          $filter = $filter_manager->createInstance('markdown', $config);
          return $filter->process($text, 'en');
        }
      }
      else {
        return t('Please see README in Auctions base module');
      }
      break;
  }
}

/**
 * Implements hook_auctions_core_workflow_action().
 *
 * AUCTION CORE HOOK.
 *
 * allow other modules to interact upon auction_item workflow changes.
 */
function auctions_commerce_auctions_core_workflow_action(AuctionItem $auctionItem, $workflow) {
  $auctionTools = \Drupal::service('auctions_commerce.orderItem');
  switch ($workflow) {
    // Bidding open.
    case 1:
      // Auction relisted.
    case 2:
      break;

    // Auction closed.
    case 3:
      if ($auctionItem->hasBids()) {
        $topthree = $auctionItem->getBids($auctionItem->getRelistCount());
        $key = \array_keys($topthree);
        $topBid = $topthree[$key[0]];
        $auctionTools->createAuctionOrderItem($topBid);
      }
      break;
  }

}

/**
 * This is a utility function simply to give easy proceedural access.
 */
function auctions_commerce_create_auction_order_item(AuctionBid $auctionBid) {
  $orderItemToolkit = \Drupal::service('auctions_commerce.orderItem');
  $orderItem = $orderItemToolkit->createAuctionOrderItem($auctionBid);
  return $orderItem;
}

/**
 * Implements hook_ENTITY_TYPE_delete() for commerce_order_item.
 *
 * If a 'User' removes an auction_item from the cart, this function removes it.
 */
function auctions_commerce_commerce_order_item_delete(EntityInterface $entity) {
  if ($entity instanceof OrderItem && $entity->get('type')->getString() == 'auction_item') {
    // @todo Implement bid reject workflow. @bidPurchaseOffer
    // @todo Notify via email the story & owner that this order item has been removed from the cart. @bidPurchaseOffer
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc