Inheritance: extends SugarBean
Esempio n. 1
0
 public function testFormatResults()
 {
     $tempPT = new ProductTemplate();
     $tempPT->name = 'MasonUnitTest';
     $tempPT->description = "Unit'test";
     $tempPT->cost_price = 1000;
     $tempPT->discount_price = 800;
     $tempPT->list_price = 1100;
     $tempPT->save();
     $_REQUEST['data'] = '{"conditions":[{"end":"%","name":"name","op":"like_custom","value":""}],"field_list":["name","id","type_id","mft_part_num","cost_price","list_price","discount_price","pricing_factor","description","cost_usdollar","list_usdollar","discount_usdollar","tax_class_name"],"form":"EditView","group":"or","id":"EditView_product_name[1]","limit":"30","method":"query","modules":["ProductTemplates"],"no_match_text":"No Match","order":"name","populate_list":["name_1","product_template_id_1"],"post_onblur_function":"set_after_sqs"}';
     $_REQUEST['query'] = 'MasonUnitTest';
     require_once 'modules/home/quicksearchQuery.php';
     $json = getJSONobj();
     $data = $json->decode(html_entity_decode($_REQUEST['data']));
     if (isset($_REQUEST['query']) && !empty($_REQUEST['query'])) {
         foreach ($data['conditions'] as $k => $v) {
             if (empty($data['conditions'][$k]['value'])) {
                 $data['conditions'][$k]['value'] = $_REQUEST['query'];
             }
         }
     }
     $this->quickSearch = new quicksearchQuery();
     $result = $this->quickSearch->query($data);
     $resultBean = $json->decodeReal($result);
     $this->assertEquals($resultBean['fields'][0]['description'], $tempPT->description);
 }
 public static function createProductTemplateByName($name)
 {
     $currencies = Currency::getAll();
     $currencyValue = new CurrencyValue();
     $currencyValue->value = 500.54;
     $currencyValue->currency = $currencies[0];
     $productTemplate = new ProductTemplate();
     $productTemplate->name = $name;
     $productTemplate->description = 'Description';
     $productTemplate->priceFrequency = 2;
     $productTemplate->cost = $currencyValue;
     $currencyValueListPrice = new CurrencyValue();
     $currencyValueListPrice->value = 600.54;
     $currencyValueListPrice->currency = $currencies[0];
     $productTemplate->listPrice = $currencyValueListPrice;
     $currencyValueSellPrice = new CurrencyValue();
     $currencyValueSellPrice->value = 500.54;
     $currencyValueSellPrice->currency = $currencies[0];
     $productTemplate->sellPrice = $currencyValueSellPrice;
     $productTemplate->type = ProductTemplate::TYPE_PRODUCT;
     $productTemplate->status = ProductTemplate::STATUS_ACTIVE;
     $sellPriceFormula = new SellPriceFormula();
     $sellPriceFormula->type = SellPriceFormula::TYPE_EDITABLE;
     $productTemplate->sellPriceFormula = $sellPriceFormula;
     $saved = $productTemplate->save();
     assert('$saved');
     return $productTemplate;
 }
