本文整理汇总了PHP中Product::getInstanceByID方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getInstanceByID方法的具体用法?PHP Product::getInstanceByID怎么用?PHP Product::getInstanceByID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Product
的用法示例。
在下文中一共展示了Product::getInstanceByID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* @role create
*/
public function create()
{
$request = $this->getRequest();
$rpp = RecurringProductPeriod::getNewInstance(Product::getInstanceByID((int) $request->get('productID'), ActiveRecord::LOAD_DATA));
$rpp->position->set(1000);
return $this->save($rpp);
}
示例2: add_to_cart
public function add_to_cart()
{
$request = $this->application->getRequest();
$productID = $request->get('productID');
$customerOrderID = $request->get('customerOrderID');
$count = $request->get('count');
if (!isset($customerOrderID) && intval($customerOrderID == 0)) {
throw new Exception('Order ID is required');
}
$order = CustomerOrder::getInstanceById($customerOrderID);
$order->load(true);
$order->loadAll();
//throw new Exception('order : ' . $order->getTotal(true));
$product = Product::getInstanceByID($productID, true, true);
$product->load(true);
//$variations = !$product->parent->get() ? $product->getVariationData($this->application) : array('1','2');
//throw new Exception('variation ' . json_encode($variations) . ' parent : ' . $product->getID() . ' productID ' . $productID);
if (!$product->isAvailable()) {
throw new Exception('Product ' . $productID . ' is not Available ');
} else {
if ($count < $product->getMinimumQuantity()) {
$count = $product->getMinimumQuantity();
}
ActiveRecordModel::beginTransaction();
$item = $order->addProduct($product, $count);
if ($item instanceof OrderedItem) {
if ($order->isMultiAddress->get()) {
$item->save();
}
}
if ($product->parent->get()) {
$order->mergeItems();
} else {
$item->save();
}
//$order->mergeItems();
$order->getTotal(true);
$order->totalAmount->set($order->getTotal(true));
$order->getTaxAmount();
$order->save(true);
ActiveRecordModel::commit();
}
$response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
if ($item->getID() > 0) {
$parser = $this->getParser();
$apiFieldNames = $parser->getApiFieldNames();
$selFilter = new ARSelectFilter();
$selFilter->mergeCondition(new EqualsCond(new ARFieldHandle('OrderedItem', 'ID'), $item->getID()));
$orderedItem = OrderedItem::getRecordSetArray('OrderedItem', $selFilter);
while ($item = array_shift($orderedItem)) {
$orderedItemXml = $response->addChild('ordered_item');
foreach ($item as $k => $v) {
if (in_array($k, $apiFieldNames)) {
$orderedItemXml->addChild($k, htmlentities($v));
}
}
}
}
return new SimpleXMLResponse($response);
}
示例3: getKeywordsString
protected function getKeywordsString($array)
{
if (isset($array['Product'])) {
$array = $array['Product'];
}
if (empty($array['sku'])) {
return null;
}
if (is_string($array['name'])) {
$array['name_lang'] = $array['name'];
}
if (isset($array['DefaultImage']) && is_array($array['DefaultImage']['Product']['name']) && !empty($array['DefaultImage']['Product']['name']['en'])) {
$array['name_lang'] = $array['DefaultImage']['Product']['name']['en'];
}
if (!empty($array['parentID']) && empty($array['Parent'])) {
$array['Parent'] = Product::getInstanceByID($array['parentID'], true)->toArray();
}
if (!empty($array['Parent']['name_lang']) && empty($array['name_lang'])) {
$array['name_lang'] = $array['Parent']['name_lang'];
}
$name = isset($array['name_lang']) ? $array['name_lang'] : array_shift($array['name']);
//if (!$name) { var_dump($array); exit; }
$str = $name . '-' . $array['sku'];
//var_dump($str);
if ($str) {
$str = preg_replace('/[^a-zA-Z0-9_\\-]/', '', urldecode(createHandleString($str)));
}
return $str && strlen($str) > 0 ? $str : null;
}
示例4: process
public function process()
{
AddRatingFieldToSchema::process();
$main = Product::getInstanceByID($this->request->get('id'), true);
if ($main->parent->get()) {
$main->parent->get()->load();
$var = $main->toArray();
$var['custom'] = $main->custom->get();
$this->request->set('variation', $var);
$this->request->set('activeVariationID', $this->request->get('id'));
$main = $main->parent->get();
$this->request->set('id', $main->getID());
$productArray = $main->toArray();
$handle = empty($productArray['URL']) ? $productArray['name_lang'] : $productArray['URL'];
$this->request->set('producthandle', $handle);
}
ActiveRecord::clearPool();
$variations = $main->getRelatedRecordSet('Product', select());
$handle = $main->URL->get() ? $main->URL->get() : $main->getValueByLang('name', 'en');
foreach ($variations as $variation) {
$variation->setValueByLang('name', 'en', $main->getValueByLang('name', 'en') . ' ' . $variation->sku->get());
$variation->URL->set($handle . ' ' . $variation->sku->get());
$variation->parent->set(null);
}
$variations->toArray();
}
示例5: delete
public function delete()
{
$product = Product::getInstanceByID($this->request->get('id'), ActiveRecord::LOAD_DATA, array('Category'));
$category = Category::getInstanceByID($this->request->get('categoryId'), ActiveRecord::LOAD_DATA);
$relation = ActiveRecordModel::getInstanceById('ProductCategory', array('productID' => $product->getID(), 'categoryID' => $category->getID()));
$relation->delete();
return new JSONResponse(array('data' => $relation->toFlatArray()));
}
示例6: specification
public function specification()
{
$request = $this->application->getRequest();
$productID = $request->get('ID');
$product = Product::getInstanceByID($productID, Product::LOAD_DATA, Product::LOAD_REFERENCES);
$product->load();
throw new Exception(' product ' . json_encode($product->getSpecification()));
}
示例7: process
public function process()
{
$custom = $this->request->get('custom');
foreach (json_decode($this->request->get('items')) as $key => $id) {
$prod = Product::getInstanceByID($id, true);
$prod->custom->set($custom[$key]);
$prod->save();
}
}
示例8: create
public function create()
{
$parentId = $this->request->get('parentID', false);
if (substr($parentId, 0, 1) == 'c') {
$parent = Category::getInstanceByID(substr($parentId, 1));
} else {
$parent = Product::getInstanceByID($parentId);
}
$productOption = ProductOption::getNewInstance($parent);
return $this->save($productOption);
}
示例9: index
public function index()
{
$productID = (int) $this->request->get('id');
$product = Product::getInstanceByID($productID, ActiveRecord::LOAD_DATA);
$response = new ActionResponse();
$response->set('ownerID', $productID);
$response->set('categoryID', $product->category->get()->getID());
$response->set('items', ProductBundle::getBundledProductArray($product));
$currency = $this->application->getDefaultCurrency();
$response->set('total', $currency->getFormattedPrice(ProductBundle::getTotalBundlePrice($product, $currency)));
return $response;
}
示例10: create
/**
* @role update
*/
public function create()
{
$product = Product::getInstanceByID((int) $this->request->get('productID'));
if ($uploadFile = $this->request->get('uploadFile')) {
$tmpPath = $uploadFile['tmp_name'];
$name = $uploadFile['name'];
} else {
$tmpPath = null;
$name = basename($this->request->get('filePath'));
}
$productFile = ProductFile::getNewInstance($product, $tmpPath, $name, $this->request->get('filePath'));
return $this->save($productFile);
}
示例11: index
public function index()
{
//error_reporting(E_ALL);ini_set('display_errors', 1);
$product = Product::getInstanceByID($this->request->get('id'), true);
$mirror = null;
foreach ($product->getRelatedRecordSetArray('ProductImage', select()) as $image) {
if ($image['title_lang'] == 'Virtual Mirror') {
$mirror = $image['urls'][3];
}
}
if ($mirror) {
$response = new BlockResponse();
$response->set('mirror', $mirror);
return $response;
}
}
示例12: add
/**
* Creates new relationship
*
* @role update
*/
public function add()
{
$productID = $this->request->get('relatedownerID');
$ownerID = $this->request->get('id');
$list = ActiveRecordModel::getInstanceById('ProductList', $ownerID, ActiveRecordModel::LOAD_DATA);
$product = Product::getInstanceByID($productID, Product::LOAD_DATA, array('ProductImage'));
if (!$list->contains($product)) {
$list->addProduct($product);
$response = new ActionResponse();
$response->set('product', $product->toArray());
$response->set('added', true);
return $response;
} else {
return new JSONResponse(array('error' => $this->translate('_err_multiple')));
}
}
示例13: getBestsellerData
private function getBestsellerData($sql, $order = 'DESC')
{
$this->setChartType(self::TABLE);
$q = $this->getQuery($sql);
$f = $q->getFilter();
$f->resetOrder();
$f->resetGrouping();
$f->setOrder(new ARExpressionHandle('cnt'), $order);
$q->addField('OrderedItem.productID');
$f->setGrouping(new ARExpressionHandle('OrderedItem.productID'));
$f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), 1));
$f->setLimit(self::TABLE_LIMIT);
$q->joinTable('CustomerOrder', 'OrderedItem', 'ID', 'customerOrderID');
$this->getReportData($q);
$ids = array();
foreach ($this->values as $product) {
$ids[$product['productID']] = $product['cnt'];
}
// fetch product details
$fields = array_flip(array('sku', 'name', 'cnt'));
$products = ActiveRecordModel::getRecordSetArray('Product', new ARSelectFilter(new INCond(new ARFieldHandle('Product', 'ID'), array_keys($ids))), array('Parent'));
ProductSet::loadVariationsForProductArray($products);
foreach ($products as $product) {
$product['cnt'] = $ids[$product['ID']];
if (empty($product['name'])) {
if (!empty($product['parentID'])) {
$parent = Product::getInstanceByID($product['parentID'], true);
$product['name'] = $parent->getValueByLang('name');
} else {
$product['name'] = '';
}
}
if (isset($product['variationValues'])) {
$product['name'] .= ' (' . implode(' / ', $product['variationValues']) . ')';
}
// array_merge to put all array values in the same order
$ids[$product['ID']] = array_merge($fields, array_intersect_key($product, $fields));
}
$this->values = $ids;
}
示例14: add
/**
* Creates new relationship
*
* @role update
*/
public function add()
{
$productID = $this->request->get('relatedownerID');
$ownerID = $this->request->get('id');
$owner = Product::getInstanceByID($ownerID, Product::LOAD_DATA);
$product = Product::getInstanceByID($productID, Product::LOAD_DATA, array('ProductImage'));
if ($product->isBundle()) {
return new JSONResponse(array('error' => $this->translate('_err_bundle_with_bundle')));
}
if (!ProductBundle::hasRelationship($owner, $product)) {
$instance = ProductBundle::getNewInstance($owner, $product);
if (!$instance) {
return new JSONResponse(array('error' => $this->translate('_err_add_to_itself')));
}
$instance->save();
$response = new ActionResponse();
$response->set('product', $product->toArray());
$response->set('added', true);
$response->set('total', $this->getTotal($owner));
return $response;
} else {
return new JSONResponse(array('error' => $this->translate('_err_multiple')));
}
}
示例15: countTabsItems
public function countTabsItems()
{
ClassLoader::import('application.model.product.*');
$product = Product::getInstanceByID((int) $this->request->get('id'), ActiveRecord::LOAD_DATA);
return new JSONResponse(array('tabProductBundle' => count(ProductBundle::getBundledProductArray($product)), 'tabProductRelationship' => $product->getRelationships(ProductRelationship::TYPE_CROSS)->getTotalRecordCount(), 'tabProductUpsell' => $product->getRelationships(ProductRelationship::TYPE_UP)->getTotalRecordCount(), 'tabProductFiles' => $product->getFiles(false)->getTotalRecordCount(), 'tabProductImages' => count($product->getImageArray()), 'tabProductOptions' => $product->getOptions()->getTotalRecordCount(), 'tabProductReviews' => $product->getRelatedRecordCount('ProductReview'), 'tabProductCategories' => $product->getRelatedRecordCount('ProductCategory') + 1, 'tabProductVariations' => $product->getRelatedRecordCount('Product', new ARSelectFilter(new EqualsCond(new ARFieldHandle('Product', 'isEnabled'), true)))));
}