<?php namespace Afosto\ActiveAnts; require_once dirname(__FILE__) . '/vendor/autoload.php'; //Include our configs require_once dirname(__FILE__) . '/../config.php'; //Make sure this directory is writable $cacheDirectory = dirname(__FILE__) . '/../cache/'; App::start($url, $user, $password, $cacheDirectory); $product = Product::model()->setName('testProduct')->setSku('testSku'); if (!$product->save()) { echo $product->getMessage(); } $item = OrderItem::model()->setSku('testSku', false)->setGrossPrice(1.21)->setName('testProduct')->setTaxRate(21); $address = Address::model()->setName('Afosto SaaS BV')->setAddress('Protonstraat', 9, 'a')->setCity('Groningen')->setCountry('NL')->setPostalcode('9743AL'); $order = Order::model()->setEmail('*****@*****.**')->setOrderId('#' . rand(100, 999))->setPhoneNumber('test')->addOrderItem($item)->setBillingAddress($address)->setShippingAddress(); //$order->setPickupPoint('NL-111101', '1111AA', 'Straatnaam 10a' , 'Groningen'); if (!$order->save()) { echo $order->getMessage(); } $purchase = PurchaseOrder::model()->addItem('testSku', 1)->addReference('testPurchaseOrder'); if (!$purchase->save()) { echo $purchase->getMessage(); } foreach (Stock::model()->findAll() as $stock) { echo $stock->sku . ': ' . $stock->stock . "\n"; }
public function afterSave() { $num = OrderItem::model()->count(array('condition' => 'item_id=:item_id ', 'params' => array(':item_id' => $this->item_id))); $model = Item::model()->findByPk($this->item_id); $model->deal_count = $num; $model->save(); return parent::afterSave(); }
public function actionCheckStock() { $number = $_GET['number']; $sku_id = $_GET['sku_id']; $sku = Sku::model()->findByPk($sku_id); $criteria = new CDbCriteria(); $criteria->addCondition('item_id=:item_id'); $criteria->addCondition('price=:price'); $criteria->addCondition('props_name=:props_name'); $criteria->params[':item_id'] = $sku->item_id; $criteria->params[':price'] = $sku->price; $criteria->params[':props_name'] = $sku->props_name; $orderItem = OrderItem::model()->find($criteria); if ($sku->stock + $orderItem->quantity < $number || $number <= 0) { echo 0; } else { echo 1; } }
public function getProducts($which = 'after') { $order = array(); $products = array(); if (($which == 'after' || $which == 'both') && isset($this->_SupplierProduct[$this->delivery_date_id])) { $products = $this->_SupplierProduct[$this->delivery_date_id]; } else { if ($which == 'before' && isset($this->_SupplierProduct_Before[$this->delivery_date_id])) { $products = $this->_SupplierProduct_Before[$this->delivery_date_id]; } } if ($which == 'both' && isset($this->_SupplierProduct_Before[$this->delivery_date_id])) { foreach ($this->_SupplierProduct_Before[$this->delivery_date_id] as $pid => $qty) { if (!isset($products[$pid])) { $products[$pid] = $qty; } } } if (empty($products)) { return $order; } $Order = $this->_getOrder($this->_user->id, $this->delivery_date_id, $this->_location_id); $Order = $Order->id ? $Order : false; //We don't to create a new order foreach ($products as $id => $qty) { $OI = null; if ($Order) { $OI = OrderItem::model()->findByAttributes(array('supplier_product_id' => $id, 'order_id' => $Order->id)); } if (!$OI) { $OI = new OrderItem(); $OI->supplier_product_id = $id; } $SP = $OI->SupplierProduct; $OI->quantity = $qty; //Only update price etc if it hasn't been set yet. if (empty($OI->name)) { $OI->price = $SP->item_sales_price; $OI->name = $SP->name; $OI->unit = $SP->unit; $OI->packing_station_id = $SP->packing_station_id; } $order[] = $OI; } return $order; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return OrderItem the loaded model * @throws CHttpException */ public function loadModel($id) { $model = OrderItem::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * Predicate for checking wether the order can be deleted or not. * * @return boolean */ public function getCanBeDeleted() { return !OrderItem::model()->forOrder($this)->exists(); }
public function getExtras_total() { $criteria = new CDbCriteria(); $criteria->select = 'SUM(price * quantity) as date_total'; $criteria->with = 'Order'; $criteria->condition = 'delivery_date_id=:dateId AND user_id=:customerId'; $criteria->params = array(':dateId' => $this->delivery_date_id, ':customerId' => $this->user_id); $extras = OrderItem::model()->find($criteria); $extrasTotal = $extras ? $extras->date_total : 0; return $extrasTotal; }