Esempio n. 3
0
 public function testLoad()
 {
     $this->assertEquals(2, Group::getCount());
     $this->assertEquals(0, Role::getCount());
     $this->assertEquals(0, Account::getCount());
     $this->assertEquals(0, Contact::getCount());
     $this->assertEquals(0, Opportunity::getCount());
     $this->assertEquals(0, Meeting::getCount());
     $this->assertEquals(0, Note::getCount());
     $this->assertEquals(0, Task::getCount());
     $this->assertEquals(1, User::getCount());
     $this->assertEquals(0, ProductCatalog::getCount());
     $this->assertEquals(0, ProductCategory::getCount());
     $this->assertEquals(0, ProductTemplate::getCount());
     $this->assertEquals(0, Product::getCount());
     $messageLogger = new MessageLogger();
     DemoDataUtil::unsetLoadedModules();
     DemoDataUtil::load($messageLogger, 3);
     $this->assertEquals(8, Group::getCount());
     $this->assertEquals(3, Role::getCount());
     $this->assertEquals(3, Account::getCount());
     $this->assertEquals(16, Contact::getCount());
     $this->assertEquals(6, Opportunity::getCount());
     $this->assertEquals(18, Meeting::getCount());
     $this->assertEquals(12, Note::getCount());
     $this->assertEquals(9, Task::getCount());
     $this->assertEquals(10, User::getCount());
     $this->assertEquals(1, ProductCatalog::getCount());
     $this->assertEquals(6, ProductCategory::getCount());
     $this->assertEquals(32, ProductTemplate::getCount());
     $this->assertEquals(59, Product::getCount());
 }
 public function testSimpleUserImportWhereAllRowsSucceed()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $import = new Import();
     $serializedData['importRulesType'] = 'ProductTemplates';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('productTemplates.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.productTemplates.tests.unit.files'));
     $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $currencies = Currency::getAll();
     $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_2' => ImportMappingUtil::makeIntegerColumnMappingData('sellPriceFormula__type'), 'column_3' => ImportMappingUtil::makeFloatColumnMappingData('sellPriceFormula__discountOrMarkupPercentage'), 'column_4' => ImportMappingUtil::makeCurrencyColumnMappingData('cost', $currencies[0]), 'column_5' => ImportMappingUtil::makeCurrencyColumnMappingData('listPrice', $currencies[0]), 'column_6' => ImportMappingUtil::makeCurrencyColumnMappingData('sellPrice', $currencies[0]), 'column_7' => ImportMappingUtil::makeIntegerColumnMappingData('priceFrequency'), 'column_8' => ImportMappingUtil::makeIntegerColumnMappingData('type'), 'column_9' => ImportMappingUtil::makeIntegerColumnMappingData('status'));
     $importRules = ImportRulesUtil::makeImportRulesByType('ProductTemplates');
     $page = 0;
     $config = array('pagination' => array('pageSize' => 50));
     //This way all rows are processed.
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     $dataProvider->getPagination()->setCurrentPage($page);
     $importResultsUtil = new ImportResultsUtil($import);
     $messageLogger = new ImportMessageLogger();
     ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger);
     $importResultsUtil->processStatusAndMessagesForEachRow();
     //Confirm that 3 models where created.
     $productTemplates = ProductTemplate::getAll();
     $this->assertEquals(2, count($productTemplates));
     $productTemplates = ProductTemplate::getByName('A Gift of Monotheists import');
     $this->assertEquals(1, count($productTemplates[0]));
     $this->assertEquals('A Gift of Monotheists import', $productTemplates[0]->name);
     $this->assertEquals(2, $productTemplates[0]->sellPriceFormula->type);
     $this->assertEquals(10, $productTemplates[0]->sellPriceFormula->discountOrMarkupPercentage);
     $this->assertEquals(180, $productTemplates[0]->sellPrice->value);
     $this->assertEquals(200, $productTemplates[0]->listPrice->value);
     $this->assertEquals(200, $productTemplates[0]->cost->value);
     $this->assertEquals(2, $productTemplates[0]->priceFrequency);
     $this->assertEquals(2, $productTemplates[0]->type);
     $this->assertEquals(2, $productTemplates[0]->status);
     $productTemplates[0]->delete();
     $productTemplates = ProductTemplate::getByName('A Gift of Monotheists import Copy');
     $this->assertEquals(1, count($productTemplates[0]));
     $this->assertEquals('A Gift of Monotheists import Copy', $productTemplates[0]->name);
     $this->assertEquals(2, $productTemplates[0]->sellPriceFormula->type);
     $this->assertEquals(5, $productTemplates[0]->sellPriceFormula->discountOrMarkupPercentage);
     $this->assertEquals(180, $productTemplates[0]->sellPrice->value);
     $this->assertEquals(200, $productTemplates[0]->listPrice->value);
     $this->assertEquals(200, $productTemplates[0]->cost->value);
     $this->assertEquals(2, $productTemplates[0]->priceFrequency);
     $this->assertEquals(2, $productTemplates[0]->type);
     $this->assertEquals(2, $productTemplates[0]->status);
     $productTemplates[0]->delete();
     //Confirm that 2 rows were processed as 'updated'.
     $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED));
     //Confirm 2 rows were processed as 'errors'.
     $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR));
     $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR);
     $this->assertEquals(0, count($beansWithErrors));
 }
 /**
  * @param RedBean_OODBBean $rowBean
  */
 public function analyzeByRow(RedBean_OODBBean $rowBean)
 {
     $resolvedAcceptableValues = ArrayUtil::resolveArrayToLowerCase(static::getAcceptableValues());
     if (!in_array(strtolower($rowBean->{$this->columnName}), $resolvedAcceptableValues)) {
         $label = Zurmo::t('ImportModule', '{attributeLabel} specified is invalid and this row will be skipped during import.', array('{attributeLabel}' => ProductTemplate::getAnAttributeLabel('sellPriceFormula')));
         $this->shouldSkipRow = true;
         $this->analysisMessages[] = $label;
     }
 }
 public function testSuperUserFetchProductDescriptionOnProductTemplateSelectAction()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $productTemplates = ProductTemplate::getAll();
     $this->assertEquals(1, count($productTemplates));
     $superProductTemplateId = self::getModelIdByModelNameAndName('ProductTemplate', 'My Product Template');
     $this->setGetArray(array('id' => $superProductTemplateId));
     $content = $this->runControllerWithNoExceptionsAndGetContent('productTemplates/default/getProductTemplateDataForProduct');
     $content = CJSON::decode($content);
     $this->assertEquals("Description", $content['productDescription']);
 }
 public function testResolveProductTemplateHasManyProductCategoriesFromPost()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $category1 = ProductCategoryTestHelper::createProductCategoryByName('Test Product Category');
     $category2 = ProductCategoryTestHelper::createProductCategoryByName('Test Product Category2');
     $productTemplate = ProductTemplateTestHelper::createProductTemplateByName('PT1');
     $postData = array('categoryIds' => $category1->id . ',' . $category2->id);
     // Not Coding Standard
     $id = $productTemplate->id;
     $productTemplate->forget();
     unset($productTemplate);
     $productTemplate = ProductTemplate::getById($id);
     $categories = ProductTemplateProductCategoriesUtil::resolveProductTemplateHasManyProductCategoriesFromPost($productTemplate, $postData);
     $this->assertEquals(count($categories), 2);
     $this->assertEquals($categories[$category1->id]->id, $category1->id);
 }
 /**
  * Gets the products random data
  * @return array
  */
 public static function getProductsRandomData()
 {
     $productNames = array('names' => array('Amazing Kid Sample', 'You Can Do Anything Sample', 'A Bend in the River November Issue', 'A Gift of Monotheists October Issue', 'Enjoy Once in a Lifetime Music'));
     $productTemplates = ProductTemplate::getAll();
     foreach ($productTemplates as $template) {
         if (strpos($template->name, 'Laptop') !== false || strpos($template->name, 'Camera') !== false || strpos($template->name, 'Handycam') !== false) {
             for ($i = 1; $i < 3; $i++) {
                 $randomString = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 2);
                 $productNames['names'][] = $template->name . '-P' . $randomString;
             }
         }
     }
     return $productNames;
 }
