public function process() { $this->application->getRouter()->removeAutoAppendVariable('currency'); if (!$this->response instanceof ActionResponse) { return; } $products = $this->response->get('products'); $parents = $variations = array(); foreach ($products as $key => $product) { if ($product['parentID']) { $parents[$product['parentID']] = true; $variations[$key] = $product; } } if (!$parents) { return; } $loadedParents = array(); foreach (ActiveRecordModel::getRecordSetArray('Product', select(in(f('Product.ID'), array_keys($parents))), array('Manufacturer', 'DefaultImage' => 'ProductImage', 'Category')) as $parent) { $loadedParents[$parent['ID']] = $parent; } ProductSpecification::loadSpecificationForRecordSetArray($loadedParents); ProductPrice::loadPricesForRecordSetArray($loadedParents); foreach ($products as $key => $product) { if ($product['parentID']) { $parent = $loadedParents[$product['parentID']]; foreach ($parent as $field => $value) { if (empty($product[$field])) { $product[$field] = $parent[$field]; } } foreach (array('price_USD', 'price_CAD', 'formattedPrice', 'formattedListPrice') as $field) { if (isset($parent[$field])) { $product[$field] = $parent[$field]; } } ///var_dump($parent);exit; $products[$key] = $product; } } ProductSet::loadVariationsForProductArray($variations); foreach ($variations as $key => $variation) { $vars = array(); foreach ($variation['variationTypes'] as $type) { $vars[] = $type['name_lang']; } if ($vars) { $products[$key]['name_lang'] .= ' (' . implode(' / ', $vars) . ')'; } } $this->response->set('products', $products); }
public static function getSetlist($companyId) { $criteria = new CDbCriteria(); $criteria->condition = 't.delete_flag=0 and t.dpid=' . $companyId; $criteria->order = ' t.lid asc '; $models = ProductSet::model()->findAll($criteria); //return CHtml::listData($models, 'lid', 'category_name','pid'); //$options = array(); $options = array(yii::t('app', '--请选择分类--')); if ($models) { foreach ($models as $model) { $options[$model->lid] = $model->set_name; } //var_dump($options);exit; } return $options; }
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; }
public function __construct(CustomerOrder $order, Currency $currency) { parent::__construct(); $this->order = $order; $order->loadAll(); // billing address if ($address = $order->billingAddress->get()) { $fields = array('firstName', 'lastName', 'companyName', 'phone', 'city', 'postalCode', 'countryID' => 'country'); foreach ($fields as $key => $field) { $addressField = is_numeric($key) ? $field : $key; $this->{$field}->set($address->{$addressField}->get()); } $this->state->set($this->getStateValue($address)); $this->address->set($address->address1->get() . ' ' . $address->address2->get()); } // shipping address $address = $order->shippingAddress->get(); if (!$address) { $address = $order->billingAddress->get(); } if ($address) { foreach ($fields as $key => $field) { $addressField = is_numeric($key) ? $field : $key; $field = 'shipping' . ucfirst($field); $this->{$field}->set($address->{$addressField}->get()); } $this->shippingState->set($this->getStateValue($address)); $this->shippingAddress->set($address->address1->get() . ' ' . $address->address2->get()); } // amount $order->currency->set($currency); $this->amount->set(round($order->getDueAmount(), 2)); $this->currency->set($currency->getID()); // transaction identification $this->invoiceID->set($order->getID()); if (isset($_SERVER['REMOTE_ADDR'])) { $this->ipAddress->set($_SERVER['REMOTE_ADDR']); } // customer identification if ($order->user->get()) { $order->user->get()->load(); $this->shippingEmail->set($order->user->get()->email->get()); $this->email->set($order->user->get()->email->get()); $this->clientID->set($order->user->get()->getID()); } // order details // load variation data $variations = new ProductSet(); foreach ($order->getShoppingCartItems() as $item) { if ($item->product->get() && $item->product->get()->parent->get()) { $variations->unshift($item->product->get()); } } if ($variations->size()) { $variations->loadVariations(); } foreach ($order->getShoppingCartItems() as $item) { $product = $item->getProduct(); $variations = array(); foreach ($product->getRegisteredVariations() as $variation) { $variations[] = $variation->getValueByLang('name'); } $ri = RecurringItem::getInstanceByOrderedItem($item); if ($ri && $ri->isExistingRecord()) { $ri->load(); } else { $ri = null; } $this->addLineItem($product->getName() . ($variations ? ' (' . implode(' / ', $variations) . ')' : ''), $item->getPrice(false), $item->count->get(), $product->sku->get(), $ri); } if ($discount = $order->getFixedDiscountAmount()) { $this->addLineItem(CustomerOrder::getApplication()->translate('_discount'), $discount * -1, 1, 'discount'); } foreach ($order->getShipments() as $shipment) { if ($rate = $shipment->getSelectedRate()) { $rate = $rate->toArray(); $name = empty($rate['ShippingService']['name_lang']) ? $rate['serviceName'] : $rate['ShippingService']['name_lang']; $this->addLineItem($name, $shipment->getShippingTotalBeforeTax(), 1, 'shipping'); } } if ($taxes = $order->getTaxBreakdown()) { foreach ($taxes as $id => $amount) { $tax = Tax::getInstanceById($id, true); $this->addLineItem($tax->getValueByLang('name', null), $amount, 1, 'tax'); } } }
protected function processDataArray($productArray, $displayedColumns) { // load price data ProductPrice::loadPricesForRecordSetArray($productArray, false); // load child products // if (isset($displayedColumns['Product.parentID'])) //{ ProductSet::loadVariationTypesForProductArray($productArray); ProductSet::loadChildrenForProductArray($productArray); //} ProductSpecification::loadSpecificationForRecordSetArray($productArray, true); foreach ($productArray as &$product) { if (!empty($product['children'])) { foreach ($product['children'] as &$child) { if (!empty($product['attributes'])) { $child['attributes'] = $product['attributes']; } if (!empty($product['Manufacturer'])) { $child['Manufacturer'] = $product['Manufacturer']; } foreach (array('definedPrices', 'definedListPrices', 'price_USD', 'price_CAD', 'listPrice_USD', 'listPrice_CAD') as $key) { if (!empty($product[$key])) { $child[$key] = $product[$key]; } } foreach ($child as $key => $value) { if (empty($value) && !empty($product[$key])) { $child[$key] = $product[$key]; } } $variation = null; if (!empty($child['variationValues'])) { $variation = array_shift($child['variationValues']); } $name = $child['name']; $child['URL'] = $product['URL']; $child['name_lang'] = $name . ' ' . $child['sku']; $child['xParent'] = $child['Parent']; unset($child['Parent']); $child['URL'] = $this->router->createFullUrl(createProductUrl(array('product' => $child), $this->application)); $child['Parent'] = $child['xParent']; $child['name'] = $name; if ($variation) { $child['name'] .= ' (' . $variation . ')'; $child['name_lang'] = $child['name']; } $child['id'] = $child['ID']; } $product['URL'] = $this->router->createFullUrl(createProductUrl(array('product' => $product), $this->application)); if (empty($product['ProductImage']['ID'])) { if (!empty($product['children'][0]['ProductImage'])) { $product['ProductImage'] = $product['children'][0]['ProductImage']; $product['DefaultImage'] = $product['children'][0]['DefaultImage']; } } } $product['id'] = $product['ID']; } $defCurrency = $this->application->getDefaultCurrencyCode(); foreach ($productArray as &$product) { foreach ($this->getUserGroups() as $groupID => $groupName) { if (isset($product['priceRules'][$defCurrency][1][$groupID])) { $product['GroupPrice'][$groupID] = $product['priceRules'][$defCurrency][1][$groupID]; } } } return $productArray; }
protected function processDataArray($productArray, $displayedColumns) { // load specification data foreach ($displayedColumns as $column => $type) { list($class, $field) = explode('.', $column, 2); if ('specField' == $class) { ProductSpecification::loadSpecificationForRecordSetArray($productArray, true); break; } } // load price data ProductPrice::loadPricesForRecordSetArray($productArray, false); // load child products if (isset($displayedColumns['Product.parentID'])) { ProductSet::loadVariationTypesForProductArray($productArray); ProductSet::loadChildrenForProductArray($productArray); } $defCurrency = $this->application->getDefaultCurrencyCode(); foreach ($productArray as &$product) { foreach ($this->getUserGroups() as $groupID => $groupName) { if (isset($product['priceRules'][$defCurrency][1][$groupID])) { $product['GroupPrice'][$groupID] = $product['priceRules'][$defCurrency][1][$groupID]; } } } return $productArray; }
public function actionPrintKitchen() { $orderId = Yii::app()->request->getParam('orderId', 0); $companyId = Yii::app()->request->getParam('companyId'); $typeId = Yii::app()->request->getParam('typeId'); $callId = Yii::app()->request->getParam('callId'); Until::validOperate($companyId, $this); $db = Yii::app()->db; $ret = array(); //var_dump(Yii::app()->params->has_cache);exit; $transaction = $db->beginTransaction(); try { $order = Order::model()->with('company')->find('t.lid=:id and t.dpid=:dpid', array(':id' => $orderId, ':dpid' => $companyId)); //var_dump($order);exit; $criteria = new CDbCriteria(); $criteria->condition = 't.status in ("1","2","3") and t.dpid=' . $order->dpid . ' and t.site_id=' . $order->site_id . ' and t.is_temp=' . $order->is_temp; $criteria->order = ' t.lid desc '; $siteNo = SiteNo::model()->find($criteria); //var_dump($siteNo);exit; if ($siteNo->is_temp == '0') { $site = Site::model()->with('siteType')->find('t.lid=:lid and t.dpid=:dpid', array(':lid' => $order->site_id, ':dpid' => $order->dpid)); $site->status = '2'; $site->save(); } else { $site = new Site(); } $orderProducts = OrderProduct::model()->with('product')->findAll('t.order_id=:id and t.dpid=:dpid and t.delete_flag=0', array(':id' => $orderId, ':dpid' => $companyId)); $order->order_status = '2'; $order->callno = $callId; $order->save(); $siteNo->status = '2'; $siteNo->save(); $jobids = array(); //var_dump($orderProducts);exit; foreach ($orderProducts as $orderProduct) { $reprint = false; //var_dump($orderProduct);exit; if ($orderProduct->is_print == '0') { //echo $orderProduct->is_print; exit; $tempprintret = Helper::printKitchen($order, $orderProduct, $site, $siteNo, $reprint); sleep(4); //echo $tempprintret;exit; //if($tempprintret['status']) //{ array_push($jobids, $tempprintret['jobid'] . "_" . $orderProduct->lid); //如果失败jobid==0,检测时判断就行 //} //$orderProduct->is_print='1'; $orderProduct->product_order_status = '1'; $orderProduct->save(); if ($orderProduct->set_id != "0000000000") { $productset = ProductSet::model()->find('t.lid=:id and t.dpid=:dpid', array(':id' => $orderProduct->set_id, ':dpid' => $companyId)); if (!empty($productset)) { $productset->order_number++; $productset->save(); } } $product = Product::model()->find('t.lid=:id and t.dpid=:dpid', array(':id' => $orderProduct->product_id, ':dpid' => $companyId)); if (!empty($product)) { $product->order_number++; $product->save(); } // $product= Product::model()->find('t.lid=:id and t.dpid=:dpid' , array(':id'=>$orderProduct->product_id,':dpid'=>$companyId)); // $product->order_number++; // $product->save(); } } $transaction->commit(); //var_dump(json_encode($jobids));exit; Gateway::getOnlineStatus(); $store = Store::instance('wymenu'); $store->set("kitchenjobs_" . $companyId . "_" . $orderId, json_encode($jobids), 0, 300); $ret = array('status' => true, 'allnum' => count($jobids), 'msg' => yii::t('app', '打印任务正常发布')); } catch (Exception $e) { $transaction->rollback(); //如果操作失败, 数据回滚 $ret = array('status' => false, 'allnum' => count($jobids), 'msg' => yii::t('app', '打印任务发布异常')); Yii::app()->end(json_encode($ret)); } $this->renderPartial('printresultlist', array('orderId' => $orderId, 'ret' => $ret, 'typeId' => $typeId, 'callId' => $callId)); /*/////////////test Gateway::getOnlineStatus(); $se=new Sequence("printer_job_id"); $jobid = $se->nextval(); $test_print_data=array( "company_id"=> $this->companyId, "job_id"=>$jobid, "printer"=>"192.168.63.100", "content"=>"BBB6D3ADCAB9D3C30A0A0A0A0A0A1D5601" ); $store = Store::instance('wymenu'); $clientId=$store->get("client_".$companyId); var_dump($clientId, json_encode($test_print_data)); if(!empty($clientId)) { Gateway::sendToClient($clientId,json_encode($test_print_data)); } exit;*/ ///////////test }
public function actionIndex() { // $companyId = Yii::app()->request->getParam('companyId', '0'); $typeId = Yii::app()->request->getParam('typeId', '0'); $siteTypes = SiteClass::getTypes($this->companyId); if (empty($siteTypes)) { $typeId = 'tempsite'; } if ($typeId != 'tempsite') { $typeKeys = array_keys($siteTypes); $typeId = array_search($typeId, $typeKeys) ? $typeId : $typeKeys[0]; } $criteria = new CDbCriteria(); $criteria->condition = 't.delete_flag=0 and t.dpid=' . $companyId; $criteria->order = ' pid,lid '; $categories = ProductCategory::model()->findAll($criteria); // var_dump($categories);exit; $criteriaps = new CDbCriteria(); $criteriaps->condition = 't.delete_flag=0 and t.dpid=' . $companyId; $criteriaps->with = "productsetdetail"; $criteriaps->order = ' t.lid asc '; $productSets = ProductSet::model()->findAll($criteriaps); $setprice = array(); foreach ($productSets as $productSet) { $sqlsetsum = "select sum(price * number) as tprice from nb_product_set_detail where dpid=" . $companyId . " and set_id=" . $productSet->lid . " and is_select=1 and delete_flag=0"; $nowval = Yii::app()->db->createCommand($sqlsetsum)->queryScalar(); $setprice[$productSet->lid] = empty($nowval) ? "0.00" : $nowval; } //var_dump($setprice);exit; $criteriap = new CDbCriteria(); $criteriap->condition = 'delete_flag=0 and t.dpid=' . $companyId; // and is_show=1 $criteriap->order = ' t.category_id asc,t.lid asc '; $products = Product::model()->findAll($criteriap); //var_dump($products);exit; $productidnameArr = array(); foreach ($products as $product) { $productidnameArr[$product->lid] = $product->product_name; } //var_dump($productidnameArr);exit; $this->render('indexall', array('siteTypes' => $siteTypes, 'typeId' => $typeId, "categories" => $categories, "productSets" => $productSets, 'setprice' => $setprice, "products" => $products, "pn" => $productidnameArr)); }
public function items() { $request = $this->getRequest(); $ids = explode(',', $request->get('item_ids')); $items = array(); $this->application->getLocale()->translationManager()->loadFile('backend/Shipment'); $set = new ProductSet(); foreach ($ids as $id) { $item = ActiveRecordModel::getInstanceByID('OrderedItem', $id, OrderedItem::LOAD_DATA); $item->customerOrder->get()->load(); $item->customerOrder->get()->loadItems(); if ($image = $item->getProduct()->defaultImage->get()) { $image->load(); } $items[] = $item->toArray(); $set->add($item->getProduct()->getParent()); } $response = new ActionResponse('items', $items); // load product options and variations // pp(array_keys(ProductOption::loadOptionsForProductSet($set))); $response->set('allOptions', ProductOption::loadOptionsForProductSet($set)); $response->set('variations', $set->getVariationData($this->application)); return $response; }
public function actionDetailIndex() { $pwlid = Yii::app()->request->getParam('lid'); $criteria = new CDbCriteria(); $criteria->with = array('product'); $criteria->order = 't.group_no'; //$criteria->with = 'printer'; $criteria->condition = 't.dpid=' . $this->companyId . ' and t.set_id=' . $pwlid . ' and t.delete_flag=0 and product.delete_flag=0'; $criteria2 = new CDbCriteria(); $criteria2->condition = 't.dpid=' . $this->companyId . ' and t.lid=' . $pwlid . ' and t.delete_flag=0'; $pages = new CPagination(ProductSetDetail::model()->count($criteria)); // $pages->setPageSize(1); $pages->applyLimit($criteria); $models = ProductSetDetail::model()->findAll($criteria); $psmodel = ProductSet::model()->find($criteria2); // var_dump($psmodel);exit; $this->render('detailindex', array('models' => $models, 'psmodel' => $psmodel, 'pages' => $pages)); }
public function actionIndex() { //$sc = Yii::app()->request->getPost('csinquery'); $typeId = Yii::app()->request->getParam('typeId'); $categoryId = Yii::app()->request->getParam('cid', ""); $fromId = Yii::app()->request->getParam('from', 'sidebar'); $csinquery = Yii::app()->request->getPost('csinquery', ""); //var_dump($csinquery);exit; if ($typeId == 'product') { $criteria = new CDbCriteria(); $criteria->with = array('company', 'category'); $criteria->condition = 't.delete_flag=0 and t.dpid=' . $this->companyId; if (!empty($categoryId)) { $criteria->condition .= ' and t.category_id = ' . $categoryId; } if (!empty($csinquery)) { $criteria->condition .= ' and t.simple_code like "%' . strtoupper($csinquery) . '%"'; } $pages = new CPagination(Product::model()->count($criteria)); // $pages->setPageSize(1); $pages->applyLimit($criteria); $models = Product::model()->findAll($criteria); $categories = $this->getCategories(); //var_dump($models);exit; $this->render('index', array('models' => $models, 'pages' => $pages, 'categories' => $categories, 'categoryId' => $categoryId, 'typeId' => $typeId)); } else { $criteria = new CDbCriteria(); $criteria->condition = 't.delete_flag=0 and t.dpid=' . $this->companyId; $pages = new CPagination(ProductSet::model()->count($criteria)); $pages->applyLimit($criteria); $models = ProductSet::model()->findAll($criteria); //var_dump($models);exit; $this->render('index', array('models' => $models, 'pages' => $pages, 'typeId' => $typeId)); } //var_dump($sc);exit; //$db = Yii::app()->db; /*if(empty($sc)) { $sql = "SELECT 0 as isset,lid,dpid,product_name as name,simple_code as cs,main_picture as pic , status from nb_product where delete_flag=0 and is_show=1 and dpid=".$this->companyId . " union ". "SELECT 1 as isset,lid,dpid,set_name as name,simple_code as cs,main_picture as pic ,status from nb_product_set where delete_flag=0 and dpid=".$this->companyId ; }else{ $sql = "SELECT 0 as isset,lid,dpid,product_name as name,simple_code as cs,main_picture as pic , status from nb_product where delete_flag=0 and is_show=1 and dpid=".$this->companyId." and simple_code like '%".$sc."%'" . " union ". "SELECT 1 as isset,lid,dpid,set_name as name,simple_code as cs,main_picture as pic ,status from nb_product_set where delete_flag=0 and dpid=".$this->companyId." and simple_code like '%".$sc."%'" ; } $command=$db->createCommand($sql); //$command->bindValue(":table" , $this->table); $models= $command->queryAll(); //var_dump($models);exit; $criteria = new CDbCriteria; $pages = new CPagination(count($models)); // $pages->setPageSize(1); $pages->applyLimit($criteria); $this->render('index',array( 'models'=>$models, 'pages'=>$pages ));*/ }