/** * 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(); $this->couponItem = \Aimeos\MShop\Coupon\Manager\Factory::createManager($context)->createItem(); $provider = new \Aimeos\MShop\Coupon\Provider\Example($context, $this->couponItem, 'abcd'); $this->object = new \Aimeos\MShop\Coupon\Provider\Decorator\Required($context, $this->couponItem, 'abcd', $provider); $this->object->setObject($this->object); $orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager($context); $orderBaseManager = $orderManager->getSubManager('base'); $orderProductManager = $orderBaseManager->getSubManager('product'); $productManager = \Aimeos\MShop\Product\Manager\Factory::createManager($context); $search = $productManager->createSearch(); $search->setConditions($search->compare('==', 'product.code', array('CNC'))); $products = $productManager->searchItems($search); $priceManager = \Aimeos\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 \Aimeos\MShop\Order\Item\Base\Standard($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 = \TestHelperMShop::getContext()->getEditor(); $manager = \Aimeos\MShop\Price\Manager\Factory::createManager(\TestHelperMShop::getContext()); $listManager = $manager->getSubManager('lists'); $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 \Aimeos\MW\Setup\Exception If a required ID is not available */ protected function getPriceData(array $keys) { $priceManager = \Aimeos\MShop\Price\Manager\Factory::createManager($this->additional, 'Standard'); $priceTypeManager = $priceManager->getSubManager('type', 'Standard'); $value = $ship = $domain = $code = array(); foreach ($keys as $dataset) { $exp = explode('/', $dataset); if (count($exp) != 5) { throw new \Aimeos\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; }
protected function setUp() { $this->price = \Aimeos\MShop\Price\Manager\Factory::createManager(\TestHelperMShop::getContext())->createItem(); $attrValues = array('order.base.service.attribute.id' => 3, 'order.base.service.attribute.siteid' => 99, 'order.base.service.attribute.parentid' => 42, 'order.base.service.attribute.name' => 'UnitName', 'order.base.service.attribute.type' => 'default', 'order.base.service.attribute.code' => 'UnitCode', 'order.base.service.attribute.value' => 'UnitValue', 'order.base.service.attribute.mtime' => '2020-12-31 23:59:59', 'order.base.service.attribute.ctime' => '2011-01-01 00:00:01', 'order.base.service.attribute.editor' => 'unitTestUser'); $this->attribute = array('UnitCode' => new \Aimeos\MShop\Order\Item\Base\Service\Attribute\Standard($attrValues)); $this->values = array('order.base.service.id' => 1, 'order.base.service.siteid' => 99, 'order.base.service.serviceid' => 'ServiceID', 'order.base.service.baseid' => 42, 'order.base.service.code' => 'UnitCode', 'order.base.service.name' => 'UnitName', 'order.base.service.mediaurl' => 'Url for test', 'order.base.service.type' => 'payment', 'order.base.service.mtime' => '2012-01-01 00:00:01', 'order.base.service.ctime' => '2011-01-01 00:00:01', 'order.base.service.editor' => 'unitTestUser'); $this->object = new \Aimeos\MShop\Order\Item\Base\Service\Standard($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 = \Aimeos\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 \Aimeos\MShop\Order\Item\Base\Product\Attribute\Standard($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' => \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_NONE, 'status' => \Aimeos\MShop\Order\Item\Base::STAT_PROGRESS, 'pos' => 1, 'mtime' => '2000-12-31 23:59:59', 'ctime' => '2011-01-01 00:00:01', 'editor' => 'unitTestUser'); $this->subProducts = array(new \Aimeos\MShop\Order\Item\Base\Product\Standard(clone $this->price), new \Aimeos\MShop\Order\Item\Base\Product\Standard(clone $this->price)); $this->object = new \Aimeos\MShop\Order\Item\Base\Product\Standard($this->price, $this->values, $this->attribute, $this->subProducts); }
protected function setUp() { $context = \TestHelperMShop::getContext(); $priceManager = \Aimeos\MShop\Price\Manager\Factory::createManager($context); $item = \Aimeos\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 \Aimeos\MShop\Order\Item\Base\Standard($priceManager->createItem(), $context->getLocale()); $this->object = new \Aimeos\MShop\Coupon\Provider\None($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 = \TestHelperMShop::getContext(); $priceManager = \Aimeos\MShop\Price\Manager\Factory::createManager($context); $couponItem = \Aimeos\MShop\Coupon\Manager\Factory::createManager($context)->createItem(); $couponItem->setConfig(array('percentrebate.productcode' => 'U:MD', 'percentrebate.rebate' => '10')); // Don't create order base item by createItem() as this would already register the plugins $this->orderBase = new \Aimeos\MShop\Order\Item\Base\Standard($priceManager->createItem(), $context->getLocale()); $this->object = new \Aimeos\MShop\Coupon\Provider\PercentRebate($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 = \TestHelperMShop::getContext(); $pluginManager = \Aimeos\MShop\Plugin\Manager\Factory::createManager($context); $this->plugin = $pluginManager->createItem(); $this->plugin->setProvider('Coupon'); $this->plugin->setStatus(1); $priceItem = \Aimeos\MShop\Price\Manager\Factory::createManager($context)->createItem(); $this->order = new \Aimeos\MShop\Order\Item\Base\Standard($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 = \Aimeos\MShop\Plugin\Manager\Factory::createManager($context); $item = $pluginManager->createItem(); $provider = new \Aimeos\MShop\Plugin\Provider\Order\Example($context, $item); $priceItem = \Aimeos\MShop\Price\Manager\Factory::createManager($context)->createItem(); $this->order = new \Aimeos\MShop\Order\Item\Base\Standard($priceItem, $context->getLocale()); $this->object = new \Aimeos\MShop\Plugin\Provider\Decorator\Log($context, $item, $provider); }
protected function setUp() { $context = \TestHelperMShop::getContext(); $this->values = array('order.base.id' => 1, 'order.base.siteid' => 99, 'order.base.customerid' => 'testuser', 'order.base.comment' => 'this is a comment from unittest', 'order.base.status' => 0, 'order.base.mtime' => '2011-01-01 00:00:02', 'order.base.ctime' => '2011-01-01 00:00:01', 'order.base.editor' => 'unitTestUser'); $price = \Aimeos\MShop\Price\Manager\Factory::createManager($context)->createItem(); $this->locale = \Aimeos\MShop\Locale\Manager\Factory::createManager($context)->createItem(); $this->object = new \Aimeos\MShop\Order\Item\Base\Standard($price, $this->locale, $this->values); //registering order object for plugin use $pluginManager = \Aimeos\MShop\Plugin\Manager\Factory::createManager($context); $pluginManager->register($this->object, 'order'); }
/** * 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 = \Aimeos\MShop\Plugin\Manager\Factory::createManager($context); $this->plugin = $pluginManager->createItem(); $this->plugin->setTypeId(2); $this->plugin->setProvider('Example'); $this->plugin->setConfig(array('key' => 1)); $this->plugin->setStatus('1'); $priceItem = \Aimeos\MShop\Price\Manager\Factory::createManager($context)->createItem(); $this->order = new \Aimeos\MShop\Order\Item\Base\Standard($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 = \TestHelperMShop::getContext(); $couponItem = \Aimeos\MShop\Coupon\Manager\Factory::createManager($context)->createItem(); $couponItem->setConfig(array('freeshipping.productcode' => 'U:SD')); $this->object = new \Aimeos\MShop\Coupon\Provider\FreeShipping($context, $couponItem, 'zyxw'); $delPrice = \Aimeos\MShop\Price\Manager\Factory::createManager($context)->createItem(); $delPrice->setCosts('5.00'); $delPrice->setCurrencyId('EUR'); $priceManager = \Aimeos\MShop\Price\Manager\Factory::createManager($context); $manager = \Aimeos\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 \Aimeos\MShop\Order\Item\Base\Standard($priceManager->createItem(), $context->getLocale()); $this->orderBase->setService($delivery, 'delivery'); }
/** * Adds the price test data. * * @param array $testdata Associative list of key/list pairs * @throws \Aimeos\MW\Setup\Exception If a required ID is not available */ private function addPriceData(array $testdata) { $priceManager = \Aimeos\MShop\Price\Manager\Factory::createManager($this->additional, 'Standard'); $priceTypeManager = $priceManager->getSubManager('type', 'Standard'); $ptypeIds = array(); $ptype = $priceTypeManager->createItem(); $this->conn->begin(); 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 \Aimeos\MW\Setup\Exception(sprintf('No price type ID found for "%1$s"', $dataset['typeid'])); } $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->setStatus($dataset['status']); $priceManager->saveItem($price, false); } $this->conn->commit(); }
/** * @param string $code */ protected function createProduct($code) { $orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager(\TestHelperMShop::getContext()); $orderProductManager = $orderManager->getSubManager('base')->getSubManager('product'); $product = $orderProductManager->createItem(); $price = \Aimeos\MShop\Price\Manager\Factory::createManager(\TestHelperMShop::getContext())->createItem(); $price->setValue('2.99'); $product->setPrice($price); $product->setProductCode($code); return $product; }
protected function cleanupPrice() { $manager = \Aimeos\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()); }
/** * 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 = \TestHelperMShop::getContext()->getEditor(); $this->object = \Aimeos\MShop\Price\Manager\Factory::createManager(\TestHelperMShop::getContext()); }
protected function delete(\Aimeos\MShop\Product\Item\Iface $product) { $priceManager = \Aimeos\MShop\Price\Manager\Factory::createManager($this->context); $manager = \Aimeos\MShop\Product\Manager\Factory::createManager($this->context); $listManager = $manager->getSubManager('lists'); foreach ($product->getListItems('price') as $listItem) { $priceManager->deleteItem($listItem->getRefItem()->getId()); $listManager->deleteItem($listItem->getId()); } $manager->deleteItem($product->getId()); }
/** * Adds the required order base product data. * * @param \Aimeos\MShop\Order\Manager\Base\Iface $orderBaseManager Order Base Manager * @param array $bases Associative list of key/list pairs * @param array $testdata Associative list of key/list pairs * @throws \Aimeos\MW\Setup\Exception If no type ID is found */ protected function addOrderBaseProductData(\Aimeos\MShop\Common\Manager\Iface $orderBaseManager, array $bases, array $testdata) { $ordProds = array(); $products = $this->getProductItems($testdata); $orderBaseProductManager = $orderBaseManager->getSubManager('product', 'Standard'); $orderBaseProductAttrManager = $orderBaseProductManager->getSubManager('attribute', 'Standard'); $priceManager = \Aimeos\MShop\Price\Manager\Factory::createManager($this->additional, 'Standard'); $this->conn->begin(); foreach ($testdata['order/base/product'] as $key => $dataset) { if (!isset($bases['ids'][$dataset['baseid']])) { throw new \Aimeos\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 \Aimeos\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']; }
public function testUpdateTotalValueMax() { $priceManager = \Aimeos\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('\\Aimeos\\MShop\\Plugin\\Exception'); $this->object->update($this->order, 'addProduct.before', $this->products['CNE']); }
/** * Returns the price type IDs for the given domains and codes * * @param array $domain Domain the price type is for * @param array $code Code the price type is for * @return array List of price type IDs */ protected function getPriceTypeIds(array $domain, array $code) { $manager = \Aimeos\MShop\Price\Manager\Factory::createManager($this->additional, 'Standard'); $typeManager = $manager->getSubManager('type', 'Standard'); $search = $typeManager->createSearch(); $expr = array($search->compare('==', 'price.type.domain', $domain), $search->compare('==', 'price.type.code', $code)); $search->setConditions($search->combine('&&', $expr)); $typeids = array(); foreach ($typeManager->searchItems($search) as $item) { $typeids[] = $item->getId(); } return $typeids; }
public function testCreateManagerNotExisting() { $this->setExpectedException('\\Aimeos\\MShop\\Exception'); \Aimeos\MShop\Price\Manager\Factory::createManager(\TestHelper::getContext(), 'unknown'); }
protected function getListItems() { $manager = \Aimeos\MShop\Price\Manager\Factory::createManager($this->context, 'Standard'); $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.lists.parentid', $item->getId()), $search->compare('==', 'price.lists.domain', 'customer'), $search->compare('==', 'price.lists.editor', $this->editor), $search->compare('==', 'price.lists.type.code', 'default')); $search->setConditions($search->combine('&&', $expr)); $search->setSortations(array($search->sort('+', 'price.lists.position'))); return $this->object->searchItems($search); }
/** * 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 \Aimeos\MW\Setup\Exception If a required ID is not available */ private function addPriceListData(array $testdata, array $refIds) { $priceManager = \Aimeos\MShop\Price\Manager\Factory::createManager($this->additional, 'Standard'); $priceTypeManager = $priceManager->getSubManager('type', 'Standard'); $priceListManager = $priceManager->getSubManager('lists', 'Standard'); $priceListTypeManager = $priceListManager->getSubManager('type', 'Standard'); $value = $ship = $domain = $code = array(); foreach ($testdata['price/lists'] as $dataset) { $exp = explode('/', $dataset['parentid']); if (count($exp) != 5) { throw new \Aimeos\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/lists/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/lists'] as $dataset) { if (!isset($parentIds[$dataset['parentid']])) { throw new \Aimeos\MW\Setup\Exception(sprintf('No price ID found for "%1$s"', $dataset['parentid'])); } if (!isset($listItemTypeIds[$dataset['typeid']])) { throw new \Aimeos\MW\Setup\Exception(sprintf('No attribute list type ID found for "%1$s"', $dataset['typeid'])); } if (!isset($refIds[$dataset['domain']][$dataset['refid']])) { throw new \Aimeos\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(); }