本文整理汇总了PHP中Product::getById方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getById方法的具体用法?PHP Product::getById怎么用?PHP Product::getById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Product
的用法示例。
在下文中一共展示了Product::getById方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getOrder
/**
* @return Order
*/
public function getOrder()
{
if ($this->order_id && !$this->order) {
$this->order = Product::getById($this->order_id);
}
return $this->product;
}
示例2: indexAction
public function indexAction()
{
$this->view->Title = 'Đặt hàng';
$this->view->headTitle($this->view->Title);
$id = $this->getRequest()->getParam("id_product");
$Product = Product::getById($id);
if ($this->getRequest()->isPost()) {
$request = $this->getRequest()->getParams();
$error = $this->_checkForm($request);
if (count($error) == 0) {
$Contact = new Contact();
$Contact->merge($request);
$Contact->created_date = date("Y-m-d H:i:s");
$Contact->save();
//$_SESSION['msg'] = "Yêu cầu đặt hàng của bạn đã được gửi, xin trân thành cảm ơn!";
My_Plugin_Libs::setSplash('<b>Yêu cầu đặt hàng của bạn đã được gửi, xin trân thành cảm ơn!</b>');
$this->_redirect($this->_helper->url('index', 'contact', 'default'));
}
if (count($error)) {
$this->view->error = $error;
}
}
$this->view->Product = $Product;
$this->view->Contact = $Contact;
}
示例3: detailsAction
public function detailsAction()
{
$id = $this->getRequest()->getParam("product_id");
$Product = Product::getById($id);
$this->view->Product = $Product;
$this->view->Title = $Product->product_name;
$this->view->headTitle($this->view->Title);
}
示例4: getProducts
function getProducts()
{
$ProductID = $this->f3->get('PARAMS.ProductID');
$p = new Product($this->db);
//$products = $product->all();
if (isset($ProductID)) {
$products = $p->getById($ProductID);
} else {
$products = $p->all();
}
echo $this->utils->successResponse($p, $products);
}
示例5: editProduct
function editProduct($post)
{
$ProductID = $this->f3->get('PARAMS.ProductID');
$post = json_decode($this->f3->get('BODY'), true);
$p = new Product($this->db);
$products = $p->getById($this->userID, $ProductID);
$product = $products[0];
$product->ProductName = $post['ProductName'];
$product->ProductDesc = filter_var($post['ProductDesc'], FILTER_SANITIZE_STRING);
$product->ProductPrice = $post['ProductPrice'];
if ($this->debug) {
$this->utils->debug(__METHOD__, $product->cast());
}
$product->save();
echo $this->utils->successResponse($product, null);
}
示例6: testResolveProductHasManyProductCategoriesFromPost
public function testResolveProductHasManyProductCategoriesFromPost()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$category1 = ProductCategoryTestHelper::createProductCategoryByName('Test Product Category');
$category2 = ProductCategoryTestHelper::createProductCategoryByName('Test Product Category2');
$product = ProductTestHelper::createProductByNameForOwner('I am testing products', $super);
$postData = array('categoryIds' => $category1->id . ',' . $category2->id);
// Not Coding Standard
$id = $product->id;
$product->forget();
unset($product);
$product = Product::getById($id);
$categories = ProductCategoriesUtil::resolveProductHasManyProductCategoriesFromPost($product, $postData);
$this->assertEquals(count($categories), 2);
$this->assertEquals($categories[$category1->id]->id, $category1->id);
}
示例7: testSuperUserEditProductPortletControllerAction
public function testSuperUserEditProductPortletControllerAction()
{
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
$products = Product::getAll();
$this->assertEquals(1, count($products));
$superProductId = self::getModelIdByModelNameAndName('Product', 'My Product 1');
$this->setGetArray(array('attribute' => 'sellPrice', 'item' => $superProductId, 'value' => '300.54'));
$this->runControllerWithNoExceptionsAndGetContent('products/default/update', true);
//Save product.
$superProduct = Product::getById($superProductId);
$this->assertEquals(300.54, $superProduct->sellPrice->value);
$this->setGetArray(array('attribute' => 'sellPrice', 'item' => $superProductId, 'value' => '3000.54'));
$this->runControllerWithNoExceptionsAndGetContent('products/default/update', true);
//Save product.
$superProduct = Product::getById($superProductId);
$this->assertEquals(3000.54, $superProduct->sellPrice->value);
$this->setGetArray(array('attribute' => 'quantity', 'item' => $superProductId, 'value' => '10'));
$this->runControllerWithNoExceptionsAndGetContent('products/default/update', true);
//Save product.
$superProduct = Product::getById($superProductId);
$this->assertEquals(10, $superProduct->quantity);
}
示例8: process
//.........这里部分代码省略.........
$objOrder->city($_SESSION['shop']['city2']);
$objOrder->zip($_SESSION['shop']['zip2']);
$objOrder->country_id($_SESSION['shop']['countryId2']);
$objOrder->phone($_SESSION['shop']['phone2']);
$objOrder->vat_amount($_SESSION['shop']['vat_price']);
$objOrder->shipment_amount($_SESSION['shop']['shipment_price']);
$objOrder->shipment_id($shipper_id);
$objOrder->payment_id($payment_id);
$objOrder->payment_amount($_SESSION['shop']['payment_price']);
$objOrder->ip($customer_ip);
$objOrder->host($customer_host);
$objOrder->lang_id(FRONTEND_LANG_ID);
$objOrder->browser($customer_browser);
$objOrder->note($_SESSION['shop']['note']);
if (!$objOrder->insert()) {
// $order_id is unset!
return \Message::error($_ARRAYLANG['TXT_SHOP_ORDER_ERROR_STORING']);
}
$order_id = $objOrder->id();
$_SESSION['shop']['order_id'] = $order_id;
// The products will be tested one by one below.
// If any single one of them requires delivery, this
// flag will be set to true.
// This is used to determine the order status at the
// end of the shopping process.
$_SESSION['shop']['isDelivery'] = false;
// Try to redeem the Coupon, if any
$coupon_code = isset($_SESSION['shop']['coupon_code']) ? $_SESSION['shop']['coupon_code'] : null;
//\DBG::log("Cart::update(): Coupon Code: $coupon_code");
$items_total = 0;
// Suppress Coupon messages (see Coupon::available())
\Message::save();
foreach (Cart::get_products_array() as $arrProduct) {
$objProduct = Product::getById($arrProduct['id']);
if (!$objProduct) {
unset($_SESSION['shop']['order_id']);
return \Message::error($_ARRAYLANG['TXT_ERROR_LOOKING_UP_ORDER']);
}
$product_id = $arrProduct['id'];
$name = $objProduct->name();
$priceOptions = !empty($arrProduct['optionPrice']) ? $arrProduct['optionPrice'] : 0;
$quantity = $arrProduct['quantity'];
$price = $objProduct->get_custom_price(self::$objCustomer, $priceOptions, $quantity);
$item_total = $price * $quantity;
$items_total += $item_total;
$productVatId = $objProduct->vat_id();
$vat_rate = $productVatId && Vat::getRate($productVatId) ? Vat::getRate($productVatId) : '0.00';
// Test the distribution method for delivery
$productDistribution = $objProduct->distribution();
if ($productDistribution == 'delivery') {
$_SESSION['shop']['isDelivery'] = true;
}
$weight = $productDistribution == 'delivery' ? $objProduct->weight() : 0;
// grams
if ($weight == '') {
$weight = 0;
}
// Add to order items table
$result = $objOrder->insertItem($order_id, $product_id, $name, $price, $quantity, $vat_rate, $weight, $arrProduct['options']);
if (!$result) {
unset($_SESSION['shop']['order_id']);
// TODO: Verify error message set by Order::insertItem()
return false;
}
// Store the Product Coupon, if applicable.
// Note that it is not redeemed yet (uses=0)!
示例9: testUpdateRelatedCatalogItemOnAProductBySellPriceCriteria
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);
}
示例10: testMassDeleteActionsForSelectedIds
/**
* @deletes selected products.
*/
public function testMassDeleteActionsForSelectedIds()
{
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
$products = Product::getAll();
$this->assertEquals(13, count($products));
$superProductId = self::getModelIdByModelNameAndName('Product', 'My Product 1');
$superProductId2 = self::getModelIdByModelNameAndName('Product', 'My Product 2');
$superProductId3 = self::getModelIdByModelNameAndName('Product', 'My Product 3');
$superProductId4 = self::getModelIdByModelNameAndName('Product', 'My Product 4');
$superProductId5 = self::getModelIdByModelNameAndName('Product', 'My Product 5');
$superProductId6 = self::getModelIdByModelNameAndName('Product', 'My Product 6');
$superProductId7 = self::getModelIdByModelNameAndName('Product', 'My Product 7');
$superProductId8 = self::getModelIdByModelNameAndName('Product', 'My Product 8');
$superProductId9 = self::getModelIdByModelNameAndName('Product', 'My Product 9');
$superProductId10 = self::getModelIdByModelNameAndName('Product', 'My Product 10');
$superProductId11 = self::getModelIdByModelNameAndName('Product', 'My Product 11');
$superProductId12 = self::getModelIdByModelNameAndName('Product', 'My Product 12');
//Load Model MassDelete Views.
//MassDelete view for single selected ids
$this->setGetArray(array('selectedIds' => '5,6,7,8,9', 'selectAll' => ''));
// Not Coding Standard
$this->resetPostArray();
$content = $this->runControllerWithNoExceptionsAndGetContent('products/default/massDelete');
$this->assertFalse(strpos($content, '<strong>5</strong> Products selected for removal') === false);
//MassDelete view for all result selected ids
$this->setGetArray(array('selectAll' => '1'));
$this->resetPostArray();
$content = $this->runControllerWithNoExceptionsAndGetContent('products/default/massDelete');
$this->assertFalse(strpos($content, '<strong>13</strong> Products selected for removal') === false);
//MassDelete for selected Record Count
$products = Product::getAll();
$this->assertEquals(13, count($products));
//MassDelete for selected ids for paged scenario
$superProduct1 = Product::getById($superProductId);
$superProduct2 = Product::getById($superProductId2);
$superProduct3 = Product::getById($superProductId3);
$superProduct4 = Product::getById($superProductId4);
$superProduct5 = Product::getById($superProductId5);
$superProduct6 = Product::getById($superProductId6);
$superProduct7 = Product::getById($superProductId7);
$pageSize = Yii::app()->pagination->getForCurrentUserByType('massDeleteProgressPageSize');
$this->assertEquals(5, $pageSize);
//MassDelete for selected ids for page 1
$this->setGetArray(array('selectedIds' => $superProductId . ',' . $superProductId2 . ',' . $superProductId3 . ',' . $superProductId4 . ',' . $superProductId5 . ',' . $superProductId6 . ',' . $superProductId7, 'selectAll' => '', 'massDelete' => '', 'Product_page' => 1));
$this->setPostArray(array('selectedRecordCount' => 7));
$this->runControllerWithExitExceptionAndGetContent('products/default/massDelete');
//MassDelete for selected Record Count
$products = Product::getAll();
$this->assertEquals(8, count($products));
//MassDelete for selected ids for page 2
$this->setGetArray(array('selectedIds' => $superProductId . ',' . $superProductId2 . ',' . $superProductId3 . ',' . $superProductId4 . ',' . $superProductId5 . ',' . $superProductId6 . ',' . $superProductId7, 'selectAll' => '', 'massDelete' => '', 'Product_page' => 2));
$this->setPostArray(array('selectedRecordCount' => 7));
$this->runControllerWithNoExceptionsAndGetContent('products/default/massDeleteProgress');
//MassDelete for selected Record Count
$products = Product::getAll();
$this->assertEquals(6, count($products));
}
示例11: getSubstitutionArray
/**
* Returns an array with all placeholders and their values to be
* replaced in any shop mailtemplate for the given order ID.
*
* You only have to set the 'substitution' index value of your MailTemplate
* array to the array returned.
* Customer data is not included here. See {@see Customer::getSubstitutionArray()}.
* Note that this method is now mostly independent of the current session.
* The language of the mail template is determined by the browser
* language range stored with the order.
* @access private
* @static
* @param integer $order_id The order ID
* @param boolean $create_accounts If true, creates User accounts
* and Coupon codes. Defaults to true
* @return array The array with placeholders as keys
* and values from the order on success,
* false otherwise
*/
static function getSubstitutionArray($order_id, $create_accounts = true)
{
global $_ARRAYLANG;
/*
$_ARRAYLANG['TXT_SHOP_URI_FOR_DOWNLOAD'].":\r\n".
'http://'.$_SERVER['SERVER_NAME'].
"/index.php?section=download\r\n";
*/
$objOrder = Order::getById($order_id);
if (!$objOrder) {
// Order not found
return false;
}
$lang_id = $objOrder->lang_id();
if (!intval($lang_id)) {
$lang_id = \FWLanguage::getLangIdByIso639_1($lang_id);
}
$status = $objOrder->status();
$customer_id = $objOrder->customer_id();
$customer = Customer::getById($customer_id);
$payment_id = $objOrder->payment_id();
$shipment_id = $objOrder->shipment_id();
$arrSubstitution = array('CUSTOMER_COUNTRY_ID' => $objOrder->billing_country_id(), 'LANG_ID' => $lang_id, 'NOW' => date(ASCMS_DATE_FORMAT_DATETIME), 'TODAY' => date(ASCMS_DATE_FORMAT_DATE), 'ORDER_ID' => $order_id, 'ORDER_ID_CUSTOM' => ShopLibrary::getCustomOrderId($order_id), 'ORDER_DATE' => date(ASCMS_DATE_FORMAT_DATE, strtotime($objOrder->date_time())), 'ORDER_TIME' => date(ASCMS_DATE_FORMAT_TIME, strtotime($objOrder->date_time())), 'ORDER_STATUS_ID' => $status, 'ORDER_STATUS' => $_ARRAYLANG['TXT_SHOP_ORDER_STATUS_' . $status], 'MODIFIED' => date(ASCMS_DATE_FORMAT_DATETIME, strtotime($objOrder->modified_on())), 'REMARKS' => $objOrder->note(), 'ORDER_SUM' => sprintf('% 9.2f', $objOrder->sum()), 'CURRENCY' => Currency::getCodeById($objOrder->currency_id()));
$arrSubstitution += $customer->getSubstitutionArray();
if ($shipment_id) {
$arrSubstitution += array('SHIPMENT' => array(0 => array('SHIPMENT_NAME' => sprintf('%-40s', Shipment::getShipperName($shipment_id)), 'SHIPMENT_PRICE' => sprintf('% 9.2f', $objOrder->shipment_amount()))), 'SHIPPING_ADDRESS' => array(0 => array('SHIPPING_COMPANY' => $objOrder->company(), 'SHIPPING_TITLE' => $_ARRAYLANG['TXT_SHOP_' . strtoupper($objOrder->gender())], 'SHIPPING_FIRSTNAME' => $objOrder->firstname(), 'SHIPPING_LASTNAME' => $objOrder->lastname(), 'SHIPPING_ADDRESS' => $objOrder->address(), 'SHIPPING_ZIP' => $objOrder->zip(), 'SHIPPING_CITY' => $objOrder->city(), 'SHIPPING_COUNTRY_ID' => $objOrder->country_id(), 'SHIPPING_COUNTRY' => \Cx\Core\Country\Controller\Country::getNameById($objOrder->country_id()), 'SHIPPING_PHONE' => $objOrder->phone())));
}
if ($payment_id) {
$arrSubstitution += array('PAYMENT' => array(0 => array('PAYMENT_NAME' => sprintf('%-40s', Payment::getNameById($payment_id)), 'PAYMENT_PRICE' => sprintf('% 9.2f', $objOrder->payment_amount()))));
}
$arrItems = $objOrder->getItems();
if (!$arrItems) {
\Message::warning($_ARRAYLANG['TXT_SHOP_ORDER_WARNING_NO_ITEM']);
}
// Deduct Coupon discounts, either from each Product price, or
// from the items total. Mind that the Coupon has already been
// stored with the Order, but not redeemed yet. This is done
// in this method, but only if $create_accounts is true.
$coupon_code = NULL;
$coupon_amount = 0;
$objCoupon = Coupon::getByOrderId($order_id);
if ($objCoupon) {
$coupon_code = $objCoupon->code();
}
$orderItemCount = 0;
$total_item_price = 0;
// Suppress Coupon messages (see Coupon::available())
\Message::save();
foreach ($arrItems as $item) {
$product_id = $item['product_id'];
$objProduct = Product::getById($product_id);
if (!$objProduct) {
//die("Product ID $product_id not found");
continue;
}
//DBG::log("Orders::getSubstitutionArray(): Item: Product ID $product_id");
$product_name = substr($item['name'], 0, 40);
$item_price = $item['price'];
$quantity = $item['quantity'];
// TODO: Add individual VAT rates for Products
// $orderItemVatPercent = $objResultItem->fields['vat_percent'];
// Decrease the Product stock count,
// applies to "real", shipped goods only
$objProduct->decreaseStock($quantity);
$product_code = $objProduct->code();
// Pick the order items attributes
$str_options = '';
// Any attributes?
if ($item['attributes']) {
$str_options = ' ';
// '[';
$attribute_name_previous = '';
foreach ($item['attributes'] as $attribute_name => $arrAttribute) {
//DBG::log("Attribute /$attribute_name/ => ".var_export($arrAttribute, true));
// NOTE: The option price is optional and may be left out
foreach ($arrAttribute as $arrOption) {
$option_name = $arrOption['name'];
$option_price = $arrOption['price'];
$item_price += $option_price;
// Recognize the names of uploaded files,
// verify their presence and use the original name
//.........这里部分代码省略.........
示例12: testEditOfTheProductForTheCustomFieldsPlacedForProductsModule
/**
* @depends testEditOfTheProductForTheTagCloudFieldAfterRemovingAllTagsPlacedForProductsModule
*/
public function testEditOfTheProductForTheCustomFieldsPlacedForProductsModule()
{
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
//Set the date and datetime variable values here.
$date = Yii::app()->dateFormatter->format(DateTimeUtil::getLocaleDateFormatForInput(), time());
$dateAssert = date('Y-m-d');
$datetime = Yii::app()->dateFormatter->format(DateTimeUtil::getLocaleDateTimeFormatForInput(), time());
$datetimeAssert = date('Y-m-d H:i:') . "00";
$baseCurrency = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode());
//Retrieve the account id, the super user id and product Id.
$accountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
$superUserId = $super->id;
$explicitReadWriteModelPermission = ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP;
$product = Product::getByName('myEditProduct');
$productId = $product[0]->id;
//Edit a new Product based on the custom fields.
$this->setGetArray(array('id' => $productId));
$this->setPostArray(array('Product' => array('name' => 'myEditProduct', 'owner' => array('id' => $superUserId), 'type' => 1, 'sellPrice' => array('currency' => array('id' => $baseCurrency->id), 'value' => 200), 'account' => array('id' => $accountId), 'quantity' => 10, 'priceFrequency' => 2, 'stage' => array('value' => 'Open'), 'explicitReadWriteModelPermissions' => array('type' => $explicitReadWriteModelPermission), 'checkboxCstm' => '0', 'currencyCstm' => array('value' => 40, 'currency' => array('id' => $baseCurrency->id)), 'decimalCstm' => '12', 'dateCstm' => $date, 'datetimeCstm' => $datetime, 'picklistCstm' => array('value' => 'b'), 'multiselectCstm' => array('values' => array('gg', 'hh')), 'tagcloudCstm' => array('values' => array('reading', 'surfing')), 'countrylistCstm' => array('value' => 'aaaa'), 'statelistCstm' => array('value' => 'aaa1'), 'citylistCstm' => array('value' => 'ab1'), 'integerCstm' => '11', 'phoneCstm' => '259-784-2069', 'radioCstm' => array('value' => 'e'), 'textCstm' => 'This is a test Edit Text', 'textareaCstm' => 'This is a test Edit TextArea', 'urlCstm' => 'http://wwww.abc-edit.com')));
$this->runControllerWithRedirectExceptionAndGetUrl('products/default/edit');
//Check the details if they are saved properly for the custom fields.
$productId = self::getModelIdByModelNameAndName('Product', 'myEditProduct');
$product = Product::getById($productId);
//Retrieve the permission of the product.
$explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($product);
$readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
$readOnlyPermitables = $explicitReadWriteModelPermissions->getReadOnlyPermitables();
$this->assertEquals($product->name, 'myEditProduct');
$this->assertEquals($product->quantity, 10);
$this->assertEquals($product->sellPrice->value, 200.0);
$this->assertEquals($product->account->id, $accountId);
$this->assertEquals($product->type, 1);
$this->assertEquals($product->stage->value, 'Open');
$this->assertEquals($product->owner->id, $superUserId);
$this->assertEquals(1, count($readWritePermitables));
$this->assertEquals(0, count($readOnlyPermitables));
$this->assertEquals($product->checkboxCstm, '0');
$this->assertEquals($product->currencyCstm->value, 40);
$this->assertEquals($product->currencyCstm->currency->id, $baseCurrency->id);
$this->assertEquals($product->dateCstm, $dateAssert);
$this->assertEquals($product->datetimeCstm, $datetimeAssert);
$this->assertEquals($product->decimalCstm, '12');
$this->assertEquals($product->picklistCstm->value, 'b');
$this->assertEquals($product->integerCstm, 11);
$this->assertEquals($product->phoneCstm, '259-784-2069');
$this->assertEquals($product->radioCstm->value, 'e');
$this->assertEquals($product->textCstm, 'This is a test Edit Text');
$this->assertEquals($product->textareaCstm, 'This is a test Edit TextArea');
$this->assertEquals($product->urlCstm, 'http://wwww.abc-edit.com');
$this->assertEquals($product->dateCstm, $dateAssert);
$this->assertEquals($product->datetimeCstm, $datetimeAssert);
$this->assertEquals($product->countrylistCstm->value, 'aaaa');
$this->assertEquals($product->statelistCstm->value, 'aaa1');
$this->assertEquals($product->citylistCstm->value, 'ab1');
$this->assertContains('gg', $product->multiselectCstm->values);
$this->assertContains('hh', $product->multiselectCstm->values);
$this->assertContains('reading', $product->tagcloudCstm->values);
$this->assertContains('surfing', $product->tagcloudCstm->values);
$metadata = CalculatedDerivedAttributeMetadata::getByNameAndModelClassName('calcnumber', 'Product');
$testCalculatedValue = CalculatedNumberUtil::calculateByFormulaAndModelAndResolveFormat($metadata->getFormula(), $product);
$this->assertEquals(132, intval(str_replace(',', '', $testCalculatedValue)));
// Not Coding Standard
}
示例13: update_products
/**
* Store any Products that have been modified.
*
* Takes the Product data directly from the various fields of the
* $_POST array. Only updates the database records for Products that
* have at least one of their values changed.
* @return boolean True on success, false otherwise.
* @global array $_ARRAYLANG Language array
*/
function update_products()
{
global $_ARRAYLANG;
$arrError = array();
foreach (array_keys($_POST['product_id']) as $product_id) {
$product_code = contrexx_input2raw($_POST['identifier'][$product_id]);
$product_code_old = contrexx_input2raw($_POST['identifierOld'][$product_id]);
$ord = intval($_POST['ord'][$product_id]);
$ord_old = intval($_POST['ordOld'][$product_id]);
$discount_active = isset($_POST['discount_active'][$product_id]) ? 1 : 0;
$special_offer_old = $_POST['specialOfferOld'][$product_id];
$discount_price = floatval($_POST['discount_price'][$product_id]);
$discountOld = floatval($_POST['discountOld'][$product_id]);
$normalprice = floatval($_POST['price1'][$product_id]);
$normalpriceOld = floatval($_POST['price1Old'][$product_id]);
$resellerprice = floatval($_POST['price2'][$product_id]);
$resellerpriceOld = floatval($_POST['price2Old'][$product_id]);
$stock = intval($_POST['stock'][$product_id]);
$stockOld = intval($_POST['stockOld'][$product_id]);
// $status = (isset($_POST['active'][$product_id]) ? 1 : 0);
// $statusOld = $_POST['activeOld'][$product_id];
$vat_id = isset($_POST['taxId'][$product_id]) ? intval($_POST['taxId'][$product_id]) : 0;
$vat_id_old = intval($_POST['taxIdOld'][$product_id]);
$shownOnStartpage = empty($_POST['shownonstartpage'][$product_id]) ? 0 : 1;
$shownOnStartpageOld = empty($_POST['shownonstartpageOld'][$product_id]) ? 0 : 1;
// This is used when the Product name can be edited right on the overview
$name = isset($_POST['name'][$product_id]) ? contrexx_input2raw($_POST['name'][$product_id]) : null;
$nameOld = isset($_POST['nameOld'][$product_id]) ? contrexx_input2raw($_POST['nameOld'][$product_id]) : null;
/* Distribution and weight have been removed from the overview due to the
changes made to the delivery options.
$distribution = $_POST['distribution'][$product_id];
$distributionOld = $_POST['distributionOld'][$product_id];
$weight = $_POST['weight'][$product_id];
$weightOld = $_POST['weightOld'][$product_id];
// Flag used to determine whether the record has to be
// updated in the database
$updateProduct = false;
// Check whether the weight was changed
if ($weight != $weightOld) {
// Changed.
// If it's empty, set to NULL and don't complain.
// The NULL weight will be silently ignored by the database.
if ($weight == '') {
$weight = 'NULL';
} else {
// Check the format
$weight = Weight::getWeight($weight);
// The NULL weight will be silently ignored by the database.
if ($weight === 'NULL') {
// 'NULL', the format was invalid. cast error
\Message::error($_ARRAYLANG['TXT_WEIGHT_INVALID_IGNORED']);
} else {
// If getWeight() returns any other value, the format
// is valid. Verify that the numeric value has changed
// as well; might be that the user simply removed the
// unit ('g').
if ($weight != Weight::getWeight($weightOld)) {
// Really changed
$updateProduct = true;
}
// Otherwise, the new amd old values are the same.
}
}
}
if ($updateProduct === false) {
// reset the weight to the old and, hopefully, correct value,
// in case the record is updated anyway
$weight = Weight::getWeight($weightOld);
}
*/
// Check if any one value has been changed
if ($product_code != $product_code_old || $ord != $ord_old || $discount_active != $special_offer_old || $discount_price != $discountOld || $normalprice != $normalpriceOld || $resellerprice != $resellerpriceOld || $stock != $stockOld || $vat_id != $vat_id_old || $shownOnStartpage != $shownOnStartpageOld || $name != $nameOld) {
$arrProducts = array(Product::getById($product_id));
if (!is_array($arrProducts)) {
continue;
}
foreach ($arrProducts as $objProduct) {
if (!$objProduct) {
$arrError[$product_code] = true;
continue;
}
$objProduct->code($product_code);
$objProduct->ord($ord);
$objProduct->discount_active($discount_active);
$objProduct->discountprice($discount_price);
$objProduct->price($normalprice);
$objProduct->resellerprice($resellerprice);
$objProduct->stock($stock);
// $objProduct->active($status);
$objProduct->vat_id($vat_id);
// $objProduct->distribution($distribution);
//.........这里部分代码省略.........
示例14: getMenuoptions
/**
* Returns a string with HTML options for any menu
*
* Includes Products with the given active status only if $active is
* not null. The options' values are the Product IDs.
* The sprintf() format for the options defaults to "%2$s", possible
* values are:
* - %1$u: The Product ID
* - %2$s: The Product name
* @static
* @param integer $selected The optional preselected Product ID
* @param boolean $active Optional. Include active (true) or
* inactive (false) Products only.
* Ignored if null. Defaults to null
* @param string $format The optional sprintf() format
* @param boolean $showAllOptions Show all options and not only the selected
* @return array The HTML options string on success,
* null otherwise
* @global ADONewConnection
* @author Reto Kohli <reto.kohli@comvation.com>
*/
static function getMenuoptions($selected = null, $active = null, $format = '%2$s', $showAllOptions = true)
{
global $_ARRAYLANG;
$arrName = array(0 => $_ARRAYLANG['TXT_SHOP_PRODUCT_NONE']) + self::getNameArray($active, $format);
if ($arrName === false) {
return null;
}
if ($selected && !$showAllOptions) {
$arrName = array();
$product = Product::getById($selected);
$arrName[$product->id()] = $product->name();
}
return \Html::getOptions($arrName, $selected);
}
示例15: actionCopy
/**
* Copies the product
* @param int $id
*/
public function actionCopy($id)
{
$copyToProduct = new Product();
$postVariableName = get_class($copyToProduct);
if (!isset($_POST[$postVariableName])) {
$product = Product::getById((int) $id);
ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($product);
ProductZurmoCopyModelUtil::copy($product, $copyToProduct);
}
$this->processEdit($copyToProduct);
}