/** * Sets up the fixture, especially creates products. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $orderProducts = array(); $context = TestHelper::getContext(); $couponManager = MShop_Coupon_Manager_Factory::createManager($context); $this->_couponItem = $couponManager->createItem(); $provider = new MShop_Coupon_Provider_Example($context, $this->_couponItem, 'abcd'); $this->_object = new MShop_Coupon_Provider_Decorator_BasketValues($context, $this->_couponItem, 'abcd', $provider); $this->_object->setObject($this->_object); $orderManager = MShop_Order_Manager_Factory::createManager($context); $orderBaseManager = $orderManager->getSubManager('base'); $orderProductManager = $orderBaseManager->getSubManager('product'); $productManager = MShop_Product_Manager_Factory::createManager($context); $search = $productManager->createSearch(); $search->setConditions($search->compare('==', 'product.code', array('CNC'))); $products = $productManager->searchItems($search); $priceManager = MShop_Price_Manager_Factory::createManager($context); $price = $priceManager->createItem(); $price->setValue(321); foreach ($products as $product) { $orderProduct = $orderProductManager->createItem(); $orderProduct->copyFrom($product); $orderProducts[$product->getCode()] = $orderProduct; } $orderProducts['CNC']->setPrice($price); $this->_orderBase = new MShop_Order_Item_Base_Default($priceManager->createItem(), $context->getLocale()); $this->_orderBase->addProduct($orderProducts['CNC']); }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->_editor = TestHelper::getContext()->getEditor(); $manager = MShop_Price_Manager_Factory::createManager(TestHelper::getContext()); $listManager = $manager->getSubManager('list'); $this->_object = $listManager->getSubManager('type'); }
/** * Gets required price item ids. * * @param array $keys List of keys for search * @return array $refIds List with referenced Ids * @throws MW_Setup_Exception If a required ID is not available */ protected function _getPriceData(array $keys) { $priceManager = MShop_Price_Manager_Factory::createManager($this->_additional, 'Default'); $priceTypeManager = $priceManager->getSubManager('type', 'Default'); $value = $ship = $domain = $code = array(); foreach ($keys as $dataset) { $exp = explode('/', $dataset); if (count($exp) != 5) { throw new MW_Setup_Exception(sprintf('Some keys for ref price are set wrong "%1$s"', $dataset)); } $domain[] = $exp[1]; $code[] = $exp[2]; $value[] = $exp[3]; $ship[] = $exp[4]; } $search = $priceTypeManager->createSearch(); $expr = array($search->compare('==', 'price.type.domain', $domain), $search->compare('==', 'price.type.code', $code)); $search->setConditions($search->combine('&&', $expr)); $result = $priceTypeManager->searchItems($search); $typeids = array(); foreach ($result as $item) { $typeids[] = $item->getId(); } $search = $priceManager->createSearch(); $expr = array($search->compare('==', 'price.value', $value), $search->compare('==', 'price.costs', $ship), $search->compare('==', 'price.typeid', $typeids)); $search->setConditions($search->combine('&&', $expr)); $result = $priceManager->searchItems($search); $refIds = array(); foreach ($result as $item) { $refIds['price/' . $item->getDomain() . '/' . $item->getType() . '/' . $item->getValue() . '/' . $item->getCosts()] = $item->getId(); } return $refIds; }
/** * Initializes the price list type controller. * * @param MShop_Context_Item_Interface $context MShop context object */ public function __construct(MShop_Context_Item_Interface $context) { parent::__construct($context, 'Price_List_Type'); $manager = MShop_Price_Manager_Factory::createManager($context); $listManager = $manager->getSubManager('list'); $this->_manager = $listManager->getSubManager('type'); }
public function testCreateManagerNotExisting() { $this->setExpectedException('MShop_Exception'); $target = 'MShop_Common_Manager_Interface'; $manager = MShop_Price_Manager_Factory::createManager(TestHelper::getContext(), 'test'); $this->assertInstanceOf($target, $manager); }
protected function setUp() { $this->_price = MShop_Price_Manager_Factory::createManager(TestHelper::getContext())->createItem(); $attrValues = array('id' => 3, 'siteid' => 99, 'ordservid' => 42, 'name' => 'UnitName', 'type' => 'default', 'code' => 'UnitCode', 'value' => 'UnitValue', 'mtime' => '2020-12-31 23:59:59', 'ctime' => '2011-01-01 00:00:01', 'editor' => 'unitTestUser'); $this->_attribute = array('UnitCode' => new MShop_Order_Item_Base_Service_Attribute_Default($attrValues)); $this->_values = array('id' => 1, 'siteid' => 99, 'servid' => 'ServiceID', 'baseid' => 42, 'code' => 'UnitCode', 'name' => 'UnitName', 'mediaurl' => 'Url for test', 'type' => 'payment', 'mtime' => -99, 'ctime' => '2011-01-01 00:00:01', 'editor' => 'unitTestUser'); $this->_object = new MShop_Order_Item_Base_Service_Default($this->_price, $this->_values, $this->_attribute); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->_price = MShop_Price_Manager_Factory::createManager(TestHelper::getContext())->createItem(); $attrValues = array('id' => 4, 'siteid' => 99, 'ordprodid' => 11, 'type' => 'default', 'code' => 'size', 'value' => '30', 'name' => 'small', 'mtime' => '2011-01-06 13:20:34', 'ctime' => '2011-01-01 00:00:01', 'editor' => 'unitTestUser'); $this->_attribute = array(new MShop_Order_Item_Base_Product_Attribute_Default($attrValues)); $this->_values = array('id' => 1, 'siteid' => 99, 'ordprodid' => 10, 'type' => 'bundle', 'prodid' => 10, 'baseid' => 42, 'suppliercode' => 'UnitSupplier', 'productid' => 111, 'prodcode' => 'UnitProd', 'warehousecode' => 'unitwarehouse', 'name' => 'UnitProduct', 'mediaurl' => 'testurl', 'quantity' => 11, 'flags' => MShop_Order_Item_Base_Product_Abstract::FLAG_NONE, 'status' => MShop_Order_Item_Abstract::STAT_PROGRESS, 'pos' => 1, 'mtime' => '2000-12-31 23:59:59', 'ctime' => '2011-01-01 00:00:01', 'editor' => 'unitTestUser'); $this->_subProducts = array(new MShop_Order_Item_Base_Product_Default(clone $this->_price), new MShop_Order_Item_Base_Product_Default(clone $this->_price)); $this->_object = new MShop_Order_Item_Base_Product_Default($this->_price, $this->_values, $this->_attribute, $this->_subProducts); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $context = TestHelper::getContext(); $priceManager = MShop_Price_Manager_Factory::createManager($context); $item = MShop_Coupon_Manager_Factory::createManager($context)->createItem(); // Don't create order base item by createItem() as this would already register the plugins $this->_orderBase = new MShop_Order_Item_Base_Default($priceManager->createItem(), $context->getLocale()); $this->_object = new MShop_Coupon_Provider_Example($context, $item, '1234'); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $context = TestHelper::getContext(); $priceManager = MShop_Price_Manager_Factory::createManager($context); $couponItem = MShop_Coupon_Manager_Factory::createManager($context)->createItem(); $couponItem->setConfig(array('present.productcode' => 'U:PD', 'present.quantity' => '1')); // Don't create order base item by createItem() as this would already register the plugins $this->_orderBase = new MShop_Order_Item_Base_Default($priceManager->createItem(), $context->getLocale()); $this->_object = new MShop_Coupon_Provider_Present($context, $couponItem, 'zyxw'); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $context = TestHelper::getContext(); $pluginManager = MShop_Plugin_Manager_Factory::createManager($context); $this->_plugin = $pluginManager->createItem(); $this->_plugin->setProvider('Coupon'); $this->_plugin->setStatus(1); $priceItem = MShop_Price_Manager_Factory::createManager($context)->createItem(); $this->_order = new MShop_Order_Item_Base_Default($priceItem, $context->getLocale()); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $context = TestHelper::getContext(); $pluginManager = MShop_Plugin_Manager_Factory::createManager($context); $item = $pluginManager->createItem(); $provider = new MShop_Plugin_Provider_Order_Example($context, $item); $priceItem = MShop_Price_Manager_Factory::createManager($context)->createItem(); $this->_order = new MShop_Order_Item_Base_Default($priceItem, $context->getLocale()); $this->_object = new MShop_Plugin_Provider_Decorator_Log($context, $item, $provider); }
/** * Adds the price test data. * * @param array $testdata Associative list of key/list pairs * @throws MW_Setup_Exception If a required ID is not available */ private function _addPriceData(array $testdata) { $priceManager = MShop_Price_Manager_Factory::createManager($this->_additional, 'Default'); $priceTypeManager = $priceManager->getSubManager('type', 'Default'); $priceUnitManager = $priceManager->getSubManager('unit', 'Default'); $ptypeIds = $punitIds = array(); $ptype = $priceTypeManager->createItem(); $punit = $priceUnitManager->createItem(); $this->_conn->begin(); foreach ($testdata['price/unit'] as $key => $dataset) { $punit->setId(null); $punit->setCode($dataset['code']); $punit->setLabel($dataset['label']); $punit->setStatus($dataset['status']); $priceUnitManager->saveItem($punit); $punitIds[$key] = $punit->getId(); } foreach ($testdata['price/type'] as $key => $dataset) { $ptype->setId(null); $ptype->setCode($dataset['code']); $ptype->setDomain($dataset['domain']); $ptype->setLabel($dataset['label']); $ptype->setStatus($dataset['status']); $priceTypeManager->saveItem($ptype); $ptypeIds[$key] = $ptype->getId(); } $price = $priceManager->createItem(); foreach ($testdata['price'] as $key => $dataset) { if (!isset($ptypeIds[$dataset['typeid']])) { throw new MW_Setup_Exception(sprintf('No price type ID found for "%1$s"', $dataset['typeid'])); } if (!isset($punitIds[$dataset['unitid']])) { throw new MW_Setup_Exception(sprintf('No price unit ID found for "%1$s"', $dataset['unitid'])); } $price->setId(null); $price->setCurrencyId($dataset['currencyid']); $price->setTypeId($ptypeIds[$dataset['typeid']]); $price->setDomain($dataset['domain']); $price->setLabel($dataset['label']); $price->setQuantity($dataset['quantity']); $price->setValue($dataset['value']); $price->setCosts($dataset['shipping']); $price->setRebate($dataset['rebate']); $price->setTaxRate($dataset['taxrate']); $price->setDivisibility($dataset['divisibility']); $price->setUnitId($punitIds[$dataset['unitid']]); $price->setStatus($dataset['status']); $priceManager->saveItem($price, false); } $this->_conn->commit(); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $context = TestHelper::getContext(); $couponItem = MShop_Coupon_Manager_Factory::createManager($context)->createItem(); $couponItem->setConfig(array('freeshipping.productcode' => 'U:SD')); $this->_object = new MShop_Coupon_Provider_FreeShipping($context, $couponItem, 'zyxw'); $delPrice = MShop_Price_Manager_Factory::createManager($context)->createItem(); $delPrice->setCosts('5.00'); $delPrice->setCurrencyId('EUR'); $priceManager = MShop_Price_Manager_Factory::createManager($context); $manager = MShop_Order_Manager_Factory::createManager($context)->getSubManager('base')->getSubManager('service'); $delivery = $manager->createItem(); $delivery->setCode('test'); $delivery->setType('delivery'); $delivery->setPrice($delPrice); // Don't create order base item by createItem() as this would already register the plugins $this->_orderBase = new MShop_Order_Item_Base_Default($priceManager->createItem(), $context->getLocale()); $this->_orderBase->setService($delivery, 'delivery'); }
protected function _getListItems() { $manager = MShop_Price_Manager_Factory::createManager($this->_context, 'Default'); $search = $manager->createSearch(); $expr = array($search->compare('==', 'price.domain', 'attribute'), $search->compare('==', 'price.value', '99.99'), $search->compare('==', 'price.type.code', 'default')); $search->setConditions($search->combine('&&', $expr)); $search->setSlice(0, 1); $results = $manager->searchItems($search); if (($item = reset($results)) === false) { throw new Exception('No price item found'); } $search = $this->_object->createSearch(); $expr = array($search->compare('==', 'price.list.parentid', $item->getId()), $search->compare('==', 'price.list.domain', 'customer'), $search->compare('==', 'price.list.editor', $this->_editor), $search->compare('==', 'price.list.type.code', 'default')); $search->setConditions($search->combine('&&', $expr)); $search->setSortations(array($search->sort('+', 'price.list.position'))); return $this->_object->searchItems($search); }
public function testCreateManagerNotExisting() { $this->setExpectedException('MShop_Exception'); MShop_Price_Manager_Factory::createManager(TestHelper::getContext(), 'unknown'); }
/** * Adds the price-list test data. * * @param array $testdata Associative list of key/list pairs * @param array $refIds Associative list of domains and the keys/IDs of the inserted items * @throws MW_Setup_Exception If a required ID is not available */ private function _addPriceListData(array $testdata, array $refIds) { $priceManager = MShop_Price_Manager_Factory::createManager($this->_additional, 'Default'); $priceTypeManager = $priceManager->getSubManager('type', 'Default'); $priceListManager = $priceManager->getSubManager('list', 'Default'); $priceListTypeManager = $priceListManager->getSubManager('type', 'Default'); $value = $ship = $domain = $code = array(); foreach ($testdata['price/list'] as $dataset) { $exp = explode('/', $dataset['parentid']); if (count($exp) != 5) { throw new MW_Setup_Exception(sprintf('Some keys for parentid are set wrong "%1$s"', $dataset['parentid'])); } $domain[] = $exp[1]; $code[] = $exp[2]; $value[] = $exp[3]; $ship[] = $exp[4]; } $search = $priceTypeManager->createSearch(); $expr = array($search->compare('==', 'price.type.domain', $domain), $search->compare('==', 'price.type.code', $code)); $search->setConditions($search->combine('&&', $expr)); $typeids = array(); foreach ($priceTypeManager->searchItems($search) as $item) { $typeids[] = $item->getId(); } $search = $priceManager->createSearch(); $expr = array($search->compare('==', 'price.value', $value), $search->compare('==', 'price.costs', $ship), $search->compare('==', 'price.typeid', $typeids)); $search->setConditions($search->combine('&&', $expr)); $parentIds = array(); foreach ($priceManager->searchItems($search) as $item) { $parentIds['price/' . $item->getDomain() . '/' . $item->getType() . '/' . $item->getValue() . '/' . $item->getCosts()] = $item->getId(); } $listItemTypeIds = array(); $listItemType = $priceListTypeManager->createItem(); $this->_conn->begin(); foreach ($testdata['price/list/type'] as $key => $dataset) { $listItemType->setId(null); $listItemType->setCode($dataset['code']); $listItemType->setDomain($dataset['domain']); $listItemType->setLabel($dataset['label']); $listItemType->setStatus($dataset['status']); $priceListTypeManager->saveItem($listItemType); $listItemTypeIds[$key] = $listItemType->getId(); } $listItem = $priceListManager->createItem(); foreach ($testdata['price/list'] as $dataset) { if (!isset($parentIds[$dataset['parentid']])) { throw new MW_Setup_Exception(sprintf('No price ID found for "%1$s"', $dataset['parentid'])); } if (!isset($listItemTypeIds[$dataset['typeid']])) { throw new MW_Setup_Exception(sprintf('No attribute list type ID found for "%1$s"', $dataset['typeid'])); } if (!isset($refIds[$dataset['domain']][$dataset['refid']])) { throw new MW_Setup_Exception(sprintf('No "%1$s" ref ID found for "%2$s"', $dataset['refid'], $dataset['domain'])); } $listItem->setId(null); $listItem->setParentId($parentIds[$dataset['parentid']]); $listItem->setTypeId($listItemTypeIds[$dataset['typeid']]); $listItem->setRefId($refIds[$dataset['domain']][$dataset['refid']]); $listItem->setDomain($dataset['domain']); $listItem->setDateStart($dataset['start']); $listItem->setDateEnd($dataset['end']); $listItem->setConfig($dataset['config']); $listItem->setPosition($dataset['pos']); $listItem->setStatus($dataset['status']); $priceListManager->saveItem($listItem, false); } $this->_conn->commit(); }
public function testUpdateTotalValueMax() { $priceManager = MShop_Price_Manager_Factory::createManager(TestHelper::getContext()); $this->_plugin->setConfig(array('total-value-max' => array('EUR' => '110.00'))); $price = $priceManager->createItem(); $price->setValue('100.00'); $this->_products['CNC']->setPrice($price); $this->_products['CNC']->setQuantity(1); $this->assertTrue($this->_object->update($this->_order, 'addProduct.before', $this->_products['CNC'])); $this->_order->addProduct($this->_products['CNC']); $price = $priceManager->createItem(); $price->setValue('10.00'); $this->_products['CNE']->setPrice($price); $this->_products['CNE']->setQuantity(2); $this->setExpectedException('MShop_Plugin_Exception'); $this->_object->update($this->_order, 'addProduct.before', $this->_products['CNE']); }
protected function _cleanupPrice() { $manager = MShop_Price_Manager_Factory::createManager($this->_context); $search = $manager->createSearch(); $expr = array($search->compare('==', 'price.domain', 'product'), $search->compare('==', 'price.label', 'import-%')); $search->setConditions($search->combine('&&', $expr)); $search->setSortations(array($search->sort('+', 'price.id'))); $start = 0; do { $result = $manager->searchItems($search); $manager->deleteItems(array_keys($result)); $count = count($result); $start += $count; $search->setSlice($start); } while ($count == $search->getSliceSize()); }
/** * Adds the required order base product data. * * @param MShop_Order_Manager_Base_Interface $orderBaseManager Order Base Manager * @param array $bases Associative list of key/list pairs * @param array $testdata Associative list of key/list pairs * @throws MW_Setup_Exception If no type ID is found */ protected function _addOrderBaseProductData(MShop_Common_Manager_Interface $orderBaseManager, array $bases, array $testdata) { $ordProds = array(); $products = $this->_getProductItems($testdata); $orderBaseProductManager = $orderBaseManager->getSubManager('product', 'Default'); $orderBaseProductAttrManager = $orderBaseProductManager->getSubManager('attribute', 'Default'); $priceManager = MShop_Price_Manager_Factory::createManager($this->_additional, 'Default'); $this->_conn->begin(); foreach ($testdata['order/base/product'] as $key => $dataset) { if (!isset($bases['ids'][$dataset['baseid']])) { throw new MW_Setup_Exception(sprintf('No base ID found for "%1$s" in order base product data', $dataset['baseid'])); } if (!isset($bases['items'][$dataset['baseid']])) { throw new MW_Setup_Exception(sprintf('No base Item found for "%1$s" in order base product data', $dataset['baseid'])); } $ordProdItem = $orderBaseProductManager->createItem(); $ordProdItem->setId(null); $ordProdItem->setBaseId($bases['ids'][$dataset['baseid']]); $ordProdItem->setType($dataset['type']); $ordProdItem->setSupplierCode($dataset['suppliercode']); $ordProdItem->setProductCode($dataset['prodcode']); $ordProdItem->setName($dataset['name']); $ordProdItem->setMediaUrl($dataset['mediaurl']); $ordProdItem->setQuantity($dataset['amount']); $ordProdItem->setFlags($dataset['flags']); $ordProdItem->setStatus($dataset['status']); $ordProdItem->setPosition($dataset['pos']); if (isset($dataset['warehousecode'])) { $ordProdItem->setWarehouseCode($dataset['warehousecode']); } if (isset($dataset['prodid'])) { $ordProdItem->setProductId($products[$dataset['prodid']]->getId()); } // product bundle related fields if (isset($dataset['ordprodid'])) { $ordProdItem->setOrderProductId($ordProds[$dataset['ordprodid']]); } $priceItem = $priceManager->createItem(); $priceItem->setValue($dataset['price']); $priceItem->setCosts($dataset['shipping']); $priceItem->setRebate($dataset['rebate']); $priceItem->setTaxRate($dataset['taxrate']); $ordProdItem->setPrice($priceItem); $orderBaseProductManager->saveItem($ordProdItem); $bases['items'][$dataset['baseid']]->addProduct($ordProdItem, $dataset['pos']); //adds Products to orderbase $ordProds[$key] = $ordProdItem->getId(); } $this->_addOrderBaseProductAttributeData($orderBaseProductAttrManager, $testdata, $ordProds, $products); $this->_conn->commit(); return $bases['items']; }
protected function _delete(MShop_Product_Item_Interface $product) { $priceManager = MShop_Price_Manager_Factory::createManager($this->_context); $manager = MShop_Product_Manager_Factory::createManager($this->_context); $listManager = $manager->getSubManager('list'); foreach ($product->getListItems('price') as $listItem) { $priceManager->deleteItem($listItem->getRefItem()->getId()); $listManager->deleteItem($listItem->getId()); } $manager->deleteItem($product->getId()); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->_editor = TestHelper::getContext()->getEditor(); $this->_object = MShop_Price_Manager_Factory::createManager(TestHelper::getContext()); }
/** * @param string $code */ protected function _createProduct($code) { $orderManager = MShop_Order_Manager_Factory::createManager(TestHelper::getContext()); $orderProductManager = $orderManager->getSubManager('base')->getSubManager('product'); $product = $orderProductManager->createItem(); $price = MShop_Price_Manager_Factory::createManager(TestHelper::getContext())->createItem(); $price->setValue('2.99'); $product->setPrice($price); $product->setProductCode($code); return $product; }
/** * Initializes the media controller. * * @param MShop_Context_Item_Interface $context MShop context object */ public function __construct(MShop_Context_Item_Interface $context) { parent::__construct($context, 'Price'); $this->_manager = MShop_Price_Manager_Factory::createManager($context); }