Esempio n. 9
0
 public function testProductSaveWithPermissions()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $contacts = Contact::getAll();
     $accounts = Account::getByName('superAccount');
     $opportunities = Opportunity::getByName('superOpportunity');
     $productTemplates = ProductTemplate::getByName('superProductTemplate');
     $account = $accounts[0];
     $user = $account->owner;
     $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $explicitReadWriteModelPermissions = new ExplicitReadWriteModelPermissions();
     $currencyHelper = Yii::app()->currencyHelper;
     $currencyCode = $currencyHelper->getBaseCode();
     $currency = Currency::getByCode($currencyCode);
     $postData = array('productTemplate' => array('id' => $productTemplates[0]->id), 'name' => 'ProductPermissionTest', 'quantity' => 6, 'account' => array('id' => $accounts[0]->id), 'contact' => array('id' => $contacts[0]->id), 'opportunity' => array('id' => ''), 'type' => ProductTemplate::TYPE_PRODUCT, 'priceFrequency' => ProductTemplate::PRICE_FREQUENCY_ONE_TIME, 'sellPrice' => array('currency' => array('id' => $currency->id), 'value' => 210), 'stage' => array('value' => 'Open'), 'owner' => array('id' => $user->id), 'explicitReadWriteModelPermissions' => array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP, 'nonEveryoneGroup' => ''));
     $model = new Product();
     $sanitizedPostData = PostUtil::sanitizePostByDesignerTypeForSavingModel($model, $postData);
     if ($model instanceof SecurableItem) {
         $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::resolveByPostDataAndModelThenMake($sanitizedPostData, $model);
     } else {
         $explicitReadWriteModelPermissions = null;
     }
     $readyToUseData = ExplicitReadWriteModelPermissionsUtil::removeIfExistsFromPostData($sanitizedPostData);
     $sanitizedOwnerData = PostUtil::sanitizePostDataToJustHavingElementForSavingModel($readyToUseData, 'owner');
     $sanitizedDataWithoutOwner = PostUtil::removeElementFromPostDataForSavingModel($readyToUseData, 'owner');
     $model->setAttributes($sanitizedDataWithoutOwner);
     if ($model->validate()) {
         $modelToStringValue = strval($model);
         if ($sanitizedOwnerData != null) {
             $model->setAttributes($sanitizedOwnerData);
         }
         if ($model instanceof OwnedSecurableItem) {
             $passedOwnerValidation = $model->validate(array('owner'));
         } else {
             $passedOwnerValidation = true;
         }
         if ($passedOwnerValidation && $model->save(false)) {
             if ($explicitReadWriteModelPermissions != null) {
                 $success = ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($model, $explicitReadWriteModelPermissions);
                 //todo: handle if success is false, means adding/removing permissions save failed.
             }
             $savedSuccessfully = true;
         }
     } else {
     }
     $this->assertEquals('ProductPermissionTest', $model->name);
 }
 public function testSuperUserCreateAction()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     Yii::app()->user->userModel = $super;
     $this->resetGetArray();
     $currency = new Currency();
     $currency->code = 'USD';
     $currency->rateToBase = 1;
     $currency->save();
     $currencyRec = Currency::getByCode('USD');
     $currencyValue1Array = array('currency' => array('id' => $currencyRec->id), 'value' => 500.54);
     ProductTemplateTestHelper::createProductTemplateByName("My Catalog Item 1");
     $productTemplate = ProductTemplate::getByName('My Catalog Item 1');
     $product = array();
     $product['name'] = 'Red Widget';
     $product['quantity'] = 5;
     $product['priceFrequency'] = ProductTemplate::PRICE_FREQUENCY_ONE_TIME;
     $product['sellPrice'] = $currencyValue1Array;
     $product['type'] = ProductTemplate::TYPE_PRODUCT;
     $product['stage']['value'] = Product::OPEN_STAGE;
     $product['productTemplate'] = array('id' => $productTemplate[0]->id);
     $this->setPostArray(array('Product' => $product, 'Product_owner_name' => 'Super User'));
     $redirectUrl = $this->runControllerWithRedirectExceptionAndGetUrl('products/default/create');
     $products = Product::getByName('Red Widget');
     $this->assertEquals(1, count($products));
     $this->assertTrue($products[0]->id > 0);
     $this->assertEquals(500.54, $products[0]->sellPrice->value);
     $compareRedirectUrl = Yii::app()->createUrl('products/default/details', array('id' => $products[0]->id));
     $this->assertEquals($compareRedirectUrl, $redirectUrl);
 }
 protected static function resolveAjaxOptionsForSelectList()
 {
     $singularTitle = ProductTemplate::getModelLabelByTypeAndLanguage('Singular');
     $title = Zurmo::t('ProductTemplatesModule', $singularTitle . ' Search', LabelUtil::getTranslationParamsForAllModules());
     return ModalView::getAjaxOptionsForModalLink($title);
 }
 /**
  * Walkthrough test for synchronous download
  */
 public function testAsynchronousDownloadDefaultControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $notificationsBeforeCount = count(Notification::getAll());
     $notificationMessagesBeforeCount = count(NotificationMessage::getAll());
     $productTemplates = ProductTemplate::getAll();
     if (count($productTemplates)) {
         foreach ($productTemplates as $productTemplate) {
             $productTemplate->delete();
         }
     }
     $productTemplates = array();
     for ($i = 0; $i <= ExportModule::$asynchronusThreshold + 1; $i++) {
         $productTemplates[] = ProductTemplateTestHelper::createProductTemplateByName('superProductTemplate' . $i);
     }
     $this->setGetArray(array('ProductTemplate_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => ''));
     $this->runControllerWithRedirectExceptionAndGetUrl('productTemplates/default/export');
     // Start background job
     $job = new ExportJob();
     $this->assertTrue($job->run());
     $exportItems = ExportItem::getAll();
     $this->assertEquals(1, count($exportItems));
     $fileModel = $exportItems[0]->exportFileModel;
     $this->assertEquals(1, $exportItems[0]->isCompleted);
     $this->assertEquals('csv', $exportItems[0]->exportFileType);
     $this->assertEquals('productTemplates', $exportItems[0]->exportFileName);
     $this->assertTrue($fileModel instanceof ExportFileModel);
     $this->assertEquals($notificationsBeforeCount + 1, count(Notification::getAll()));
     $this->assertEquals($notificationMessagesBeforeCount + 1, count(NotificationMessage::getAll()));
     // Check export job, when many ids are selected.
     // This will probably never happen, but we need test for this case too.
     $notificationsBeforeCount = count(Notification::getAll());
     $notificationMessagesBeforeCount = count(NotificationMessage::getAll());
     // Now test case when multiple ids are selected
     $exportItems = ExportItem::getAll();
     if (count($exportItems)) {
         foreach ($exportItems as $exportItem) {
             $exportItem->delete();
         }
     }
     $selectedIds = "";
     foreach ($productTemplates as $productTemplate) {
         $selectedIds .= $productTemplate->id . ",";
         // Not Coding Standard
     }
     $this->setGetArray(array('ProductTemplatesSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'name' => ''), 'multiselect_ProductTemplatesSearchForm_anyMixedAttributesScope' => 'All', 'ProductTemplate_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => "{$selectedIds}"));
     $this->runControllerWithRedirectExceptionAndGetUrl('productTemplates/default/export');
     // Start background job
     $job = new ExportJob();
     $this->assertTrue($job->run());
     $exportItems = ExportItem::getAll();
     $this->assertEquals(1, count($exportItems));
     $fileModel = $exportItems[0]->exportFileModel;
     $this->assertEquals(1, $exportItems[0]->isCompleted);
     $this->assertEquals('csv', $exportItems[0]->exportFileType);
     $this->assertEquals('productTemplates', $exportItems[0]->exportFileName);
     $this->assertTrue($fileModel instanceof ExportFileModel);
     $this->assertEquals($notificationsBeforeCount + 1, count(Notification::getAll()));
     $this->assertEquals($notificationMessagesBeforeCount + 1, count(NotificationMessage::getAll()));
 }
 /**
  * @depends testWhetherSearchWorksForTheCustomFieldsPlacedForProductTemplatesModuleAfterEditingTheProductTemplate
  */
 public function testDeleteOfTheProductTemplateUserForTheCustomFieldsPlacedForProductTemplatesModule()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     //Get the product template id from the recently edited product template.
     $productTemplateId = self::getModelIdByModelNameAndName('ProductTemplate', 'myEditProductTemplate');
     //Set the opportunity id so as to delete the opportunity.
     $this->setGetArray(array('id' => $productTemplateId));
     $this->runControllerWithRedirectExceptionAndGetUrl('productTemplates/default/delete');
     //Check wether the product template is deleted.
     $productTemplate = ProductTemplate::getByName('myEditProductTemplate');
     $this->assertEquals(0, count($productTemplate));
 }
 public function testUpdateRelatedCatalogItemOnAProductBySellPriceCriteria()
 {
     $super = User::getByUsername('super');
     $contactStates = ContactState::getAll();
     //Create workflow
     $workflow = new Workflow();
     $workflow->setDescription('aDescription');
     $workflow->setIsActive(true);
     $workflow->setOrder(1);
     $workflow->setModuleClassName('ProductsModule');
     $workflow->setName('myFirstProductWorkflow');
     $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING);
     $workflow->setType(Workflow::TYPE_ON_SAVE);
     $workflow->setTriggersStructure('1');
     //Add Trigger
     $trigger = new TriggerForWorkflowForm('ProductsModule', 'Product', Workflow::TYPE_ON_SAVE);
     $trigger->attributeIndexOrDerivedType = 'sellPrice';
     $trigger->value = 600;
     $trigger->operator = 'greaterThanOrEqualTo';
     $workflow->addTrigger($trigger);
     //Add action
     $currencies = Currency::getAll();
     $action = new ActionForWorkflowForm('Product', Workflow::TYPE_ON_SAVE);
     $action->type = ActionForWorkflowForm::TYPE_UPDATE_RELATED;
     $action->relation = 'productTemplate';
     $attributes = array('description' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'Set Price'), 'priceFrequency' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 2), 'listPrice' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 800, 'currencyId' => $currencies[0]->id), 'cost' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 700, 'currencyId' => $currencies[0]->id));
     $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
     $workflow->addAction($action);
     //Create the saved Workflow
     $savedWorkflow = new SavedWorkflow();
     SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow);
     $saved = $savedWorkflow->save();
     $this->assertTrue($saved);
     $productTemplate = ProductTemplateTestHelper::createProductTemplateByName('superProductTemplate');
     $productTemplates = ProductTemplate::getByName('superProductTemplate');
     $product = ProductTestHelper::createProductByNameForOwner('Test Product', $super);
     $this->assertTrue($product->id > 0);
     $product->productTemplate = $productTemplates[0];
     //Change product sell price
     $product->sellPrice->value = 650;
     $this->assertTrue(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $product));
     $saved = $product->save();
     $this->assertTrue($saved);
     $productId = $product->id;
     $product->forget();
     $product = Product::getById($productId);
     $this->assertEquals('Set Price', $product->productTemplate->description);
     $this->assertEquals(2, $product->productTemplate->priceFrequency);
     $this->assertEquals(700, $product->productTemplate->cost->value);
     $this->assertEquals(800, $product->productTemplate->listPrice->value);
 }
 public function testCloningWithAnotherProductTemplate()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     Yii::app()->user->userModel = $super;
     $productTemplate = ProductTemplateTestHelper::createProductTemplateByName("My Copy Catalog Item");
     $id = $productTemplate->id;
     $this->setGetArray(array('id' => $id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('productTemplates/default/copy');
     $this->assertTrue(strpos($content, 'My Copy Catalog Item') > 0);
     $productTemplates = ProductTemplate::getAll();
     $this->assertEquals(1, count($productTemplates));
 }
Esempio n. 16
0
 public function testProductTemplateCategories()
 {
     $user = UserTestHelper::createBasicUser('Steven 2');
     $product = ProductTestHelper::createProductByNameForOwner('Product 1', $user);
     $productTemplate = ProductTemplateTestHelper::createProductTemplateByVariables($product, ProductTemplate::PRICE_FREQUENCY_ONE_TIME, ProductTemplate::TYPE_PRODUCT, ProductTemplate::STATUS_ACTIVE, SellPriceFormula::TYPE_EDITABLE);
     $productCategory = ProductCategoryTestHelper::createProductCategoryByName("Test Category");
     $productCategoryII = ProductCategoryTestHelper::createProductCategoryByName("Test CategoryII");
     $productTemplate->productCategories->add($productCategory);
     $productTemplate->productCategories->add($productCategoryII);
     $this->assertTrue($productTemplate->save());
     $id = $productTemplate->id;
     $productTemplate->forget();
     unset($productTemplate);
     $productTemplate = ProductTemplate::getById($id);
     $this->assertEquals($productCategory, $productTemplate->productCategories[0]);
     $this->assertEquals($productCategoryII, $productTemplate->productCategories[1]);
 }
Esempio n. 17
0
//$fedex_id = $shipper->id;
//$usps_id = $shipper->id;
//$desktops_id = $category->id;
//$laptops_id = $category->id;
//$stationary_id = $category->id;
//$wobbly_id = $category->id;
//$widgets_id = $type->id;
//$hardware_id = $type->id;
//$support_id = $type->id;
//$taxrate_id = $taxrate->id;
//$euro_id = $currency->id;
foreach ($sugar_demodata['producttemplate_seed_data'] as $v) {
    $manufacturer_id_max = count($manufacturer_id_arr) - 1;
    $productcategory_id_max = count($productcategory_id_arr) - 1;
    $producttype_id_max = count($producttype_id_arr) - 1;
    $template = new ProductTemplate();
    $template->manufacturer_id = $manufacturer_id_arr[mt_rand(0, $manufacturer_id_max)];
    $template->category_id = $productcategory_id_arr[mt_rand(0, $manufacturer_id_max)];
    $template->type_id = $producttype_id_arr[mt_rand(0, $manufacturer_id_max)];
    $template->currency_id = $dollar_id;
    $template->name = $v['name'];
    $template->tax_class = $v['tax_class'];
    $template->cost_price = $v['cost_price'];
    $template->cost_usdollar = $v['cost_usdollar'];
    $template->list_price = $v['list_price'];
    $template->list_usdollar = $v['list_usdollar'];
    $template->discount_price = $v['discount_price'];
    $template->discount_usdollar = $v['discount_usdollar'];
    $template->pricing_formula = $v['pricing_formula'];
    $template->mft_part_num = $v['mft_part_num'];
    $template->pricing_factor = $v['pricing_factor'];
Esempio n. 18
0
 /**
  * Copies the product template
  * @param int $id
  */
 public function actionCopy($id)
 {
     $copyToProductTemplate = new ProductTemplate();
     $postVariableName = get_class($copyToProductTemplate);
     if (!isset($_POST[$postVariableName])) {
         $productTemplate = ProductTemplate::getById((int) $id);
         ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($productTemplate);
         ProductZurmoCopyModelUtil::copy($productTemplate, $copyToProductTemplate);
     }
     $this->processEdit($copyToProductTemplate);
 }
 public function testSuperUserCreateProductFromProductTemplateControllerAction()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $products = Product::getAll();
     $this->assertEquals(1, count($products));
     $superProductTemplateId = self::getModelIdByModelNameAndName('ProductTemplate', 'My Product Template');
     $productTemplate = ProductTemplate::getById($superProductTemplateId);
     $productCategory = ProductCategoryTestHelper::createProductCategoryByName("Test Category");
     $productCategoryII = ProductCategoryTestHelper::createProductCategoryByName("Test CategoryII");
     $productTemplate->productCategories->add($productCategory);
     $productTemplate->productCategories->add($productCategoryII);
     $productTemplate->save();
     $superProductTemplateId = $productTemplate->id;
     $productTemplate->forget();
     unset($productTemplate);
     $accountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
     $this->setGetArray(array('relationModuleId' => 'accounts', 'portletId' => '1', 'uniqueLayoutId' => 'AccountDetailsAndRelationsView_1', 'id' => $superProductTemplateId, 'relationModelId' => $accountId, 'relationAttributeName' => 'account', 'relationModelClassName' => 'Account', 'redirect' => '0'));
     $this->runControllerWithNoExceptionsAndGetContent('products/default/createProductFromProductTemplate', true);
     $products = Product::getAll();
     $this->assertEquals(2, count($products));
     $latestProduct = $products[1];
     $productSavedCategory = $latestProduct->productCategories[0];
     $productSavedCategoryII = $latestProduct->productCategories[1];
     $this->assertEquals('Test Category', $productSavedCategory->name);
     $this->assertEquals('Test CategoryII', $productSavedCategoryII->name);
     $this->assertEquals('My Product Template', $latestProduct->name);
     $this->assertEquals(500.54, $latestProduct->sellPrice->value);
     //When created from contact should copy the contact account to product
     $contactId = self::getModelIdByModelNameAndName('Contact', 'superContact superContactson');
     $this->setGetArray(array('relationModuleId' => 'accounts', 'portletId' => '1', 'uniqueLayoutId' => 'ContactDetailsAndRelationsView_1', 'id' => $superProductTemplateId, 'relationModelId' => $contactId, 'relationAttributeName' => 'contact', 'relationModelClassName' => 'Contact', 'redirect' => '0'));
     $this->runControllerWithNoExceptionsAndGetContent('products/default/createProductFromProductTemplate', true);
     $products = Product::getAll();
     $this->assertEquals(3, count($products));
     $latestProduct = $products[2];
     $this->assertEquals($accountId, $latestProduct->account->id);
 }
Esempio n. 20
0
function create_product($category_id)
{
    global $sugar_demodata;
    $first_name_array = $sugar_demodata['first_name_array'];
    $first_name_count = count($sugar_demodata['first_name_array']);
    $company_name_array = $sugar_demodata['company_name_array'];
    $company_name_count = count($sugar_demodata['company_name_array']);
    global $dollar_id;
    if (empty($dollar_id)) {
        $dollar_id = '-99';
    }
    global $manufacturer_id_arr;
    $first_name_max = $first_name_count - 1;
    $cost = rand(300, 600);
    $list = rand(700, 1000);
    $discount = rand($list - 200, $list - 50);
    $template = new ProductTemplate();
    $template->name = $first_name_array[mt_rand(0, $first_name_max)] . $sugar_demodata['product_ext_name'];
    $template->tax_class = "Taxable";
    $template->manufacturer_id = $manufacturer_id_arr[0];
    $template->currency_id = $dollar_id;
    $template->cost_price = $cost;
    $template->cost_usdollar = $cost;
    $template->list_price = $list;
    $template->list_usdollar = $list;
    $template->discount_price = $discount;
    $template->discount_usdollar = $discount;
    $template->pricing_formula = "IsList";
    $template->mft_part_num = $company_name_array[mt_rand(0, $company_name_count - 1)] . ' ' . mt_rand(1, 1000000) . "XYZ987";
    $template->pricing_factor = "1";
    $template->status = "Available";
    $template->weight = rand(10, 40);
    $template->date_available = "2004-10-15";
    $template->qty_in_stock = rand(0, 150);
    $template->category_id = $category_id;
    $template->save();
    unset($template);
    //end function create_product
}