Esempio n. 1
0
 /**
  * Get field layout definition.
  *
  * @param FieldLayoutModel $fieldLayout
  *
  * @return array
  */
 public function getFieldLayoutDefinition(FieldLayoutModel $fieldLayout)
 {
     if ($fieldLayout->getTabs()) {
         $tabDefinitions = [];
         foreach ($fieldLayout->getTabs() as $tab) {
             $tabDefinitions[$tab->name] = $this->getFieldLayoutFieldsDefinition($tab->getFields());
         }
         return ['tabs' => $tabDefinitions];
     }
     return ['fields' => $this->getFieldLayoutFieldsDefinition($fieldLayout->getFields())];
 }
 /**
  * @throws \Craft\Exception
  * @throws \Exception
  */
 private function defaultProductTypes()
 {
     $productType = new Market_ProductTypeModel();
     $productType->name = 'Plain Shirts';
     $productType->handle = 'plainShirts';
     $productType->hasUrls = true;
     $productType->hasVariants = false;
     $productType->template = 'commerce/products/_product';
     $productType->urlFormat = 'commerce/products/{slug}';
     $fieldLayout = FieldLayoutModel::populateModel(['type' => 'Market_Product']);
     \Craft\craft()->fields->saveLayout($fieldLayout);
     $productType->asa('productFieldLayout')->setFieldLayout($fieldLayout);
     $variantFieldLayout = FieldLayoutModel::populateModel(['type' => 'Market_Variant']);
     \Craft\craft()->fields->saveLayout($variantFieldLayout);
     $productType->asa('variantFieldLayout')->setFieldLayout($variantFieldLayout);
     \Craft\craft()->market_productType->save($productType);
 }