sector_jobs-1.0.x-dev/sector_jobs.install
sector_jobs.install
<?php
use Drupal\menu_link_content\Entity\MenuLinkContent;
/**
* @file
* Install menu item for sector_jobs module.
*/
/**
* Adding post a job menu item.
*/
function sector_jobs_install(){
$item = MenuLinkContent::create([
'link' => ['uri' => 'internal:/post-a-job/basic'],
'title' => 'Post a Job',
'menu_name' => 'main-menu',
]);
$item->save();
// The store's address.
$address = [
'country_code' => 'NZ',
'address_line1' => 'Tasman Building Level 6/16-22 Anzac Avenue',
'locality' => 'Britomart',
'administrative_area' => 'Auckland',
'postal_code' => '1010',
];
$store = \Drupal\commerce_store\Entity\Store::create([
'type' => 'custom_store_type',
'uid' => 1,
'name' => 'Sector Jobs',
'mail' => 'noreply@sector.nz',
'address' => $address,
'default_currency' => 'NZD',
'billing_countries' => ['NZ'],
]);
$store->save();
// The price of the variation.
$price = new \Drupal\commerce_price\Price('99', 'NZD');
$basic = \Drupal\commerce_product\Entity\ProductVariation::create([
'type' => 'job_listing', // The default variation type is 'default'.
'sku' => 'basic', // The variation sku.
'status' => 1, // The product status. 0 for disabled, 1 for enabled.
'price' => $price,
]);
$basic->save();
$featured = \Drupal\commerce_product\Entity\ProductVariation::create([
'type' => 'job_listing', // The default variation type is 'default'.
'sku' => 'featured', // The variation sku.
'status' => 1, // The product status. 0 for disabled, 1 for enabled.
'price' => $price,
]);
$featured->save();
$product = \Drupal\commerce_product\Entity\Product::create([
'uid' => 1, // The user id that created the product.
'type' => 'job_listing', // Just like variation, the default product type is 'default'.
'title' => 'Job Listing',
'stores' => [$store], // The store we created/loaded above.
'variations' => [$basic, $featured], // The variation we created above.
]);
$product->save();
// You can also add a variation to a product using the addVariation() method.
//$product->addVariation($basic);
//$product->addVariation($featured);
//$product->save();
}
