本文整理汇总了PHP中MShop_Factory::createManager方法的典型用法代码示例。如果您正苦于以下问题:PHP MShop_Factory::createManager方法的具体用法?PHP MShop_Factory::createManager怎么用?PHP MShop_Factory::createManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MShop_Factory
的用法示例。
在下文中一共展示了MShop_Factory::createManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getManager
/**
* Returns the manager the controller is using.
*
* @return MShop_Common_Manager_Interface Manager object
*/
protected function _getManager()
{
if ($this->_manager === null) {
$this->_manager = MShop_Factory::createManager($this->_getContext(), 'media/list/type');
}
return $this->_manager;
}
示例2: isAvailable
/**
* Checks if the the basket weight is ok for the service provider.
*
* @param MShop_Order_Item_Base_Interface $basket Basket object
*
* @return boolean True if payment provider can be used, false if not
*/
public function isAvailable(MShop_Order_Item_Base_Interface $basket)
{
$context = $this->_getContext();
$basketWeight = 0;
$basketItems = $basket->getProducts();
foreach ($basketItems as $basketItem) {
$prodId = $basketItem->getProductId();
if (!isset($prodMap[$prodId])) {
// basket can contain a product several times in different basket items
$prodMap[$prodId] = 0.0;
}
$prodMap[$prodId] += $basketItem->getQuantity();
}
$propertyManager = MShop_Factory::createManager($context, 'product/property');
$search = $propertyManager->createSearch(true);
$expr = array($search->compare('==', 'product.property.productid', array_keys($prodMap)), $search->compare('==', 'product.property.type.code', 'package-weight'), $search->getConditions());
$search->setConditions($search->combine('&&', $expr));
$search->setSlice(0, 0x7fffffff);
// if more than 100 products are in the basket
foreach ($propertyManager->searchItems($search) as $property) {
$basketWeight += (double) $property->getValue() * $prodMap[$property->getParentId()];
}
if ($this->_checkWeightScale($basketWeight) === false) {
return false;
}
return $this->_getProvider()->isAvailable($basket);
}
示例3: update
/**
* Receives a notification from a publisher object
*
* @param MW_Observer_Publisher_Interface $order Shop basket instance implementing publisher interface
* @param string $action Name of the action to listen for
* @param mixed $value Object or value changed in publisher
* @throws MShop_Plugin_Provider_Exception if checks fail
* @return bool true if checks succeed
*/
public function update(MW_Observer_Publisher_Interface $order, $action, $value = null)
{
$ids = array();
$context = $this->_getContext();
$services = $order->getServices();
if (count($order->getProducts()) === 0) {
$priceManager = MShop_Factory::createManager($context, 'price');
foreach ($services as $type => $service) {
$service->setPrice($priceManager->createItem());
}
return true;
}
foreach ($services as $type => $service) {
$ids[$type] = $service->getServiceId();
}
$serviceManager = MShop_Factory::createManager($context, 'service');
$search = $serviceManager->createSearch(true);
$expr = array($search->compare('==', 'service.id', $ids), $search->getConditions());
$search->setConditions($search->combine('&&', $expr));
$result = $serviceManager->searchItems($search, array('price'));
foreach ($services as $type => $service) {
if (isset($result[$service->getServiceId()])) {
$provider = $serviceManager->getProvider($result[$service->getServiceId()]);
if ($provider->isAvailable($order)) {
$service->setPrice($provider->calcPrice($order));
$order->setService($service, $type);
continue;
}
}
$order->deleteService($type);
}
return true;
}
示例4: update
/**
* Receives a notification from a publisher object
*
* @param MW_Observer_Publisher_Interface $order Shop basket instance implementing publisher interface
* @param string $action Name of the action to listen for
* @param mixed $value Object or value changed in publisher
*/
public function update(MW_Observer_Publisher_Interface $order, $action, $value = null)
{
$class = 'MShop_Order_Item_Base_Interface';
if (!$order instanceof $class) {
throw new MShop_Plugin_Exception(sprintf('Object is not of required type "%1$s"', $class));
}
$notAvailable = array();
if (self::$_lock === false) {
self::$_lock = true;
$couponManager = MShop_Factory::createManager($this->_getContext(), 'coupon');
foreach ($order->getCoupons() as $code => $products) {
$search = $couponManager->createSearch(true);
$expr = array($search->compare('==', 'coupon.code.code', $code), $search->getConditions());
$search->setConditions($search->combine('&&', $expr));
$search->setSlice(0, 1);
$results = $couponManager->searchItems($search);
if (($couponItem = reset($results)) !== false) {
$couponProvider = $couponManager->getProvider($couponItem, $code);
$couponProvider->updateCoupon($order);
} else {
$notAvailable[$code] = 'coupon.gone';
}
}
self::$_lock = false;
}
if (count($notAvailable) > 0) {
$codes = array('coupon' => $notAvailable);
$msg = sprintf('Coupon in basket is not available any more');
throw new MShop_Plugin_Provider_Exception($msg, -1, null, $codes);
}
return true;
}
示例5: update
/**
* Receives a notification from a publisher object
*
* @param MW_Observer_Publisher_Interface $order Shop basket instance implementing publisher interface
* @param string $action Name of the action to listen for
* @param mixed $value Object or value changed in publisher
*/
public function update(MW_Observer_Publisher_Interface $order, $action, $value = null)
{
$context = $this->_getContext();
$context->getLogger()->log(__METHOD__ . ': event=' . $action, MW_Logger_Abstract::DEBUG);
$class = 'MShop_Order_Item_Base_Interface';
if (!$order instanceof $class) {
$msg = 'Received notification from "%1$s" which doesn\'t implement "%2$s"';
throw new MShop_Plugin_Exception(sprintf($msg, get_class($order), $class));
}
if (self::$_lock === false) {
self::$_lock = true;
$couponManager = MShop_Factory::createManager($context, 'coupon');
$search = $couponManager->createSearch();
foreach ($order->getCoupons() as $code => $products) {
$search->setConditions($search->compare('==', 'coupon.code.code', $code));
$results = $couponManager->searchItems($search);
if (($couponItem = reset($results)) !== false) {
$couponProvider = $couponManager->getProvider($couponItem, $code);
$couponProvider->updateCoupon($order);
}
}
self::$_lock = false;
}
return true;
}
示例6: isAvailable
/**
* Checks if payment provider can be used based on the basket content.
* Checks for country, currency, address, scoring, etc. should be implemented in separate decorators
*
* @param MShop_Order_Item_Base_Interface $basket Basket object
* @return boolean True if payment provider can be used, false if not
*/
public function isAvailable(MShop_Order_Item_Base_Interface $basket)
{
$context = $this->_getContext();
$config = $this->getServiceItem()->getConfig();
if (($customerId = $context->getUserId()) === null) {
return false;
}
$manager = MShop_Factory::createManager($context, 'order');
if (isset($config['ordercheck.total-number-min'])) {
$search = $manager->createSearch(true);
$expr = array($search->compare('==', 'order.base.customerid', $customerId), $search->compare('>=', 'order.statuspayment', MShop_Order_Item_Abstract::PAY_AUTHORIZED), $search->getConditions());
$search->setConditions($search->combine('&&', $expr));
$search->setSlice(0, $config['ordercheck.total-number-min']);
$result = $manager->searchItems($search);
if (count($result) < (int) $config['ordercheck.total-number-min']) {
return false;
}
}
if (isset($config['ordercheck.limit-days-pending'])) {
$time = time() - (int) $config['ordercheck.limit-days-pending'] * 86400;
$search = $manager->createSearch(true);
$expr = array($search->compare('==', 'order.base.customerid', $customerId), $search->compare('==', 'order.datepayment', date('Y-m-d H:i:s', $time)), $search->compare('==', 'order.statuspayment', MShop_Order_Item_Abstract::PAY_PENDING), $search->getConditions());
$search->setConditions($search->combine('&&', $expr));
$search->setSlice(0, 1);
$result = $manager->searchItems($search);
if (count($result) > 0) {
return false;
}
}
return $this->_getProvider()->isAvailable($basket);
}
示例7: saveItems
/**
* Creates a new list item or updates an existing one or a list thereof.
*
* @param stdClass $params Associative array containing the item properties
*/
public function saveItems(stdClass $params)
{
$this->_checkParams($params, array('site', 'items'));
$this->_setLocale($params->site);
$ids = $refIds = $domains = array();
$items = !is_array($params->items) ? array($params->items) : $params->items;
foreach ($items as $entry) {
$item = $this->_createItem((array) $entry);
$this->_manager->saveItem($item);
$domains[$item->getDomain()] = true;
$refIds[] = $item->getRefId();
$ids[] = $item->getId();
}
if (isset($domains['product'])) {
$context = $this->_getContext();
$productManager = MShop_Factory::createManager($context, 'product');
$search = $productManager->createSearch();
$search->setConditions($search->compare('==', 'product.id', $refIds));
$search->setSlice(0, count($refIds));
$indexManager = MShop_Factory::createManager($context, 'catalog/index');
$indexManager->rebuildIndex($productManager->searchItems($search));
}
$search = $this->_manager->createSearch();
$search->setConditions($search->compare('==', 'catalog.list.id', $ids));
$search->setSlice(0, count($ids));
$items = $this->_toArray($this->_manager->searchItems($search));
return array('items' => !is_array($params->items) ? reset($items) : $items, 'success' => true);
}
示例8: _getPropertyItems
/**
* Returns the product properties for the given product ID
*
* @param string $prodid Unique product ID
* @return array Associative list of product property items
*/
protected function _getPropertyItems($prodid)
{
$manager = MShop_Factory::createManager($this->_getContext(), 'product/property');
$search = $manager->createSearch();
$search->setConditions($search->compare('==', 'product.property.parentid', $prodid));
return $manager->searchItems($search);
}
示例9: update
/**
* Receives a notification from a publisher object
*
* @param MW_Observer_Publisher_Interface $order Shop basket instance implementing publisher interface
* @param string $action Name of the action to listen for
* @param mixed $value Object or value changed in publisher
* @throws MShop_Plugin_Provider_Exception if checks fail
* @return bool true if checks succeed
*/
public function update(MW_Observer_Publisher_Interface $order, $action, $value = null)
{
$context = $this->_getContext();
$context->getLogger()->log(__METHOD__ . ': event=' . $action, MW_Logger_Abstract::DEBUG);
$class = 'MShop_Order_Item_Base_Interface';
if (!$order instanceof $class) {
throw new MShop_Plugin_Exception(sprintf('Object is not of required type "%1$s"', $class));
}
$class = 'MShop_Order_Item_Base_Product_Interface';
if (!$value instanceof $class) {
throw new MShop_Plugin_Exception(sprintf('Object is not of required type "%1$s"', $class));
}
$config = $this->_getItem()->getConfig();
if ($config === array()) {
return true;
}
$productManager = MShop_Factory::createManager($context, 'product');
$criteria = $productManager->createSearch(true);
$expr = array();
$expr[] = $criteria->compare('==', 'product.id', $value->getProductId());
$expr[] = $criteria->getConditions();
foreach ($config as $property => $value) {
$expr[] = $criteria->compare('==', $property, $value);
}
$criteria->setConditions($criteria->combine('&&', $expr));
$result = $productManager->searchItems($criteria);
if (reset($result) === false) {
$code = array('product' => array_keys($config));
throw new MShop_Plugin_Provider_Exception(sprintf('Product matching given properties not found'), -1, null, $code);
}
return true;
}
示例10: update
/**
* Receives a notification from a publisher object
*
* @param MW_Observer_Publisher_Interface $order Shop basket instance implementing publisher interface
* @param string $action Name of the action to listen for
* @param mixed $value Object or value changed in publisher
* @throws MShop_Plugin_Provider_Exception if checks fail
* @return bool true if checks succeed
*/
public function update(MW_Observer_Publisher_Interface $order, $action, $value = null)
{
$context = $this->_getContext();
$logger = $context->getLogger();
$logger->log(__METHOD__ . ': event=' . $action, MW_Logger_Abstract::DEBUG);
if ($context->getConfig()->get('mshop/plugin/provider/order/complete/disable', false)) {
$logger->log(__METHOD__ . ': Is disabled', MW_Logger_Abstract::DEBUG);
return true;
}
$class = 'MShop_Order_Item_Base_Interface';
if (!$order instanceof $class) {
throw new MShop_Plugin_Provider_Exception(sprintf('Object is not of required type "%1$s"', $class));
}
if (!($value & MShop_Order_Item_Base_Abstract::PARTS_PRODUCT)) {
return true;
}
$count = 0;
$sum = MShop_Factory::createManager($context, 'price')->createItem();
foreach ($order->getProducts() as $product) {
$sum->addItem($product->getPrice(), $product->getQuantity());
$count += $product->getQuantity();
}
$this->_checkLimits($sum, $count);
return true;
}
示例11: deleteItems
/**
* Deletes an item or a list of items.
*
* @param stdClass $params Associative list of parameters
* @return array Associative list with success value
*/
public function deleteItems(stdClass $params)
{
$this->_checkParams($params, array('site', 'items'));
$this->_setLocale($params->site);
$idList = array();
$ids = (array) $params->items;
$context = $this->_getContext();
$manager = $this->_getManager();
$search = $manager->createSearch();
$search->setConditions($search->compare('==', 'text.id', $ids));
$search->setSlice(0, count($ids));
foreach ($manager->searchItems($search) as $id => $item) {
$idList[$item->getDomain()][] = $id;
}
$manager->deleteItems($ids);
foreach ($idList as $domain => $domainIds) {
$manager = MShop_Factory::createManager($context, $domain . '/list');
$search = $manager->createSearch();
$expr = array($search->compare('==', $domain . '.list.refid', $domainIds), $search->compare('==', $domain . '.list.domain', 'text'));
$search->setConditions($search->combine('&&', $expr));
$search->setSortations(array($search->sort('+', $domain . '.list.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());
}
$this->_clearCache($ids);
return array('items' => $params->items, 'success' => true);
}
示例12: testSaveItemLabelContent
public function testSaveItemLabelContent()
{
$typeManager = MShop_Factory::createManager(TestHelper::getContext(), 'text/type');
$criteria = $typeManager->createSearch();
$criteria->setSlice(0, 1);
$result = $typeManager->searchItems($criteria);
if (($type = reset($result)) === false) {
throw new Exception('No type item found');
}
$saveParams = (object) array('site' => 'unittest', 'items' => (object) array('text.content' => 'controller test text', 'text.domain' => 'product', 'text.typeid' => $type->getId(), 'text.languageid' => 'de', 'text.status' => 1));
$searchParams = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => (object) array('==' => (object) array('text.content' => 'controller test text')))));
$saved = $this->_object->saveItems($saveParams);
$searched = $this->_object->searchItems($searchParams);
$deleteParams = (object) array('site' => 'unittest', 'items' => $saved['items']->{'text.id'});
$this->_object->deleteItems($deleteParams);
$result = $this->_object->searchItems($searchParams);
$this->assertInternalType('object', $saved['items']);
$this->assertNotNull($saved['items']->{'text.id'});
$this->assertEquals($saved['items']->{'text.id'}, $searched['items'][0]->{'text.id'});
$this->assertEquals($saved['items']->{'text.content'}, $searched['items'][0]->{'text.content'});
$this->assertEquals($saved['items']->{'text.domain'}, $searched['items'][0]->{'text.domain'});
$this->assertEquals($saved['items']->{'text.typeid'}, $searched['items'][0]->{'text.typeid'});
$this->assertEquals($saved['items']->{'text.content'}, $searched['items'][0]->{'text.label'});
$this->assertEquals($saved['items']->{'text.languageid'}, $searched['items'][0]->{'text.languageid'});
$this->assertEquals($saved['items']->{'text.status'}, $searched['items'][0]->{'text.status'});
$this->assertEquals(1, count($searched['items']));
$this->assertEquals(0, count($result['items']));
$this->assertEquals('controller test text', $saved['items']->{'text.label'});
}
示例13: update
/**
* Receives a notification from a publisher object
*
* @param MW_Observer_Publisher_Interface $order Shop basket instance implementing publisher interface
* @param string $action Name of the action to listen for
* @param mixed $value Object or value changed in publisher
* @throws MShop_Plugin_Exception in case of faulty configuration or parameters
* @return bool true if attributes have been added successfully
*/
public function update(MW_Observer_Publisher_Interface $order, $action, $value = null)
{
$class = 'MShop_Order_Item_Base_Interface';
if (!$order instanceof $class) {
throw new MShop_Plugin_Exception(sprintf('Object is not of required type "%1$s"', $class));
}
$class = 'MShop_Order_Item_Base_Product_Interface';
if (!$value instanceof $class) {
throw new MShop_Plugin_Exception(sprintf('Object is not of required type "%1$s"', $class));
}
$productManager = MShop_Factory::createManager($this->_getContext(), 'product');
$config = $this->_getItem()->getConfig();
foreach ($config as $key => $properties) {
$keyElements = explode('.', $key);
if ($keyElements[0] !== 'product' || count($keyElements) < 3) {
throw new MShop_Plugin_Exception(sprintf('Configuration invalid'));
}
$productSubManager = $productManager->getSubManager($keyElements[1]);
$search = $productSubManager->createSearch(true);
$cond = array();
$cond[] = $search->compare('==', $key, $value->getProductId());
$cond[] = $search->getConditions();
$search->setConditions($search->combine('&&', $cond));
$result = $productSubManager->searchItems($search);
foreach ($result as $item) {
$attributes = $this->_addAttributes($item, $value, $properties);
$value->setAttributes($attributes);
}
}
return true;
}
示例14: setUp
/**
* 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();
$this->_ordServItem = MShop_Factory::createManager($context, 'order/base/service')->createItem();
$serviceItem = MShop_Factory::createManager($context, 'service')->createItem();
$serviceItem->setCode('test');
$this->_object = $this->getMockBuilder('MShop_Service_Provider_Payment_DirectDebit')->setMethods(array('_getOrder', '_getOrderBase', '_saveOrder', '_saveOrderBase'))->setConstructorArgs(array($context, $serviceItem))->getMock();
}
示例15: setUp
/**
* 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();
$this->_ordServItem = MShop_Factory::createManager($context, 'order/base/service')->createItem();
$serviceItem = MShop_Factory::createManager($context, 'service')->createItem();
$serviceItem->setCode('test');
$this->_object = new MShop_Service_Provider_Payment_DirectDebit($context, $serviceItem);
}